if statement - javascript, unexpected token { -



if statement - javascript, unexpected token { -

okay, have basic syntax error i'm having issues resolving. apparently missed basic , of import on code academy class can't seem resolve. i'll post code below. should obvious i'm trying within.

the error = "syntax error: unexpected token {"

the goal, write own code incorporating loops, if/else, , functions.

var info = ["love", "peace", "anger", "war"] (i = 0; < data.length; i++){ if (i <=2){ console.log("life is" + " " +data[i]); } else if (i <=4){ console.log("strife is" + " " + data[i]); } else (i = 5){ console.log("that's now"); } }

the problem, pointed out, else not take status makes sense else body run when other corresponding if/else-if conditionals failed.

thus javascript (not requiring braces around if/else-bodies) parsing so:

else statement

more starts parsing expressionstatement, (i = 5), followed invalid {. invalid same reason next invalid:

i = 5 { }

statements must separated semicolons - explicitly or via automatic semicolon insertion. former not done , latter not apply in given code.

javascript if-statement for-loop syntax

Comments

Popular posts from this blog

Delphi change the assembly code of a running process -

json - Hibernate and Jackson (java.lang.IllegalStateException: Cannot call sendError() after the response has been committed) -

C++ 11 "class" keyword -