![Trending Articles on Technical and Non Technical topics](/images/trending_categories.jpeg)
Data Structure
Networking
RDBMS
Operating System
Java
MS Excel
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP
Physics
Chemistry
Biology
Mathematics
English
Economics
Psychology
Social Studies
Fashion Studies
Legal Studies
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
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
Advertisements