Missing letters issue

function fearNotLetter(str) {
  
 for(x=str.length - 1; x >= 0; x--){
    
    if(str.charCodeAt(x) - str.charCodeAt(x-1) === 1){
       return undefined;
     } 
    
    else if((str.charCodeAt(x) - str.charCodeAt(x-1)) > 1){
      return String.fromCharCode(str.charCodeAt(x) - 1);
      
    }
  }
}

  fearNotLetter("abcdefghjklmno");

So my code is passing 3/4 of the tests. It just can’t pass the one provided (abcdefghjklmno). I feel like its something obvious, but have been banging my head against a wall, trying to find the issue.

Three hints:

  1. for loops execute the code contained within on each iteration, not just the last one.
  2. A function can return only one value.
  3. Commenting out/deleting a single line allows your code to pass the tests.

Thanks for the first hint. I Just removed the first If statement, and returned undefined, outside of the For loop, and it works.

good to know randell, thanks all