Tell us what’s happening:
Describe your issue in detail here.
**Your code so far**
function rot13(str) {
console.log(str)
var alphaBet = "ABCDEFGHIJKLMNOPQRSTUVWXYZ";
console.log(alphaBet)
var shiftedAlpha = "";
var deCoded = " ";
//shifted alphabet
for(let i = 0; i<alphaBet.length; i++) {
var offset = (i + 13) % alphaBet.length;
shiftedAlpha += alphaBet[offset]; }
console.log(shiftedAlpha)
//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]; }
console.log(result)
return result;
}
rot13("SERR PBQR PNZC");
SERR PBQR PNZC
ABCDEFGHIJKLMNOPQRSTUVWXYZ
NOPQRSTUVWXYZABCDEFGHIJKLM
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: