This is project from freecodecamp where a string is encrypt by the values of the letters are shifted by 13 places All letters will be uppercase. Do not transform any non-alphabetic character (i.e. spaces, punctuation), but do pass them on. i test numadd by regex numadd is either equal to num+13 or numadd-26. some letter went wrong and do not return an uppercase letter please someone explain whats wrong
function rot13(str) {
var str2 = '';
var arr1 = []
var arr2 = []
var reg = /[^A-Z]/
// var char
if (str.includes(' ') == false) {
for (let i = 0; i < str.length; i++) {
var char = '';
var numres
let num = str.charCodeAt(i)
// console.log(num)
// var numadd = num + 13;
// if num+13 not uppercase
if (reg.test(num + 13)) {
numres = num - 13
}
// if num+13 is uppercase
else {
numres = num + 13
}
char = String.fromCharCode(numres)
str2 += char
}
console.log(str2);
}
}
rot13("SERRPBQRPNZC");