If/else


#1

I am on the step where I have to fix an if/else statement. Can someone please show me a picture of the format of an if/else statement/(not the answer, of course.)


#2

@taskmaster365,

From one of the most respected propagators of Javascript - Douglas Crockford
= http://javascript.crockford.com/code.html
[quote how to write code using a convention ]

Compound Statements

Compound statements
are statements that contain lists of statements
encapsulated in a pair of curly-brackets-{ } (also called curly braces).

  • The enclosed statements should be indented four more spaces.
  • The { (left curly brace) should be at the end of the line that begins the compound statement.
  • The } (right curly brace) should begin a line and be indented to align with the beginning of the line containing the matching { (left curly brace).
  • Braces should be used around all statements, even single statements, when they are part of a control structure, such as an if or for statement. This makes it easier to add statements without accidentally introducing bugs.

if Statement

The if class of statements should have the following form:


if (condition) {
    compound statements
    are executed when =condition= equals a _Boolean_ **true**
 }

 if (condition) {
    compound statements
    are executed when =condition= equals a _Boolean_ **true**
 } else {
    compound statements
    are executed when =condition= equals a _Boolean_ **false**
 }

 if (condition1) {
    compound statements
    are executed when =condition1= equals a _Boolean_ **true**
 } else if (condition2) {
    compound statements
    are executed when =condition2= equals a _Boolean_ **true**
 } else {
    compound statements
    are executed when
    both  =condition1= AND =condition2=
    equals a _Boolean_ **false**
 }

[ end-quote how to write code using a convention ]

Condition

An expression that evaluates to true or false.
= https://developer.mozilla.org/en-US/docs/Web/JavaScript/Guide/Expressions_and_Operators#Expressions

A google search
== the Book ==
javascript if statement site:developer.mozilla.org
https://developer.mozilla.org/nl/docs/Web/JavaScript/Reference/Statements/if...else


3. ...And the Good
3. And the good!