Can someone help me find what is wrong on my code?

Tell us what’s happening:
Describe your issue in detail here.

All the calls from the rot13 decipher challenge output the expected result, but none of the calls actually pass …

I’ve tried the option to reset the code many times.

Examples:
rot13("SERR PBQR PNZC") should decode to the string FREE CODE CAMP

rot13("SERR CVMMN!") should decode to the string FREE PIZZA!

rot13("SERR YBIR?") should decode to the string FREE LOVE?

rot13("GUR DHVPX OEBJA SBK WHZCF BIRE GUR YNML QBT.") should decode to the string THE QUICK BROWN FOX JUMPS OVER THE LAZY DOG.

  **Your code so far**

function rot13(str) {
const alphabet = [..."ABCDEFGHIJKLMNOPQRSTUVWXYZABCDEFGHIJKLMNOPQRSTUVWXYZ"];
let rot = [...str];
let cipher = [];

for (let i = 0; i < rot.length; i++){
    let newIndex = alphabet.indexOf(rot[i]);

    if(alphabet.indexOf(rot[i]) == -1){
      cipher.push(rot[i]);
    } else {
    cipher.push(alphabet[newIndex + 13]);

    }

}

   return cipher.join(" ");
}

console.log(rot13("SERR PBQR PNZC"));
  **Your browser information:**

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

Challenge: Caesars Cipher

Link to the challenge:

The output is not was expected.

Expected:

FREE CODE CAMP

What you return:

F R E E   C O D E   C A M P

Those aren’t the same thing.

This line here is causing a problem:

return cipher.join(" ");

I think you should examine this line closely. What does the parameter in the join method do? You should examine that closely.

When I fixed this, your code passed for me.

2 Likes

thanks you’re right, I must have had brain freeze. :grinning:

It happens. We all have a mistake like that that just drives us crazy.

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