Caesars Cipher is working but the site is not letting me pass

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:

I’m not quite sure what the core issue is, but I recommend you 1) don’t start variable names with capital letters 2) use conventional formatting.

I’m still experimenting to see what’s happening.

The output strings are literally not the targets if you check with ===. I’m suspicious about your handling of non-letter characters.

Yeah, it’s really strange:

    console.log(Result);
    console.log(Result == "FREE CODE CAMP");

and this will print

FREE CODE CAMP
false

Right now I’m thinking that I did not look up the correct values in utf-16, I’ll look more into this and hope it’s an easy fix.

Do a console.log of Result while it is still an array, just before you convert it to a string with join.

Oh! So it was copying null.
Thank you, the take away from this I need to put more console.logs across the program.

This topic was automatically closed 182 days after the last reply. New replies are no longer allowed.