Tell us what’s happening:
Everything else is being decoded, but I cant seem to get the punctation to carry over. Not sure if my regex is setup right or even valid.
Please help. Much appreciated!!
BD
Your code so far
function rot13(str) {
///establish alphabet or rule
let alpha = "ABCDEFGHIJKLMNOPQRSTUVWXYZ"
let alphArr = alpha.split('')
//split given string into array
let strArr = str.split("")
console.log("original string: " + strArr)
console.log(typeof strArr[4])
let newArr = []
// for each letter in the given string. find its position /index on the alphabet or rule thenr educe that position by 13.
for (let i = 0; i <= strArr.length; i++){
if (strArr[i] === ' ')
{newArr.push(" ")}
else if (strArr[i] === /A-Za-z0-9_/g) {newArr.push(strArr[i])}
else if (typeof strArr[i] === 'string' && alphArr.indexOf(strArr[i]) >= 13) {newArr.push(alphArr[alphArr.indexOf(strArr[i]) - 13])}
else if (typeof strArr[i] === 'string' && alphArr.indexOf (strArr[i]) < 13){newArr.push(alphArr[alphArr.indexOf(strArr[i]) + 13])}
}
console.log(newArr.join(""))
return newArr.join("");
}
rot13("SERR PBQR PNZC");
Your browser information:
User Agent is: Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_6) AppleWebKit/605.1.15 (KHTML, like Gecko) Version/14.0.2 Safari/605.1.15
.
Challenge: Caesars Cipher
Link to the challenge: