Caesars Cipher - stuck with an array of letters

So I have converted the coded letters into the real ones but now I have ended up with an array of all the correct letters like this:

(14) [“F”, “R”, “E”, “E”, " ", “C”, “O”, “D”, “E”, " ", “C”, “A”, “M”, “P”]
(11) [“F”, “R”, “E”, “E”, " ", “P”, “I”, “Z”, “Z”, “A”, “!”]
(10) [“F”, “R”, “E”, “E”, " ", “L”, “O”, “V”, “E”, “?”]

I need to string (no pun intended) these elements together to make words and sentences but I am not sure what to use. Any hints in the right direction would be appreciated!

Your code so far


function rot13(str) { // LBH QVQ VG!

// a = 65, b = 66, c = 67 etc etc
  var letters = /^[A-Za-z]+$/;
  var result = [];
  
  //get the UTF code for each letter; skip non-alpha 
    for (i=0; i<str.length; i++){
    
      if (str[i].match(letters)){
        var UTF = str.charCodeAt(i);
        var UTFplus = UTF + 13;
      
        if (UTFplus <= 90){
          var char = String.fromCharCode(UTFplus);
          result.push(char);
        }else{
          var UTFplus90 = UTFplus-90;
          var UTFextra = UTFplus90 + 64;
          var char1 = String.fromCharCode(UTFextra);
         result.push(char1);
      }
    }else{
      result.push(str[i]);
    }
   }
      
    
  console.log(result);
  return result;
}

// Change the inputs below to test
// rot13("SERR PBQR PNZC");


Your browser information:

Your Browser User Agent is: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/65.0.3325.181 Safari/537.36.

Link to the challenge:
https://www.freecodecamp.org/challenges/caesars-cipher

You should look up the join() function.

2 Likes

Thanks @ArielLeslie! That worked perfectly.