JavaScript Algorithms and Data Structures Projects - Caesars Cipher

how can I have the fromCharCode() to consider only digits and exclude any special characters?

Your code so far

function rot13(str) {
  let arr = [...str]
   for (let i = 0; i < arr.length; i++) {
        switch(arr[i]) {
        case ' ':
          break;
        case 'Z':
          arr[i] = 'A'
          break;
        default:
          arr[i] = String.fromCharCode(arr[i].charCodeAt(0) + 2);
          break;
      }
   }
   return arr.join(' ')
     
}

console.log(rot13("SERR PBQR PNZC"));

Your browser information:

User Agent is: Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:105.0) Gecko/20100101 Firefox/105.0

Challenge: JavaScript Algorithms and Data Structures Projects - Caesars Cipher

Link to the challenge:

you need to avoid feeding it special characters. I don’t suggest a switch approach to this, but you can make is eork. Notice for example that you are not feeding spaces to that

1 Like