This is the challenge: Caesars Cipher- the letters are shifted by 13 places. Thus 'A' ↔ 'N', 'Q' ↔ 'D', and so on.
A function that takes a ROT13 encoded string as input and returns a decoded string. All letters will be uppercase. Don't transform any non-alphabetic character (i.e. spaces, punctuation), but do pass them on.
*I am getting the correct output but currently, each alphabet is a single string. Is there a way to combine all the individual alphabets into one single sentence *
function rot13(str) {
var original = str.split('')
var alphabet = "ABCDEFGHIJKLMNOPQRSTUVWXYZ".split('')
let i = 0;
while(i<original.length){
let indexVal = alphabet.indexOf(original[i])
if(indexVal>= 13){
indexVal -=13
}else if(indexVal===-1){
indexVal = 33
}
else{
indexVal += 13
}
var final = alphabet[indexVal]
i++;
console.log(final)
}
}
rot13("SERR CVMMN");//should log FREE PIZZA
/*
currently logs:
F
R
E
E
undefined
P
I
Z
Z
A
undefined
*/
Figured it out