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
  • Alternatively use backtics: var maps = { cave: [ ` ________________ / \ | | |_________________` ] } Commented Mar 2, 2019 at 18:27

1 Answer 1

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)

Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.