-3

hi i'm new to java script and I wrote a text adventure for a school project and I keep getting these error when I try to run it

js: "adventure.js", line 4: missing ( before condition
js: if var start = "turn on lights" || "light switch" 
js: ......^
js: "adventure.js", line 7: missing ( before condition
js: if var start = "open window" || "window"
js: ......^
js: "adventure.js", line 10: missing ( before condition
js: if var start = "wait"
js: ......^
js: "adventure.js", line 13: missing ( before condition
js: if var start = "opendoor"
js: ......^
js: "adventure.js", line 18: missing ( before condition
js: if secoundAct = "open left door" || "open door left" || "left door" || "   enter left door"
js: .............^
js: "adventure.js", line 21: missing ( before condition
js: if secoundAct = "open right" || "enter right" || "enter right door"|| "open right door"
js: .............^
js: "adventure.js", line 24: missing ( before condition
js: if secoundAct = "go back" || "turn around"
js: .............^
js: "adventure.js", line 29: missing ( before condition
js: if thirdAct = "go back" || "turn back"
js: ...........^
js: "adventure.js", line 32: missing ( before condition
js: if thirdAct = "go down right stairs" || "go right" || "right" || "down right" || "down left" || "go left" || "go down left stairs" || "jump over balcony" || "hop over balcony" 
js: ...........^
js: "adventure.js", line 37: missing ( before condition
js: if fourthAct = "monster lodging" || "go into monster lodging" || "go into giant death monnster lodging" 
js: ............^
js: "adventure.js", line 40: missing ( before condition
js: if fourthAct = "go into escape pods" || "escape pods" 
js: ............^
js: "adventure.js", line 1: Compilation produced 11 syntax errors.

does anyone know what im doing wrong bellow the code if it helps https://drive.google.com/file/d/0Bz_LEt8rxihuNGdUUUluelRhQ1E/edit?usp=sharing

1
  • 1
    Have you looked at, read, and considered what each error message means? The if else language refrence may help.
    – user289086
    Commented Jun 17, 2014 at 19:29

1 Answer 1

0

In this statement

if var start = "turn on lights" || "light switch"
  1. You're declaring the variable by using var. You don't need this.
  2. If you're trying to do an equality check, use ===. As written the expression is trying to assign "turn on lights" OR (the double pipe ||) to a var start. This doesn't make sense - the expression will always evaluate true.

See https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Operators/Logical_Operators to see why. "turn on the lights" is not null or an empty string, so is true. The same applies to "light switch". In the example above

"turn on lights" || "light switch"

will always be true.

  1. The error messages tell you a lot of what you need. They are saying that they expected to see a ( . Enclose your condition in parentheses.

So the net of all this, your statements should read something like

if(start === "turn on lights" || start === "light switch"){
  // do something
}

Note that you need to say start === on either side of the OR, you can't shortcut this.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.