Caesars Cipher - Where am I wrong?

Tell us what’s happening:
Where am I wrong in my code ? I thought I got it right ?

Is it due to the fact I only coded the matching for each character, instead of creating a processing algorithm ?

  **Your code so far**
const rotted = {"N" : "A", "O" : "B", "P" : "C", "Q" : "D", "R" : "E", "S" : "F","T" : "G", "U" : "H", "V" : "I", "W" : "J", "X" : "K", "Y" : "L", "Z" : "M", "A" : "N", "B" : "O","C" : "P","D" : "Q","E" : "R","F" : "S","G" : "T","H" : "U","I" : "V","J" : "W","K" : "X","L" : "Y","M" : "Z", " " : " ", "." : ".", "!" : "!", "?" : "?"}
const newStr = []
function rot13(str) {
for (var i = 0; i < str.length; i++) {
if (rotted.hasOwnProperty(str[i])) {
  newStr.push(rotted[str[i]])
}
} 
const reunited = newStr.join('')
return reunited
}

rot13("SERR PBQR PNZC");
  **Your browser information:**

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

Challenge: Caesars Cipher

Link to the challenge:

Your code contains global variables that are changed each time the function is run. This means that after each function call completes, subsequent function calls start with the previous value. To fix this, make sure your function doesn’t change any global variables, and declare/assign variables within the function if they need to be changed.

Example:

var myGlobal = [1];
function returnGlobal(arg) {
  myGlobal.push(arg);
  return myGlobal;
} // unreliable - array gets longer each time the function is run

function returnLocal(arg) {
  var myLocal = [1];
  myLocal.push(arg);
  return myLocal;
} // reliable - always returns an array of length 2

Thank you, I passed after making these changes :slight_smile: