Caesar cipher decoding

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

  **Your code so far**

function rot13(str) {
var shiftedAlpha = "";
var deCoded = " ";
//shifted alphabet
for(let i = 0; i<alphaBet.length; i++)  {
  var offset = (i + 13) % alphaBet.length;
  shiftedAlpha += alphaBet[offset];   }
//now step thru the coded string & decode
let result = "";
str = str.toUpperCase();

for(let i = 0; i< str.length; i++)  {
if(!/[A-Z]/.test (str[i]))  {
  result += str[i]; }
let index = shiftedAlpha.indexOf(str[i]);
result += alphaBet[index];  }

return result;

rot13("SERR PBQR PNZC");

FREE undefinedCODE undefinedCAMP

I have decoded the cipher, but I have undefined between the decoded words.
I added an if test to let the spaces pass through. It worked, but the undefined is still there. I have run out of ideas.
I don’t see any characters or non characters that would trigger this.
Any hints would be appreciated.

  **Your browser information:**

User Agent is: Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/98.0.4758.109 Safari/537.36

Challenge: Caesars Cipher

Link to the challenge:

Hey! My post is very late and I’m sure you’ve managed to solve this but I’d take another look at your code block where you check for special characters.

It’s a very small thing but you never skip the iteration for when that condition is fulfilled.
If you add continue; or something similar in that block, then you’ll move on to the next iteration. Otherwise you still add undefined from the rest of the for loop.

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