Just wondering about the line after the if statement to verify if it is withing the codes for the letters. My Question is, why are we subtracting variable code from 64 then adding a string.
function alphabetPosition(text) {
var result = "";
for (var i = 0; i < text.length; i++) {
var code = text.toUpperCase().charCodeAt(i)
if (code > 64 && code < 91) result += (code - 64) + " ";
}
return result.slice(0, result.length - 1);
}
console.log(alphabetPosition("The sunset sets at twelve o' clock."));
As an example for explanation: the code of A is 65 but its alphabetical position is 1. So if you need to get the letter’s alphabetical position from its code just subtract 64.