Error in the Caesars Cipher exercise

I have a problem because according to me, the results that my algorithm returns are good, however it does not pass the test. Please help me!

  **Your code so far**

function rot13(str) {

let letters = {
  "A": "N",
  "B": "O",
  "C": "P",
  "D": "Q",
  "E": "R",
  "F": "S",
  "G": "T",
  "H": "U",
  "I": "V",
  "J": "W",
  "K": "X",
  "L": "Y",
  "M": "Z",
  "N": "A",
  "O": "B",
  "P": "C",
  "Q": "D",
  "R": "E",
  "S": "F",
  "T": "G",
  "U": "H",
  "V": "I",
  "W": "J",
  "X": "K",
  "Y": "L",
  "Z": "M",
}

let result = "";

let regexPunctuation = /\W/;

let separate = str.split(" ");

for(let i = 0; i < separate.length; i++){

  for(let j = 0; j < separate[i].length; j++){

    // console.log(separate[i][j])
    //si on tombe sur un caractère différent d'une lettre, on l'ajoute à result
    if(regexPunctuation.test(separate[i][j])){

      result += separate[i][j];

    }

    else{

    // console.log(letters[separate[i][j]])
    result += letters[separate[i][j]];

    };


  }; //second boucle end

  result += " ";

}; //first boucle end

console.log(result);
return result;

};

rot13("SERR PBQR PNZC");
rot13("SERR CVMMN!");
rot13("GUR DHVPX OEBJA SBK WHZCF BIRE GUR YNML QBT.")
rot13("SERR YBIR?")
  **Your browser information:**

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

Challenge: Caesars Cipher

Link to the challenge:

This puts an extra space at the end.

Thank you for the help !

1 Like

This topic was automatically closed 182 days after the last reply. New replies are no longer allowed.