I keep getting this error at line 28( which is the line where I call the main function) , I tried it on replit.com also but did not work.
My logic so far is to have an array of alphabet, then go through the input string one by one and look its index in alphabet. when I get the index if its below 12(letter:M) then add 13 to the iterator and get the letter from alphabet array
else if its higher than 12, meaning it will need to go beyond the last letter and start all over again , then I subtract 13 from the iterator and that difference will get me the letter from alphabet array
**Your code so far**
function rot13(str) {
// console.log(str.split(""))
const strArr = str.toLowerCase().split("")
let indexArr=[]
let char;
const alphabet = ["a","b","c","d","e","f","g","h","i","j","k","l","m","n","o","p","q","r","s","t","u","v","w","x","y","z"];
// for each to go over input to get each letter's index in alphabet array
strArr.forEach(letter => {
// console.log(alphabet.indexOf(letter))
return indexArr.push(alphabet.indexOf(letter))
})
console.log(indexArr)
// going over the returned indexArr that has the index for the needed chars
for(let i =0; i < indexArr.length; i++){
if (indexArr[i] <= 12){
console.log(alphabet)
char = char + alphabet[indexArr[i] + 13]
} else if(indexArr[i] > 12) {
char = char + alphabet[indexArr[i] - 13]
}
return char;
}
rot13("SE");
function rot13(str) {
return str;
}
rot13("SERR PBQR PNZC");
**Your browser information:**
User Agent is: Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/99.0.4844.51 Safari/537.36
Challenge: Caesars Cipher
Link to the challenge: