0

function sillyCipher(sentence, cipher) {
  let str = "";
  let keys = Object.keys(cipher);
  for (let key in cipher) {
    for (let i = 0; i < sentence.length; i++) {
      if (sentence[i] == key) {
        str = sentence.replace(new RegExp(key, "g"), cipher[key])
      }
    }
  }
  return str
}

console.log(sillyCipher("apple" , { a : "c", p : "x", l : "r", e : "o"}));

//i got SyntaxError: Invalid regular expression: /?/: Nothing to repeat could you help can't understand this error in the loop

Nick Parsons
  • 45,728
  • 6
  • 46
  • 64

0 Answers0