I tried setting up an array that correlates capital letters with their corresponding Caesar cipher letters, so for example, A would shift 13 places to become N. I attempted to write a code that could generate this transformation, but I seem to have made an error. Can someone assist me in identifying where I went wrong and explain the mistake briefly?
let abcToCesar = [
{abc: "A", cesar: "N"},
{abc: "B", cesar: "O"},
{abc: "C", cesar: "P"},
{abc: "D", cesar: "Q"},
{abc: "E", cesar: "R"},
{abc: "F", cesar: "S"},
{abc: "G", cesar: "T"},
{abc: "H", cesar: "U"},
{abc: "I", cesar: "V"},
{abc: "J", cesar: "W"},
{abc: "K", cesar: "X"},
{abc: "L", cesar: "Y"},
{abc: "M", cesar: "Z"},
{abc: "N", cesar: "A"},
{abc: "O", cesar: "B"},
{abc: "P", cesar: "C"},
{abc: "Q", cesar: "D"},
{abc: "R", cesar: "E"},
{abc: "S", cesar: "F"},
{abc: "T", cesar: "G"},
{abc: "U", cesar: "H"},
{abc: "V", cesar: "I"},
{abc: "W", cesar: "J"},
{abc: "X", cesar: "K"},
{abc: "Y", cesar: "L"},
{abc: "Z", cesar: "M"},
]
function toCaesar(str) {
for(let i = 0; i < str.length-1; i++){
for(let i = 0; i < abcToCesar.length; i++){
if(str.charAt(i) == abcToCesar[i].abc){
str.charAt(i) == abcToCesar[i].cesar
}
else{
return str.charAt(i)
}
}
}
return str;
}
console.log(toCaesar("SERR PBQR PNZC"));