# JavaScript Algorithms and Data Structures Projects - Caesars Cipher

Hello, I need help. what’s wrong with my code?? I have no idea…

``````function rot13(str) {
const alphabets = "NOPQRSTUVWXYZABCDEFGHIJKLMNOPQRSTUVWXYZ"

return str.split("").map((letter) => {
alphabets.lastIndexOf(letter)

if(index === -1) {
return letter
}

return alphabets[index - 13]
}).join("")

}
``````
``````function rot13(str) {
const alphabets = "NOPQRSTUVWXYZABCDEFGHIJKLMNOPQRSTUVWXYZ"

return str.split("").map((letter) => {
alphabets.lastIndexOf(letter)

if(index === -1) {
return letter
}

return alphabets[index - 13]
}).join("")

}

rot13("SERR PBQR PNZC");
``````

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

Challenge: JavaScript Algorithms and Data Structures Projects - Caesars Cipher

when i put your code into my editor I see an error

ReferenceError: index is not defined

Do you think you should handle that error?

No I don’t think I can handle it.

what do you think this part means?

No I have no idea… what to do this.

Here you make a comparison of `index` to the value `-1`. Where is `index assigned a value` before this comparison is made?

1 Like
``````function rot13(str) {
const alphabets = "NOPQRSTUVWXYZABCDEFGHIJKLMNOPQRSTUVWXYZ"

return str.split("").map((letter) => {
const index = alphabets.lastIndexOf(letter)

if(index === -1) {
return letter
}

return alphabets[index - 13]
}).join("")

}

rot13("SERR PBQR PNZC");
``````

I got it!!! Thank you so much!!