Hi all, here is my working where I was trying to think out a way of approaching the Caesar Cipher before tomorrow’s class. I did not get anywhere, but wanted to record what I did here in case anyone has any thoughts. Also, if I have time, I will try and improve my code after viewing tomorrow’s video.
function rot13(str) {
switch (str) {
case “A”:
console.log(“N”);
break;
case “B”:
console.log(“O”);
break;
case “C”:
console.log(“P”);
break;
case “D”:
console.log(“Q”);
break;
case “E”:
console.log(“R”);
break;
case “F”:
console.log(“S”);
break;
case “G”:
console.log(“T”);
break;
case “H”:
console.log(“U”);
break;
case “I”:
console.log(“V”);
break;
case “J”:
console.log(“W”);
break;
case “K”:
console.log(“X”);
break;
case “L”:
console.log(“Y”);
break;
case “M”:
console.log(“Z”);
break;
case “M”:
console.log(“A”);
break;
case “N”:
console.log(“B”);
break;
case “O”:
console.log(“C”);
break;
case “P”:
console.log(“D”);
break;
case “Q”:
console.log(“E”);
break;
case “R”:
console.log(“F”);
break;
case “S”:
console.log(“G”);
break;
case “T”:
console.log(“H”);
break;
case “U”:
console.log(“I”);
break;
case “V”:
console.log(“J”);
break;
case “W”:
console.log(“K”);
break;
case “X”:
console.log(“L”);
break;
case “Y”:
console.log(“M”);
break;
case “Z”:
console.log(“N”);
break;
default:
console.log(“I am lost”);}
}
// I used console.log for the switch cases as this was the only way i could get an output - answer = “N”, e.g., did nothing
//Why is there a separate “undefined” line under each console.log return???
// How do i do multiple letter conversions at the same time? Turn a string into an array then back into a string after conversion? If so, how do i do this?
console.log(rot13(“A”));
console.log(rot13(“B”));
console.log(rot13(“M”));
console.log(rot13(“SERR PBQR PNZC”));
contents of my console:
N
undefined
O
undefined
Z
undefined
I am lost
undefined