Missing letters challenge - stuck here for quite some time

Tell us what’s happening:
I’ve got 4/5 correct but cannot understand why my code is not returning undefined as specified. Would appreciate any kind of help to identify my mistake.

Thanks in advance!
Your code so far

function fearNotLetter(str) {
for(var i = 0; i<str.length; i++){
  var first = str.charCodeAt(i);
  var second = str.charCodeAt(i+1);
  if((second - first) == 1){
  else return ((second-first) != 1)? String.fromCharCode(first + 1) : undefined;


Your browser information:

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

Challenge: Missing letters

Link to the challenge:

  else return ((second-first) != 1)? String.fromCharCode(first + 1) : undefined;

In your ternary you are checking whether (second - first) != 1, but you only get to this line of code if that is true. That means that you will always return String.fromCharCode(first + 1) when this line is reached.

1 Like


You are iterating too far in your loop.

If you iterate to the end of the array with i, then you are reaching past the end of the array with this variable. I’d shorten up the range over which you iterate.

1 Like

Oh thank you so much! I’ve got it by changing the iteration to **

> i < str.length - 1.

Was stuck there for 2 hours now and din’t realize.
Thanks again :slight_smile:

1 Like