We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
There was an error while loading. Please reload this page.
1 parent 5b8b374 commit 8baa854Copy full SHA for 8baa854
Caesars_Cipher/script.js
@@ -0,0 +1,20 @@
1
+function rot13(str) {
2
+ // first set an alphabeth variable
3
+ let alphabet = "ABCDEFGHIJKLMNOPQRSTUVWXYZ"
4
+ // create an empty string that stores the answer
5
+ let answer = ""
6
+ // run through str with a for loop
7
+ for (let i = 0; i < str.length; i++) {
8
+ // get the index and loop through with an if statement
9
+ if (alphabet.indexOf(str[i]) >= 13) {
10
+ answer += alphabet[alphabet.indexOf(str[i]) - 13]
11
+ } else if (alphabet.indexOf(str[i]) < 13 && alphabet.indexOf(str[i]) > -1) {
12
+ answer += alphabet[alphabet.indexOf(str[i]) + 13]
13
+ } else {
14
+ answer += str[i]
15
+ }
16
17
+ return answer;
18
19
+
20
+ console.log(rot13("SERR PBQR PNZC"));
0 commit comments