# Intermediate Algorithm Scripting - Missing letters

Tell us what’s happening: i didnt understand whats means { return String.fromCharCode(charCode - 1); } *
Describe your issue in detail here.
thanks
**
function fearNotLetter(str) {
for (let i = 0; i < str.length; i++) {
/
code of current character */
const charCode = str.charCodeAt(i);

``````/* if code of current character is not equal to first character + no of iteration
then a letter was skipped */
if (charCode !== str.charCodeAt(0) + i) {
/* if current character skipped past a character find previous character and return */
return String.fromCharCode(charCode - 1);
}
``````

}
return undefined;
}

// test here
fearNotLetter(“abce”);**

``````function fearNotLetter(str) {

for (let i=0; i<str.length; i++) {
const charCode = str.charCodeAt(i);

if(charCode !== str.charCodeAt(0)+ i) {

return String.fromCharCode(charCode - 1);

})
}
return undefined;
}

fearNotLetter("abce");
//d
//abce

//0<4 97 = 97    97 !== 101   97+3 =100  97+4 101

//1     98
//2       99
//3     101

``````

User Agent is: `Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/107.0.0.0 Safari/537.36 Edg/107.0.1418.56`

Challenge: Intermediate Algorithm Scripting - Missing letters

I assume that you are looking at an example answer. This answer relies on knowledge of character codes. The lowercase letters `abc...z` are represented by the numbers 97 to 122. Therefore, a set of consecutive letters will correspond to a set of consecutive character code numbers.

If you have the string `"abce"`, the function will find the character code of the first letter (97), then check if every consecutive letter has a character code one higher than the last. It will find the following:

``````a | 97
b | 98
c | 99
e | 101
``````

When it gets to 101, it sees that a letter has been skipped. Now, it has to return the missing letter, which will have a character code one less than the letter that was found. Therefore, it subtracts 1 from 101 and converts the character code into the letter `d` by calling `String.fromCharCode(charCode - 1)`.

2 Likes

This topic was automatically closed 182 days after the last reply. New replies are no longer allowed.