Tell us what’s happening:
I think my answer is similar to the suggested answer but why cant it returns the same answer??
Your code so far
function rot13(str) {
var a = str.split("");
var answer = [];
for(var i=0; i< a.length; i++){
if(str.charCodeAt(a[i])<65 || str.charCodeAt(a[i])>90 ){
answer.push(String.fromCharCOde(a[i]))
}else if(str.charCodeAt(a[i])<78){
str.charCodeAt(a[i])+ 13;
answer.push(String.fromCharCode(str.charCodeAt(a[i])+ 13));
}else {
str.charCodeAt(a[i])- 13;
answer.push(String.fromCharCode(str.charCodeAt(a[i])- 13));
}
}
return answer.join("");
}
console.log(rot13("SERR PBQR PNZC"));
Your browser information:
User Agent is: Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_6) AppleWebKit/605.1.15 (KHTML, like Gecko) Version/14.0.2 Safari/605.1.15
.
Challenge: Caesars Cipher
Link to the challenge: