21 Day Coding Challenge

Challenge 20 code ran but it says functions aren’t working properly


Can someone help me find what mistake i am making here??


i think when you write message.split(" “) it splits it into words. However, using, message.split(”") will split it into a char array. Not sure tho

1 Like

Tried that …that is not the issue.


You also are only using == instead of ===
Also you don’t really need an extra array variable but its fine

You are over complicating the if/else statements a bit. Try to think about it in a simpler way


Try to change number 0-5 to string “0” in the if/else condition and use === as well


you have to return!!!
return array.join("");


Did it still not solved


I didn’t get you 5 and 2 are used in other places as well they can’t be “O” and number 0 is already set to string O and i have added === in all statements now still not solved


Added return but still not solved


a few things.

  1. do var res = message.split(’’); this ensures you are splitting characters and not words.
  2. do not do array = res; there is no point to doing this, just work with res directly, so everywhere you wrote array, use res.
  3. in your loop array, the condition should be i < array.length, and not i <= array.length because you are starting at i = 0. Including array.length in your loop condition results in index out of bound, remember that arrays start at index 0 and not at index 1. an array such as [1,2, 3, 4, 5] has length 5, but has four indices, where 1 is 0th index, 2 is the 1st index, … and 5 is 4th index, so remember it is always the length of the array minus 1 that you’d like, hence i < array.length (or just i <= (array.length - 1)
  4. in your if statements, do “1” rather than 1, and use === to compare.
  5. I have seen the discussion about array[73] = “l”; here on the forum. I solved this problem without using this line though, for now, I would suggest getting rid this line completely.
  6. no need to break, if you break, your loop only runs one time, and so it would only ever check the first element in your array, which you don’t want to do. You want to check your whole array and every single index of it, so get rid of the break completely

I am sorry if this is too much to read, but once you understand what I have written, going back to your code and fixing these issues should not be a problem as most of these issues are quick fixes to your code.


Wow thanks alot it worked for me!!

1 Like

no problem! glad to hear it worked out!


I now I don’t have nothing related to this conversation but I used the tips of @cyberchild and it worked!

Thank you very much @cyberchild :grin::pray::+1:

1 Like

Tank You c’ ça qu’il me manque. C’était le retour.


Hey i tried my function few times but i cant quiet get which part am i missing right here?

King Seb can you help me out :sweat_smile:


console.log(message); :wink:

You’re sure you want to submit that to the validator?

1 Like

OH my godd! i just read the last line that said, :

:sweat_smile::sweat_smile: i honestly think most of our common mistakes are due upon not fully reading the actual instuctions :slightly_smiling_face:


My code is fairly similar but it’s apparently not solving the challenge. Any insight?

  function decodeMessage(message) {
  var str = message.split('');
  for (var i = 0; i < str.length; i++) {
    if ( str[i] === "0" ) { 
      str[i] = "o";
    } else if ( str[i] === "1" ) { 
      str[i] = "i";
    } else if ( str[i] === "2" ) { 
      str[i] = "u";
    } else if ( str[i] === "3" ) { 
      str[i] = "e";
    } else if ( str[i] === "4" ) { 
      str[i] = "a";
    } else if ( str[i] === "5" ) { 
      str[i] = "y";

I’m not sure it’s the only error (haven’t tested your code yet), but wouldn’t it be better to run that outside of your loop?

You also don’t have a return statement… :frowning:

Perhaps you could combine both of those :wink: (I’ve just ran it and it’ll work)


Indeed :slight_smile: I was missing a couple of “details”.

Thank you!

1 Like