I am about halfway through with the Casesar’s Cipher puzzle. The Algorithm is incomplete, so disregard the last line of code. What I am wondering is why my
for (var i = 0; i < newArray.length; i++) {
unicodeArray.push(newArray[i].charCodeAt());
}
block of code works (I understand I am somehow using a string method on an array)
but this next block of code doesn’t work although very similar.
for (var x = 0; x < minus13Array.length; x++) {
newLetterArray.push(minus13Array[x].fromCharCode());
}
I think I can figure the rest of it out if I can figure this one bit out.
Your code so far
function rot13(str) { // LBH QVQ VG!
var newArray = str.split("");
var newString = "";
var unicodeArray = [];
var minus13Array = [];
var newLetterArray = [];
for (var i = 0; i < newArray.length; i++) {
unicodeArray.push(newArray[i].charCodeAt());
}
for (var j = 0; j < unicodeArray.length;j++) {
minus13Array.push((unicodeArray[j] - 13));
}
for (var x = 0; x < minus13Array.length; x++) {
newLetterArray.push(minus13Array[x].fromCharCode());
}
return newLetterArray;
}
// Change the inputs below to test
rot13("SERR PBQR PNZC");
Your browser information:
Your Browser User Agent is: Mozilla/5.0 (Macintosh; Intel Mac OS X 10.7; rv:54.0) Gecko/20100101 Firefox/54.0.1 Waterfox/54.0.1
.
Link to the challenge: