Solve Caesers cipher Using a Switch?

Solve Caesers cipher Using a Switch?
0

#1

Can anyone show me how to use a switch statement to solve Caesers cipher challenged. I have tried ths code below but it does not work. Can anyone help

rot13(str) { 
var code = "";

switch {switch (str) {
case 'A':
answer = "N";
break;
case 'B:
answer = 'O';
break;
case 'C':
answer = "P";
break;
case 'D:
answer = 'Q"';
break;
case 'E:
answer = "R";
break;
case 'F:
answer = 'S';
break;
case 'G':
answer = "T";
break;
case 'H:
answer = "U";
break;
case 'I':
answer = "V";
break;
case 'J:
answer = 'W';
break;
case 'K':
answer = "X";
break;
case 'L:
answer = 'Y"';
break;
case 'M:
answer = 'Z"';

}
return str; 
}

#2

I cleaned up your code.
You need to use triple backticks to post code to the forum.
See this post for details.


#3

You have missing single quotes in various places in your code (like in 'B, 'D, etc).

You’ll also have to use a loop to iterate over each letters in the string.

Your code could look like

function rot13(str) {
  var code = '';

  for (...) {
    switch (letter) {
      case 'A':
        // add 'N' to `code`
        break;

      case 'B':
        // add 'O' to `code`
        break;

      ...
    }
  }

  return code;
}

#5

Part of your text is blurred. I cannot see it


#6

It’s blurred because it’s a spoiler (contains a solution). Just click on it to remove the blur.


#7

Ah… ok I will not touch it until I figure it out.


#8

You can use for loop to solve this cipher.

If you still can get it checkout this https://github.com/Deityhub/Caesars-Cipher/blob/master/Cipher.js for a rundown of how thr code works.