IF Statement Worksheet
Question 1
Why is an IF statement known as a control structure?
It is a way of controlling which code runs when you execute your program.
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.
Conditional statements like "switch". Looping statements like "for" or "while". Jumping statements like "break" and "continue".
Question 3
What is a boolean expression?
A boolean expression is an expression that results in either being 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 "==" and it is used to determine whether 2 values/variables are equal. The assiging operator assigns variables and constants in the code and uses one equal sign "=".
Question 5
Why is it important to properly indent your code when writing IF statements?
"If" statements can be long and have multiple blocks of code so it is important to have organized code that visually shows with indents what blocks of code are siblings and children of each other.
Question 6
What is a code block in JavaScript?
It is the code within the curly brackets {} and there can be many statements within one block. If there are multiple blocks within an If statement the code will stop executing once a block of code is true to the if statement and any blocks below it will not execute.
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.