0

I am trying to make a grid for a game. I have an object maps that contains the level designs. This is it:

var maps = {
  cave: [" ________________ ",
         "/                \",
         "|                 ", 
         "|                 ", 
         "|_________________"]
}

This is on github pages, by the way. Whenever I go to the console on the site, I see that it threw an error:

"Invalid or unexpected token"

On the second array value (the third line as I have it there). Why is it doing this? Can someone help please?

EDIT: sorry, didn't know this was a duplicate. I didn't know what the problem was, so I didn't know what to search for first before asking.

1 Answers1

2

You need to escape the slash on the 2nd line. If you don't escape the slash, it escapes the ", and this breaks the closing of the string:

var maps = {
  cave: [" ________________ ",
         "/                \\",
         "|                 ", 
         "|                 ", 
         "|_________________"]
}

console.log(maps)
Ori Drori
  • 183,571
  • 29
  • 224
  • 209