IF Statement Worksheet

Question 1

Why is an IF statement known as a control structure?

An IF statement is a way of controlling which code executes when your program runs.

Question 2

There are other control structures in JavaScript that we'll be learning about soon. Use your google skills to look up the other control structures in JavaScript and list them below.

Question 3

What is a boolean expression?

A boolean expression is an equation that can be evaluated to produce a result of either true or false.

Question 4

What is the 'equality operator', and what is it used for? How is it different from the assignment operator?

The equality operator is two equals signs, also know as '=='.

The single equals sign (=) is used to initialize variables, whereas the two equals signs (==) check and compare to see if variables are storing the same value.

Question 5

Why is it important to properly indent your code when writing IF statements?

Indenting your code properly enhances the readability of the code; it helps tell you what line of code is inside of an IF statement.

Question 6

What is a code block in JavaScript?

A code block (or branch) is the pair of curly braces, {}, and the code inside of them.

In an IF/ELSE statement, when the boolean expression result is true, then the program will execute the first block/branch. When the result is false, the program will execute the second block/branch, and so on.

Coding Problems

Coding Problems - See the 'script' tag below this h3 tag. You will have to write some JavaScript code in it.

Always test your work! Check the console log to make sure there are no errors.