IF Statement Worksheet

Question 1

Why is an IF statement known as a control structure?

An IF statement is known as a control structure because it's 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.

There are a few different types of control statements like Conditional Statements and Iterative Statements. In order to perform control statements we use IF statements, IF-ELSE statements, Switch statements, the Ternary Operator or conditional operator, and using the For loop.

Question 3

What is a boolean expression?

A boolean expression results in 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' represented by "==" is used to compare two values and to check if they are equal, as well as to return a boolean value of true or false depending on the result. While the 'assignment operator' which is ofter shown as "=" is used to assign a value to a variable.

Question 5

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

It is important to indent your code in IF statements, so that the code is easier to read. With proper indentation the hierarchy of the code is easier to distinguish.

Question 6

What is a code block in JavaScript?

A code block is the section of code that is incased in a pair of curly braces '{}'.

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.