Oh man am I puzzled

My solution so far for the missing letters challenge, working as expected with every test except the one with “stvwx” as the input (returning undefined instead of “u”), and I am stumped as to why. Can anyone explain what’s different about this test, and what’s missing from my code?

Thanks : )

Your code so far


function fearNotLetter(str) {
let alphabet = 'abcdefghijklmnopqrstuvwxyz';
let range = alphabet.slice(alphabet.indexOf(str[0]), str.length + 2);
for (var i = 0; i < range.length; i++) {
  if (str.includes(range[i]) === false) {
    return range[i];
  }
}
return undefined;
}

console.log(fearNotLetter("abce"));
console.log(fearNotLetter("stvwx"));

Your browser information:

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

Challenge: Missing letters

Link to the challenge:

what are the two arguments of slice?

slice takes in (beginIndex, endIndex), and it appears you’re passing in the length of characters you want as the second argument (instead of the endIndex).

So for “stvwx”, it’s endIndex is actually before the beginIndex, and it isn’t returning anything.

ohhh my goodness makes sos much sense, thank you so much!

I was trying to have range be a slice of the alphabet that contained all the letters that are supposed to be in str. but my second argument was wrong so sometimes the second argument was before the first