Missing letters Help Needed

Missing letters Help Needed
0

#1

Tell us what’s happening:
I think the logic is good but I got undefined for charCodeAt and I don’t know why…

Your code so far


function fearNotLetter(str) {
let word = str.split("");
word.map(function (letter, index) {
  if (index + 1 <= word.length && letter.charCodeAt(0) + 1 !== letter[index + 1].charCodeAt(0)) {
    let conver = letter.charCodeAt(0) + 1;
    return String.fromCharCode(conver);
  } else {
    return undefined;
  }
});
}

fearNotLetter("abce");

Your browser information:

User Agent is: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/69.0.3497.100 Safari/537.36.

Link to the challenge:
https://learn.freecodecamp.org/javascript-algorithms-and-data-structures/intermediate-algorithm-scripting/missing-letters


#2

The above part of your if statement is the issue. In the first iteration of the map method callback function, letter is ‘a’ and index is 0, so you are really evaluating the following:

'a'[1].charCodeAt(0)

Since the length of the string ‘a’ is 1, there is no index greater than 0 (arrays are zero-indexed), so ‘a’[1] is undefined and undefined does not have any properties (especially one named charCodeAt.


#3

ups that was a typo I meant word instead of letter something like …


function fearNotLetter(str) {
let word = str.split("");
word.map(function (letter, index) {
  if (index + 1 <= word.length && letter.charCodeAt(0) + 1 !== world[index + 1].charCodeAt(0)) {
    let conver = letter.charCodeAt(0) + 1;
    return String.fromCharCode(conver);
  } else {
    return undefined;
  }
});
}

fearNotLetter("abce");

I’m still getting the same issue… “Cannot read property ‘charCodeAt’ of undefined”


#4

Isn’t this a typo too?


#5

Yeah sorry, well actually in my code is word no world.

What else could be?

myFunction


#6

Still trying to figure out what I am doing wrong…