
- Javascript Basics Tutorial
- Javascript - Home
- Javascript - Overview
- Javascript - Syntax
- Javascript - Enabling
- Javascript - Placement
- Javascript - Variables
- Javascript - Operators
- Javascript - If...Else
- Javascript - Switch Case
- Javascript - While Loop
- Javascript - For Loop
- Javascript - For...in
- Javascript - Loop Control
- Javascript - Functions
- Javascript - Events
- Javascript - Cookies
- Javascript - Page Redirect
- Javascript - Dialog Boxes
- Javascript - Void Keyword
- Javascript - Page Printing
- JavaScript Objects
- Javascript - Objects
- Javascript - Number
- Javascript - Boolean
- Javascript - Strings
- Javascript - Arrays
- Javascript - Date
- Javascript - Math
- Javascript - RegExp
- Javascript - HTML DOM
- JavaScript Advanced
- Javascript - Error Handling
- Javascript - Validations
- Javascript - Animation
- Javascript - Multimedia
- Javascript - Debugging
- Javascript - Image Map
- Javascript - Browsers
- JavaScript Useful Resources
- Javascript - Questions And Answers
- Javascript - Quick Guide
- Javascript - Functions
- Javascript - Resources
Finding the ASCII score of a string - JavaScript
ASCII Code
ASCII is a 7-bit character code where every single bit represents a unique character.
Every English alphabet has a unique decimal ascii code.
We are required to write a JavaScript function that takes in a string and counts the sum of all the ascii codes of the string characters
Example
Following is the code −
const str = 'This string will be used for calculating ascii score'; const calculateASCII = str => { let res = 0; for(let i = 0; i < str.length; i++){ const num = str[i].charCodeAt(0); res += num; }; return res; }; console.log(calculateASCII(str));
Output
Following is the output in the console −
4946
- Related Articles
- Finding the 1-based index score of a lowercase alpha string in JavaScript
- Finding score of brackets in JavaScript
- Finding the number of words in a string JavaScript
- Finding number of spaces in a string JavaScript
- Finding mistakes in a string - JavaScript
- Finding the power of a string from a string with repeated letters in JavaScript
- Finding alphabet from ASCII value without using library functions in JavaScript
- Finding the first non-repeating character of a string in JavaScript
- Finding duplicate "words" in a string - JavaScript
- Finding missing letter in a string - JavaScript
- Finding the longest word in a string in JavaScript
- Finding sort order of string in JavaScript
- Finding count of special characters in a string in JavaScript
- Finding the length of longest vowel substring in a string using JavaScript
- Finding the index of the first repeating character in a string in JavaScript

Advertisements