4. Computer Choice Part 2.. question?


#1


So when put in the code the way it asks it gives me a sytax error due to a curly bracket

But when I take out some apparently unnessesary curly brackets... Wow it works!!!

I just want to know why?



#2

@fhili,
If you use the IF ELSE statement construct

if (condition)
 exactly-1-statement allowed
else
 exactly-1-statement allowed

If you want to execute more than 1 statement
you will have to encapsulate these statement's in a pair of curly-brackets-{ }
therewith creating a so-called code-block

Thus you would get

if ( condition ) {
  //IF code-block
}
else {
  //ELSE code-block
}

Reference
== the Book ==
https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Statements/if...else
and
== code-convention ==
http://javascript.crockford.com/code.html


#3

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.