Missing letters - not passing the challenge

Missing letters - not passing the challenge
0

#1

Tell us what’s happening:

Hi campers,
I have been working on this challenge on Repl.it and it does pass all tests both there and on my console. However, I am not passing the fearNotLetter(“abcdefghijklmnopqrstuvwxyz”) should return undefined test on FCC.

Could you take a look and let me know why my code is having problems?

Thanks!

Your code so far


let alphabet = 'abcdefghijklmnopqrstuvwxyz'.split('');

function fearNotLetter(str) {
  let foundLetter = "";
  let target = str.split('');
  let alphabetPortion = alphabet.slice(alphabet.indexOf(target[0]));

  for (let i = 0; i <= target.length; i++) {
    if (target.indexOf(alphabetPortion[i]) === -1) {
      foundLetter += alphabetPortion[i];
    }
  }

  if (foundLetter.length > 0) {
    return foundLetter;
  }
  else {
  return undefined;
  }
  }

fearNotLetter("abce");

Your browser information:

User Agent is: Mozilla/5.0 (Macintosh; Intel Mac OS X 10_13_6) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/68.0.3440.106 Safari/537.36.

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


#2

Add the following console.log statement on the line before the if (foundLetter.length > 0) { line and check your browser’s console (Ctrl+Shft+J in Chrome). I think you will be surprised what string value is displayed.

console.log(foundLetter);

#3

your loop goes from 0 to (and including) the length of target.
So if alphabetPortion has 26 letters, and target has 26 letters, your loop goes from 0 to 26.

Does that sound like what you wanted to do?


#4

Thank you so much for pointing me in the right direction, it worked!