Caeser Cipher Project -- works on but not on FCC help!

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 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 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 and not on FCC. Thank you in advance!

Your code so far

function rot13(str) { // A = 65 Z = 90
  const cipherArr = [['A','N'],
  const decoded = [];
  for(let i=0; i < str.length; i++){
    if (str.charCodeAt(i) < 65 || str.charCodeAt(i) > 90){
    } else {  
     for(let j=0; j < cipherArr.length; j++)
      if(str[i] === cipherArr[j][0])
 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:

I believe it has something to do with the way the linter works. Basically it does not like you not wrapping your for loop and if statement code within { and }. This issue has been fixed on the master branch but has not been deployed to production yet, so until then, you should use the curly brackets for code blocks.

1 Like

Thank you! I see exactly what you mean. I knew it was something silly and simple that I couldn’t see. Arg! I appreciate the help!

Update: added brackets, challenge passed w/flying colors. :slight_smile: