Tell us what’s happening:
The algorithm is working, the console show that the input “SERR PBQR PNZC” is coming out as “FREE CODE CAMP” and I’m returning the variable that should have the deciphered string but the site is not letting me pass the tests.
What am I missing?
Your code so far
function rot13(str) {
let Result = [];
const BASE = 65;//letter A in utf-16, so i can have a closed range
const LIMIT = 90;// Z in UTF-16, or I hope so, I'm disapoint I had to look this up
const ROTATION = 13;//C style all caps constant like if javasctip had a preprocessor
/*loop that evaluates each letter*/
for(let Index = 0; Index <= str.length; Index++)
{
let Carrier = str.charCodeAt(Index);
/*ladder that decides what to do with the character and keeps the rotations discreet*/
if(Carrier < BASE)
{
Result.push(String.fromCharCode(Carrier));
}
else if((Carrier + ROTATION) > LIMIT)
{
Carrier = Carrier % ROTATION;
Carrier = Carrier + BASE;
Result.push(String.fromCharCode(Carrier));
}
else
{
Carrier = Carrier + ROTATION;
Result.push(String.fromCharCode(Carrier));
}
}
Result = Result.join("");
console.log(Result);
return Result;
}
rot13("SERR PBQR PNZC");
Your browser information:
User Agent is: Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:109.0) Gecko/20100101 Firefox/115.0
Challenge: JavaScript Algorithms and Data Structures Projects - Caesars Cipher
Link to the challenge: