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
*/