Missing letters - trouble figuring out solution

Do you have any idea why this doesn’t work ?

function fearNotLetter(str) {
  
  var final = [];
  
  for (i = 0; i < str.length; i++) {
    var a = str[i].charCodeAt(0); 
    var b = (str[i].charCodeAt(0)) + 1;
    
    if (b != a + 1) {
      final.push(String.fromCharCode(a + 1));  
    }
  }
  return final;
}

fearNotLetter("abce");

For me the program is lopping through the parameter string, putting inside a the char code of str[i] and in b the char code of str[i + 1]. So then if b != a + 1 this should mean there is a missing character and I should add it to my final array right ?

I know I didn’t handle the undefined return and I’m not sure if there are two letter missing in a row he will act the right way but one problem at the time, I would like to get why this doesn’t work

I think the problem comes from

  if (b != a + 1) {
      final.push(String.fromCharCode(a + 1));  
  }

Still block, this is driving me crazy

Hey yeah I was saying “maybe instead of poping a new subject again i can bother you one more time” haha

So next time I will open new topic for each different chall sorry

Yeah I know I return an array, I was returning final.join() but I cut the .join() to test.

With join it return nothing, without it return an empty array …

For me when I say
a = ascii code of str[i]
b = ascii code of str[i] + 1

Then if b is not equal to a + 1 that mean that b is not the following character of the alphabet so I must write in my array the following letter which would be fromCharCode of a + 1

a and b are variables in my code, i should have name them different

on the test “abce” it should do :

a = 97 b = 98 c = 99 d = 100 e = 101

b is equal to a + 1
c is equal to b + 1
e is not equal to c + 1

well at least I think because there is not d in the “abce” test
I’m probably wrong because I think my problem lie in the if statement

Sorry I was wondering if you where talking about the letters or the variables so I precise but I was stupid name them like that …

I understood you ask me if I did write an algorithm before not that you ask me to do it

What’s you’ve wrote is more or less what I was trying to do with if b != a + 1
Because b is the ascii code of str at index + 1
And a is the ascii code of str at index
So if the difference is not 1, there is a missing letter

I think I will start again from nothing and try to find another way

My bad then … I’ve spent more time than I though on that problem, guess I’m starting to get tired if I don’t read properly :confused:

I think my problem came from the fact that I was comparing i and i + 1 but after the last character of the string, charCodeAt of i + 1 was out of the string an so return an error

Hey sorry last night I was really tired I went to sleep …

Today at start again, I tried a different approach but still doesn’t work :

 var first = array[i];
 var second = array[i + 1];

And then it go in the if statement while it wasn’t supposed to.
Took me 20 minutes before I though it may come from the fact that array[i + 1] when i = array.length is out of the str
So I’ve tried with i starting at 1, first is array[i - 1] and second just array[i] and … it work

So much time spent on that simple problem … but at least when you get the solution that’s a strange feeling, feel rewarding even if I’ve spent hours to do a very simple stuff

Here is my final answer to this challenge
image

I’m reading your answers, thanks for the
"FYI - The following to lines of code accomplish the same thing in your original code"
Because it’s typically the stuff I don’t get, I suck at reading documentation, I always confuse myself

What I love to do, instead of documentation is reading examples of code and try to figure out how it work
I mean I should do both because sometimes there are very importants infos in the documentation but it is clearer to me with examples than with documentation.

I always wonder why the guy who wrote documentation that would be read by thousands of people doesn’t make a little pedagogic effort :see_no_evil:

Your blurr solution is better than mine I think

It’s common newbie stuff, we always complicate the process instead of keeping it simple

I was planning to use one, but didn’t work so I end up with two because I wanted to see where the process fail
I’ll try to use one now

Do you know why sometimes I get this in the error section ?
image

Ok and how do you run the code there ?

Yeah but I mean I don’t see the run button ><"
Must be blind or something

Ok, I went in source, new snippet, paste the code, run it and it says nothing :confused:

In the mean time I end up in metamask js file, 6500 lines of code, seems crazy to me, I will see if I understand something