Regex issue in ceasers cipher

Tell us what’s happening:
Describe your issue in detail here.
well I have pretty much solved it but I’m having issue in whitespaces and special characters. I wanted to apply regex only to capital letter but its removing specials characters and whitespaces

   **Your code so far**

function rot13(str) {
 function alpha(x){
   return String(x).match(/^[A-Z]/g)
 }
let string = '';
for(let i = 0; i <= str.length; i++){
 let o = str.charCodeAt(i)
if(alpha(str[i])){
string += String.fromCharCode((o % 26) + 65);
}
}
return string
}
console.log(rot13("SERR CVMMN!"));
   **Your browser information:**

User Agent is: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/99.0.4844.74 Safari/537.36

Challenge: Caesars Cipher

Link to the challenge:

How about adding an “else”-branch?

2 Likes
function rot13(str) {
  function alpha(x){
    return String(x).match(/^[A-Z]/g)
  }
let string = []
for(let i = 0; i <= str.length; i++){
  let o = str.charCodeAt(i)
if(alpha(str[i])){
 string += String.fromCharCode((o % 26) + 65);
}else{
  string += str[i];
}
}
return string
}

ok so pretty much it but… it is saying undefined after result like

FREE PIZZA!undefined
1 Like

Hmmm…

2 Likes

@Jagaya @JeremyLT THANK YOUU

This topic was automatically closed 182 days after the last reply. New replies are no longer allowed.