I'm trying to make an AtBash cipher but the for loop in AtBash()
var i = 0;
function ReverseString(s) { //FOR THE LOVE OF GOD .reverse() NEEDS TO WORK WITH STRINGS!
var o = '',
i = s.length;
while (i--) {
o += s.charAt(i);
}
return o;
}
function AtBash(input1) {
var EncodedString = "";
var alphabet = "abcdefghijklmnopqrstuvwxyz";
var ReversedAlphabet = ReverseString(alphabet);
for (i = 0; i < input1.lenght; i++) {
var CurrentLetter = input1.indexOf(i);
console.log(CurrentLetter); //To test if for loop runs
var EncodedLetter = ReversedAlphabet.charAt(CurrentLetter);
console.log(EncodedLetter); //To test if for loop runs
EncodedString = EncodedString + EncodedLetter;
}
return EncodedString;
}
console.log("Test1");
console.log(AtBash("Test1"));
console.log("Test2");
console.log(AtBash("Test2"));
console.log("Gvhg3");
console.log(AtBash("Gvhg3"));
My question is what is wrong with my code? Is it because I'm calling my function wrong or returning nothing?