0

I am trying to create an object in javascript that has an object inside of it and I am getting the following error:

Uncaught SyntaxError: Unexpected token ILLEGAL

This is my code

var motivateEN = {
    0 : {0: "{name}, keep studying this lesson for a better score.", 1: "Bad luck {name}, keep studying this lesson to improve.
"},
    50:{0: "Practice makes perfect {name}, try this lesson again.",1:"Not bad, but better luck next time {name}!",2:"Well done {name}, you’re on the right track!"},
    85:{0:"Congratulations {name}, lesson complete!",1:"Woohoo, lesson complete {name}!",2:"Awesome stuff {name}! Keep it up!",3:"Great skills! Well done {name}!
"},
    100:{0: "Perfect {name}! Keep up the good work!",1:"Congratulations {name}, you got a perfect score!"} 
};
Jake
  • 3,326
  • 7
  • 39
  • 59
  • The issue is in the strings literals, which aren't allowed to span multiple lines. You can use the `\n` and `\r` [escape sequences](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String) to include line breaks. http://stackoverflow.com/questions/5391628/javascript-multiline-string – Jonathan Lonowski Mar 21 '15 at 02:35

1 Answers1

2

If you take this code and format it, the error is more obvious:

var motivateEN = {
    0: {
        0: "{name}, keep studying this lesson for a better score.",
        1: "Bad luck {name}, keep studying this lesson to improve.
        "},
...

You can't use a newline in the middle of a string

Daniel Kaplan
  • 62,768
  • 50
  • 234
  • 356
  • Thanks I tried to do javascript:alert(motivateEN.0.0); but returns an error? – Jake Mar 21 '15 at 02:37
  • @Jake To access numeric properties, you'll [have to use bracket notation](http://stackoverflow.com/questions/2026741/how-to-access-a-numeric-property) -- `motivateEN[0][0]`. Numbers aren't on their own valid identifiers, which is what dot notation expects. – Jonathan Lonowski Mar 21 '15 at 02:40