IF Statement Worksheet

Question 1

Why is an IF statement known as a control structure?

An IF statement is called a control structure because it controls what happens in the block of code based on the condition. Based on this condition, it decides which block of code to run depending on if the condition is true or false.

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.

Switch; For; While; Do... While; Break; Continue

Question 3

What is a boolean expression?

A boolean expression is an expression that indicate if the condition is true or false. Boolean expressions are often used in conjunction with control structures to control the flow of code based on the condition of the statement.

Question 4

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

The equality operator compares two values and verifies to check if they are equal. Compared to the assignment operator that just assigns a value to a variable. This is how these two operators differ from one another.

Question 5

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

Although it does not affect the way the code is executed or operates, it helps with visually examining the code and troubleshoot more effectively because you can see how each line of code is related to each other and vice versa. Additionally, it helps to create a clear line of structure, avoid errors when writing code and creates a standard of clarity where other developers can easily identify and pick up on your work for collaboration.

Question 6

What is a code block in JavaScript?

A code block is a set of statements wrapped in curly brackets. This helps to group multiple lines of code so that it is treated as one unit. This helps to organize, control the flow, and limit variables so that they don't interfere with other parts of your code.

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.