Returning the missing letter

Tell us what’s happening:
Describe your issue in detail here.
Hello,
My code passes all the tests except the last one which should return undefined. Can someone help me identify my mistake?

  **Your code so far**

function fearNotLetter(str) {
let myArr = str.split("");

console.log(myArr[0].charCodeAt(0));
for(let i = 0; i < myArr.length; ++i) {
  if(myArr[i+1].charCodeAt(0) - myArr[i].charCodeAt(0) > 1) {
    let letter = String.fromCharCode(myArr[i].charCodeAt(0) + 1);
    console.log(letter);
    return letter;
  }
}
 
}

fearNotLetter("abce");
  **Your browser information:**

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

Challenge: Missing letters

Link to the challenge:

I actually changed it a little bit and now it fails all the tests although the letter in the console is correct when I do console.log(letter).

function fearNotLetter(str) {
  let myArr = str.split("");
  let letter;
  console.log(myArr[0].charCodeAt(0));
  for(let i = 0; i < myArr.length; ++i) {
    if(myArr[i+1].charCodeAt(0) - myArr[i].charCodeAt(0) > 1) {
      letter = String.fromCharCode(myArr[i].charCodeAt(0) + 1);
      console.log(letter);
      
    }
  }
   return letter;
}

fearNotLetter("abce");

Concerning the first code you posted, change the function call at the end to use the test case that is failing:

fearNotLetter("abcdefghijklmnopqrstuvwxyz");

You should see an error message in the console pane below the editor. The FCC tests can hide these messages from you so it’s not so obvious why a test is failing.

1 Like

Okay, it was something with the index. I figured it out. Thank you!

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