Skip to content

Commit 8baa854

Browse files
committed
down the rabbit hole we go
1 parent 5b8b374 commit 8baa854

File tree

1 file changed

+20
-0
lines changed

1 file changed

+20
-0
lines changed

Caesars_Cipher/script.js

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -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

Comments
 (0)