I got a problem with this challenge. This code seems to not recognizing a question mark ( 63 ) or a exclamation mark ( 43 ) . I had the same issue with a space ( 32 ). For that I set up a else if statement just for that case, otherwise the code is ignoring spaces as well. What did I wrong and even with my third else if statement why is it ignoring all marks and sapces?
thank you very much in advance. Im going nuts because I cant figure it out right now…
Your code so far
function rot13(str) { // LBH QVQ VG!
var newArr = [];
// loop through str, convert to array with numbers
for (var i = 0; i < str.length; i++) {
var cc = str.charCodeAt(i);
if ( cc >= 65 && cc <= 77 )
{
newArr.push( cc + 13);
}
else if ( cc >= 78 && cc <= 90 )
{
newArr.push( cc -13 );
}
else if ( cc > 90 && cc < 65 )
{
newArr.push( cc );
}
else if ( cc == 32 )
{
newArr.push( cc );
}
}
var toString = String.fromCharCode.apply(null, newArr);
return toString;
}
// Change the inputs below to test
rot13("! ? . SERR");
Your browser information:
Your Browser User Agent is: Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:57.0) Gecko/20100101 Firefox/57.0.
Link to the challenge:
https://www.freecodecamp.org/challenges/caesars-cipher
