Tell us what’s happening:
So the code works but it returns undefined on stuff like space. Any fix for that?
I’m expecting that it is the method “replace” is the cause but I tried to use “letter = …” and it didn’t work as well, a fix please?
Your code so far
function rot13(str) { // LBH QVQ VG!
var Alphabet = ["A","B","C","D","E","F","G","H","I","J","K","L","M","N","O","P","Q","R","S","T","U","V","W","X","Y","Z"];
return str.toUpperCase().split("").map((letter,i) => {
if (/[N-Z]/.test(letter)){
return letter.replace(/[N-Z]/,Alphabet[Alphabet.indexOf(letter)-13]);
}
else if(/[A-M]/.test(letter)){
return letter.replace(/[A-N]/,Alphabet[Alphabet.indexOf(letter)+13])
console.log(letter)
}
});
}
// Change the inputs below to test
rot13("SERR PBQR PNZC");
Your browser information:
User Agent is: Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:60.0) Gecko/20100101 Firefox/60.0
.
Link to the challenge:
https://learn.freecodecamp.org/javascript-algorithms-and-data-structures/javascript-algorithms-and-data-structures-projects/caesars-cipher