Caesars Cipher (Cannot create property '0' on string '' )

Tell us what’s happening:

Your code so far

function rot13(str) { // LBH QVQ VG!
  let newStr = "";
    for(let i = 0; i < str.length; i++){
      let j = database.indexOf(str[i]);
      if (j === -1){
        newStr[i] = str[i]; }
        if(j > 12){
          newStr[i] = database[j-13];
        newStr[i] = database[j+13];
  return newStr;

// Change the inputs below to test
rot13("SERR PBQR PNZC");

Your browser information:

User Agent is: Mozilla/5.0 (Macintosh; Intel Mac OS X 10_11_6) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/66.0.3359.181 Safari/537.36.

Link to the challenge:

You can post solutions that invite discussion (like asking how the solution works, or asking about certain parts of the solution). But please don’t just post your solution for the sake of sharing it.

We have set your post to unlisted. Thanks for your understanding.

But this solution cannot run. It is a wrong solution.

Please update your post to ask questions and describe what problems you are having.