c0deM0nK424
Programmer
If I earn at least $500 this week, I can pay the electric bill; I must pay the bill, or else my lights will be
shut off."
You can generate the exact same sentiment in JavaScript using only two variables: income and lights. Presume
that the variable income has been previously assigned some numeric value representing this week's earnings.
The variable lights will be assigned on the condition of the income and will receive a Boolean value (true or false)
because there are only two possible outcomes for the lights: remain on or shut off. Given all this, the JavaScript
version of the above statement, using the JavaScript If...else construction, would look like this:
if (income >=500) {
lights = true;
else
{ lights = false;
}
Given this statement, JavaScript would first evaluate the expression (income >= 500). If this returns a true result,
JavaScript executes the statements within the first set of brackets {}. If the expression is false, JavaScript skips
ahead to the else clause and executes the statements within the set of brackets immediately below the else
keyword. You can include as many statements as you want within the brackets of a clause, but you must
remember to end each statement with a semicolon ( as in this example:
if (income >=500) {
lights = true;
savings=income-bills;
To JavaScript, the semicolon is the signal that one statement has finished and another is about to begin.
shut off."
You can generate the exact same sentiment in JavaScript using only two variables: income and lights. Presume
that the variable income has been previously assigned some numeric value representing this week's earnings.
The variable lights will be assigned on the condition of the income and will receive a Boolean value (true or false)
because there are only two possible outcomes for the lights: remain on or shut off. Given all this, the JavaScript
version of the above statement, using the JavaScript If...else construction, would look like this:
if (income >=500) {
lights = true;
else
{ lights = false;
}
Given this statement, JavaScript would first evaluate the expression (income >= 500). If this returns a true result,
JavaScript executes the statements within the first set of brackets {}. If the expression is false, JavaScript skips
ahead to the else clause and executes the statements within the set of brackets immediately below the else
keyword. You can include as many statements as you want within the brackets of a clause, but you must
remember to end each statement with a semicolon ( as in this example:
if (income >=500) {
lights = true;
savings=income-bills;
To JavaScript, the semicolon is the signal that one statement has finished and another is about to begin.