I’m trying to submit my solution to the problem but it keeps getting marked as wrong. Frustrated by this, I tried using the basic solution available in the ‘Get a Hint!’ section, which produced the same output as mine but got marked as right, for some reason. My code is the following:
function rot13(str) { // LBH QVQ VG!
var arr = str.split('');
console.log("\n" + str + ": ");
arr = arr.map.call(str, function(x) {
var code = x.charCodeAt(0);
if (code >= 65 && code <= 77) { // 77 = 90 - 13
console.log(x + " = " + String.fromCharCode(code + 13));
return String.fromCharCode(code + 13);
}
else if (code >= 65 && code <= 90) {
console.log(x + " = " + String.fromCharCode(code -13));
return String.fromCharCode(code - 13);
}
else {
console.log(String.fromCharCode(code) + " = " + String.fromCharCode(code));
return String.fromCharCode(code);
}
}).join('');
}
// Change the inputs below to test
rot13("SERR PBQR PNZC");
I’m using Firefox and checking my solution using the Javascript console, if that’s any help.