Troubles with an if statement in Missing Letters Alg

Troubles with an if statement in Missing Letters Alg
0.0 0


Hello all!

So I’ve written a function for the Missing Letters alg:

function fearNotLetter(str) {
var myArray = [];
 for (var i = 0; i<str.length; i++) {
  for (var j = 0; j<myArray.length; j++) {
    if (myArray[j + 1] !== (myArray[j] + 1)){
      return String.fromCharCode(myArray[j] + 1);

my problem is, the program does exactly what it’s supposed to, however, the website also asks that you add an instance for when there are not any missing letters in the sequence. I have tried to add if else and else statments along with just adding return undefined; at the end of my code and every time I add one, the undefined will return, and the actual function to find the missing letter no longer works. Please help


Hi there–

You are very close with this. I will give you four hints… (or, rather three hints, and then if that’s not enough, then hint 4 just gives you the answer. But I’d rather you got it through reading the hints!)

hint: 1

I noticed that in the case of bcd, you algorithm was returning “e.”

hint 2:

Look at the range covered by the second statement of the second for loop

hint 3:

The for loop goes through one more iteration than the length of myArray

hint 4:

Change it to j<myArray.length-1


Thank you for the hints! This is exactly what I needed I’m really glad you didn’t give me the answer. Obviously it was just the second four loop had to have the second statement of j<myArray.length - 1


I cleaned up your code.
You need to use triple backticks to post code to the forum.
See this post for details.