I’m currently doing the Caesar encryption task & i’ve created a solution for it that isn’t working in the FCC compiler but works everywhere else for me?
My Code
https://playcode.io/1001574
I’m not passing the assignment and getting the error “ReferenceError: i is not defined”
I get there’s more elegant ways to solve this, but this is what I came up with
Code:
function rot13(str) {
const alphaValue = {
a: 1,
b: 2,
c: 3,
d: 4,
e: 5,
f: 6,
g: 7,
h: 8,
i: 9,
j: 10,
k: 11,
l: 12,
m: 13,
n: 14,
o: 15,
p: 16,
q: 17,
r: 18,
s: 19,
t: 20,
u: 21,
v: 22,
w: 23,
x: 24,
y: 25,
z: 26,
};
const numValue = {
1: 'a',
2: 'b',
3: 'c',
4: 'd',
5: 'e',
6: 'f',
7: 'g',
8: 'h',
9: 'i',
10: 'j',
11: 'k',
12: 'l',
13: 'm',
14: 'n',
15: 'o',
16: 'p',
17: 'q',
18: 'r',
19: 's',
20: 't',
21: 'u',
22: 'v',
23: 'w',
24: 'x',
25: 'y',
26: 'z',
27: 'a',
28: 'b',
29: 'c',
30: 'd',
31: 'e',
32: 'f',
33: 'g',
34: 'h',
35: 'i',
36: 'j',
37: 'k',
38: 'l',
39: 'm',
40: 'n',
41: 'o',
42: 'p',
43: 'q',
44: 'r',
45: 's',
46: 't',
47: 'u',
48: 'v',
49: 'w',
50: 'x',
51: 'y',
52: 'z',
};
console.log('input: ' + str);
let input = str.toLowerCase();
let accumulator = '';
let allowedChars = [' ', '!'];
for (i = 0; i < input.length; i++) {
if (
input[i] !== ' ' &&
input[i] !== '!' &&
input[i] !== '.' &&
input[i] !== '?' &&
input[i] !== '/' &&
input[i] !== '(' &&
input[i] !== ')'
) {
keyLookup = alphaValue[input[i]];
newKey = keyLookup + 13;
accumulator += numValue[newKey];
} else accumulator += input[i];
}
console.log('output: ' + accumulator.toUpperCase());
return accumulator.toUpperCase();
}
rot13('THE QUICK BROWN FOX JUMPS OVER THE LAZY DOG.');