IF Statement Worksheet
Question 1
Why is an IF statement known as a control structure?
The IF statement is a control structure becuase its can help us controlling which code is executed.
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.
Besides the 'If Statement' & 'IF-else Statement' there are 'Switch Statement','Ternary Operator', 'Iterative Statements', 'While loop', and 'Do-While loop' for control structures for JavaScript.
Question 3
What is a boolean expression?
Its a equation that can result 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' is used to see if a variable matches a specific value. From here, the code may do different actions depending on if it was true or false. It differs from the assigment operator because the assigment operator is used to initialize variables; while the 'equality operator' is used to see if two variables are the same.
Question 5
Why is it important to properly indent your code when writing IF statements?
It helps to make it easier to read the block of the code, especially if there is an error or a change that needs to be made.
Question 6
What is a code block in JavaScript?
A block of code or code block referes to code that are between curly braces {}. Starting from the top the program will read the code and if the first code block is false, it will move to the next till either it finds a block of code where the result is true; or til it runs out of code or a code that either resets the code or stops the action.
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.