I have finally completed the challenge, has been a tough week
for(let x = 0; x < unicodes.length; x++) {
result += String.fromCharCode(unicodes[x]);
}
The final error was that the final loop was adding a whitespace character to the end of the string so changed the iteration to < rather than <=.
Thanks for all your help guys
Final solution:
function rot13(str) { // LBH QVQ VG!
let unicodes = [];
let result = "";
for(let i = 0; i < str.length; i++) {
if(str.charCodeAt(i) >= 0 && str.charCodeAt(i) <= 64) {
unicodes.push(str.charCodeAt(i));
} else if(str.charCodeAt(i) >= 65 && str.charCodeAt(i) <= 77) {
unicodes.push(str.charCodeAt(i) + 13);
} else if(str.charCodeAt(i) <= 90) {
unicodes.push(str.charCodeAt(i) - 13);
}
}
for(let x = 0; x < unicodes.length; x++) {
result += String.fromCharCode(unicodes[x]);
}
//console.log(result);
return result;
}
// Change the inputs below to test
rot13("SERR PBQR PNZC");