Given a string . Find the numberical sum of the
string .
Example 1:
Given String = "abcd"
Numerical
Sum = 1 + 2 + 3 + 4 = 10, Since a = 1 , b = 2 , c =3 and d = 4
it done html and javascript and plz do it in simple way
I am not sure if you want me to write the code for html and javascript both for dom manipulation or just the code for function of getting the sum in Javascript.
I will write the Javascript code for the function called getStringSum() and if there's any further issue then ping me on it.
function getStringSum(str) {
str = str.toLowerCase();
let sum = 0;
for(var i = 0; i < str.length; i++) {
sum += str.charCodeAt(i) - 96;
}
return sum
}
I hope this is upto your expectation and if it is kindly give an upvote.
Get Answers For Free
Most questions answered within 1 hours.