21 Day Coding Challenge

Challenge 20 - Stuck


I can’t seem to figure this one out. Here is my code, any suggestions are appreciated:

function decodeMessage(message){
  radio.message = radio.message.split(" ");
  for(var i = 0; i < radio.message.length; i++){
  radio.message[i] = radio.message[i].replace(/0/g, "o")
  radio.message[i] = radio.message[i].replace(/1/g, "i")
  radio.message[i] = radio.message[i].replace(/2/g, "u")
  radio.message[i] = radio.message[i].replace(/3/g, "e")
  radio.message[i] = radio.message[i].replace(/4/g, "a")
  radio.message[i] = radio.message[i].replace(/5/g, "y")
  return radio.message.join(" ");


The message we’re working with isn’t related to that…



Also adding to Seb’s comment
You don’t really need the loop if you are doing /_/g, '_'

message.replace(/0/g, "o").replace(/1/g, "i") // etc etc etc


1 Like

If you want to use split - then just split the message on the digit, then join back with the character.
e.g. msg = msg.split(‘4’).join(‘a’);
No need to loop here either.



got it thanks, thanks