Missing Letters - why doesn't this work

I’m confused as to why this isn’t working, can anyone shed some light on it?

Your code so far


function fearNotLetter(str) {
  const alphabet = [a,b,c,d,e,f,g,h,i,j,k,l,m,n,o,p,q,r,s,t,u,v,w,x,y,z];
  
  let stringArray = str.split("");
  let startingIndex = alphabet.indexOf(stringArray[0]);
  let answer = ""

  for (i = startingIndex; i < startingIndex + stringArray.length; i++) {
    if (stringArray.includes(alphabet[i]) !== true) {
      return answer = alphabet[i]
    } else {
      return undefined;
    }
  }

 return answer;
}

fearNotLetter("abce");

Your browser information:

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

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

[quote=“HansGrubername, post:1, topic:256458”]
const alphabet = [a,b,c,d,e,f,g,h,i,j,k,l,m,n,o,p,q,r,s,t,u,v,w,x,y,z];
v[/quote]

I didn’t go into detail but your array didn’t consist of strings:
const alphabet = ["a",...

So console says: a is not defined

2 Likes