Caesars Cipher ("-" between spaces)

Tell us what’s happening:
ok i think i have almost solved the problem…
but there is a little bug…which is “-” appearing on the blank strings…as you can see it in the output.
so how can i remove it and have “space” instead.

Your code so far

function rot13(str) { // LBH QVQ VG!
  var arr = [];
  var fixed = [];
  var final = [];
  var result = "";
  for(i = 0; i<str.length; i++){
    fixed.push(val + 13);

  for (j = 0; j<fixed.length; j++){
    if (fixed[j] > 90){

result += String.fromCharCode.apply(null, final);

  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 6.3) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/61.0.3163.100 Safari/537.36.

Link to the challenge:

How can you change your logic so that it only changes the values of characters that are letters?

i was thinking about filter() …but not sure how to use it

filter is generally going to be used to remove values from the array. What you want is for the character codes for non-letters to go into your fixed array without being changed (without adding 13) or for those to be changed back to their original values in your for loop (less efficient of course, but perhaps easier for you since you already have some logic like this).

not happening … a little help here …perhaps

Well, what have you tried since changing your code to the above? What worked? What didn’t? What behaved differently than expected?

Going back to what @ArielLeslie asked you (see below). You are currently adding 13 to the space character’s ascii code (20), so you end up up pushing the value 45 to fixed and 45 is the hyphen character. What about adding an if statement to check for ascii values between a certain range (upper A through upper Z) and only push val + 13 if the if statement evaluates to true?

1 Like