Challenge **Caesars Cipher** JS Algorithms and Data Structures Cannot pass

Good day to all. Help please. This is one of the 5 project tasks. This is decoding using the Caesar cipher. At me all tests pass for all test data which are offered on a site freecodecamp. But on a site all tests are missing. Thanks

Caesars Cipher

function rot13(str) {
var alphabet = "abcdefghijklmnopqrstuvwxyz".toUpperCase()
var result = ''
for (const letterKey in str.toUpperCase()) {
    let positionAlfa = -1//findAlphabetPosition(alphabet,str[letterKey])
    for (const alphabetKey in alphabet) {
        if (alphabet[alphabetKey] === str[letterKey]) {
            positionAlfa = alphabetKey
    if (positionAlfa === -1) {
        result = result.concat(str[letterKey])
    } else {
        var decodeLetter = ''//decode(alphabet,positionAlfa)
        let index = positionAlfa - 13 >= 0 ? positionAlfa - 13 : alphabet.length + (positionAlfa - 13)
        decodeLetter = alphabet[index]
        result = result.concat(decodeLetter)

return str;

rot13("SERR PBQR PNZC");

Your browser information:

User Agent is: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/90.0.4430.93 Safari/537.36.

Challenge: Caesars Cipher

Link to the challenge:

You are console logging the result but returning the original string. That will screw with the outcome :slight_smile:

:sweat_smile: Colleague, thank you for taking the time to help.

1 Like

hi there,

For this challenge, I first created an array of ‘alphabet soup’; so, instead of having an alphabet length of 26, I doubled it.

Then, split the given ‘str’; in that way, you’d be able to deal with each character and decode it;

Then, create something like this:

" for (let k = 0; k < splitStrArray.length; k++) {
let searchIndex = rotArray.indexOf(splitStrArray[k]);
if (searchIndex >= 0) {
decodedArray.push(rotArray[searchIndex + 13]);
} "

Hope you could figure out the rest. Happy coding!

In your eagerness to help, you seem to have accidentally overlooked the fact that OP’s code works fine and just had a simple error with the return value.

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