freeCodeCamp / freeCodeCamp

freeCodeCamp.org's open-source codebase and curriculum. Learn to code for free.
https://contribute.freecodecamp.org
BSD 3-Clause "New" or "Revised" License
404.51k stars 37.88k forks source link

Getting the right answer, still not passing #7549

Closed BCParanormal closed 8 years ago

BCParanormal commented 8 years ago

Challenge Caesars Cipher has an issue. User Agent is: Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/48.0.2564.116 Safari/537.36. Please describe how to reproduce this issue, and include links to screenshots if possible.

My code:

function rot13(str) { // LBH QVQ VG!
  var result = ' "';

  for(i = 0; i < str.length; i++){

    if(str.charCodeAt(i) == 32){result += ' ';}
    else if (str.charCodeAt(i) < 65 || str.charCodeAt(i) > 90){result += String.fromCharCode(str.charCodeAt(i));}
    else if (str.charCodeAt(i) < 77){result += String.fromCharCode(str.charCodeAt(i) + 13);}
    else{result += String.fromCharCode(str.charCodeAt(i) - 13);}

  }
 result += '" ';

  return result;
}

// Change the inputs below to test
rot13("SERR PBQR PNZC");
ltegman commented 8 years ago

You're adding double quotes and a space around the output. The double quotes are simply there to signify the input and output are a string. They should not be in your output. In the future please visit the Help Chat to confirm what you're seeing is a bug and not an issue with your solution. Thanks and happy coding!

BCParanormal commented 8 years ago

Yes I only did that because my original code without the double quotes would not pass, the problem still stands- I get the proper result but it will not pass me

alistermada commented 8 years ago

The code you posted (minus the extra quotes) is still incorrect. The second test expects the result to be FREE PIZZA!" but your code outputs "FREE PI@@A!".

Hint: One of the numbers in your code is off by one.

BCParanormal commented 8 years ago

Thanks I can get the code to output Free Pizza! by changing the 2nd else if to >= 77 so i get the right answer now but still won't pass

BCParanormal commented 8 years ago

`function rot13(str) { // LBH QVQ VG! var result = ' ';

for(i = 0; i < str.length; i++){

if(str.charCodeAt(i) == 32){result += ' ';}
else if (str.charCodeAt(i) < 65 || str.charCodeAt(i) > 90){result += str.charAt(i);}
else if (str.charCodeAt(i) < 78){result += String.fromCharCode(str.charCodeAt(i) + 13);}
else{result += String.fromCharCode(str.charCodeAt(i) - 13);}

}

return result; }

// Change the inputs below to test rot13("GUR DHVPX OEBJA QBT WHZCRQ BIRE GUR YNML SBK."); `

BCParanormal commented 8 years ago

Ok this code passes all tests manually, editor still won't pass it

alistermada commented 8 years ago

Remove the space here: var result = ' ';

BCParanormal commented 8 years ago

Yes already figured that out. Such a simple mistake . Thank you so much for putting up with this cranky old man