Tell us what’s happening:
Hi, as always, there are some mathematical imprecisions in the code but what im concerned about is why the loop does not continue workin after processing the first letter.
Your code so far
function rot13(str) {
var map = ['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'];
str = str.split("");
for (var i = 0; i < str.length; i++) {
var e = map.indexOf(str[i]);
if (e > 13) {
str[i] = map[e-12];
} else {
str[i] = map[e+12];
}
}
str.join();
return str;
}
rot13("SERR");
Your browser information:
Your Browser 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://www.freecodecamp.org/challenges/caesars-cipher