Missing Letters Challenge

Tell us what’s happening:

Hey guys! Cant figure out why this isn’t working. Any ideas? The function works, but doesn’t returned undefined.

Your code so far


function fearNotLetter(str) {

  for  (var i = 0; i < str.length; i++){
        
    if (str.charCodeAt(i) !== str.charCodeAt(i + 1) - 1){
     let result = String.fromCharCode(str.charCodeAt(i + 1)-1); 
     return result;
    }
    
  }
  return undefined;
}

fearNotLetter("abce");

Your browser information:

User Agent is: Mozilla/5.0 (Windows NT 6.1) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/67.0.3396.99 Safari/537.36.

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

I’m guessing this means I have to reformat my function, because I don’t see a way around it in its current state.
Thanks btw!

thanks for clearing that up, I actually tried the second condition you mentioned when i created the function but I set a check for i = str.length ass opposed to i < str.length - 1, forgetting that str.length is not an indexed number.