JavaScript Algorithms and Data Structures Projects - Caesars Cipher

Tell us what’s happening:
My code is passing the tests on the visual studio, except the last one and I can’t understand why. It is supposed to mount the string when it passes the last if (word == element), but for some reason isn’t.

function rot13(string) {
    let tempString = new String(string).toUpperCase()
    let target = [...tempString]

    let alphabet = ['A', 'B', 'C', 'D', 'E', 'F',
                    'F', 'H', 'I', 'J', 'K', 'L',
                    'M', 'N', 'O', 'P', 'Q', 'R', 'S',
                    'T', 'U', 'V', 'W', 'X', 'Y', 'Z']
    let alphaCypher = [] //preenchido pelo laço for
    let str = ""    

    for (i = 0; i < 26; i++) {
        sum = i + 13
        if (sum > 25) sum = i + 13 - 26 //resetar a contagem na ultima letra do alfabeto
        alphaCypher.push(alphabet[sum])
    }

    target.map(word => {
        if (alphabet.indexOf(word) > 0){
            alphabet.map((element, index) => {
                if (word == element) return str += alphaCypher[index]
         })
        } else return str += word  
    })
    return str
    
}

Your browser information:

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

Challenge: JavaScript Algorithms and Data Structures Projects - Caesars Cipher

Link to the challenge:

Check the characters in your alphabet. You’re missing one and you have a duplicate of another.

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