Tell us what’s happening:
I’m getting a ‘Potential infinite loop error’ on line 9 (the If statement). Last time I tried to override the protection, I had a bad time.
Your code so far
function rot13(str) { // LBH QVQ VG!
var regular = 'ABCDEFGHIJKLMNOPQRSTUVWXYZ'.split('');
var reverse = 'NOPQRSTUVWXYZABCDEFGHIJKLM'.split('');
var regExp = /[A-Z]/ ;
var newArr = [];
for (i = 0; str.length; i++){
if (regExp.test(str[i])){
var int = regular.indexOf(str[i]);
newArr.push(reverse[int]);
} else {
newArr.push(str[i]);
}
}
return newArr;
}
// Change the inputs below to test
rot13("SERR PBQR PNZC");
Link to the challenge:
https://www.freecodecamp.org/challenges/caesars-cipher