Tell us what’s happening:
Hello Campers! I’m working on the Caeser’s cipher challenge. I know my code is not the most elegant solution but I wrote this in the morning before coffee! At any rate, I’m not the best debugger; I particularly get thrown when identical code works in Repl.it but not on FCC. That is the circumstance here. The error being thrown is this:
TypeError: unknown: Cannot read property '0' of undefined
I’m stumped because on Repl.it the code works beautifully and returns a decoded string every time. I’m just about at a 5kyu on CodeWars, so I’m a bit embarrassed that I cannot see what the issue is. Trying to navigate the dev console in Chrome is a little nightmarish when trying to spot what one is doing wrong in the FCC embedded code editor so that wasn’t much help. Bonus points if you can help explain why it works on Repl.it and not on FCC. Thank you in advance!
Your code so far
function rot13(str) { // A = 65 Z = 90
const cipherArr = [['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']
];
const decoded = [];
for(let i=0; i < str.length; i++){
if (str.charCodeAt(i) < 65 || str.charCodeAt(i) > 90){
decoded.push(str[i])
} else {
for(let j=0; j < cipherArr.length; j++)
if(str[i] === cipherArr[j][0])
decoded.push(cipherArr[j][1])
}
}
return decoded.join("");
User Agent is: Mozilla/5.0 (Macintosh; Intel Mac OS X 10_14_4) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/73.0.3683.86 Safari/537.36
.
Link to the challenge: