Tell us what’s happening:
Your code so far
function rot13(str) { // LBH QVQ VG!
var newStr = str.split("");
var decoder = [];
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","A","B","C","D","E","F","G","H","I","J","K","L","M"];
for(var i=0; i<newStr.length; i++){
if(alphabet.indexOf(newStr[i])===-1){
decoder.push(newStr[i]);
}else{
for(var j =0; j<alphabet.length; j++){
if(newStr[i]===alphabet[j]){
decoder.push(newStr[j+13]);
}}
}
}
return decoder.join("");
}
// 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) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/67.0.3396.87 Safari/537.36
.
Link to the challenge:
https://learn.freecodecamp.org/javascript-algorithms-and-data-structures/javascript-algorithms-and-data-structures-projects/caesars-cipher