IF Statement Worksheet
Question 1
Why is an IF statement known as a control structure?
An IF statement controls the flow of a program by deciding what code to run based on whether a condition is true or false. If the condition is true, it runs one set of instructions; if false, it might run another. This way, it guides the program's actions.
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: if...else-Executes a block of code if a specified condition is true, otherwise executes another block of code. switch-Executes one of many code blocks based on the value of an expression. Loops: for-Repeats a block of code a specific number of times. while-Repeats a block of code as long as a specified condition is true. do...while-imilar to while, but it runs the block of code at least once before checking the condition. Iterative Statements: for...in-Iterates over the properties of an object. for...of-Iterates over the values of an iterable object (like arrays or strings).
Question 3
What is a boolean expression?
A boolean expression is a statement that can only be true or false. It helps in making decisions in a program.
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 for equality. The assignment operator (=) assigns a value to a variable.
Question 5
Why is it important to properly indent your code when writing IF statements?
Proper indentation in IF statements makes your code easier to read and understand. It shows which parts of the code belong to the IF block, helping prevent mistakes.
Question 6
What is a code block in JavaScript?
make it into a sentence and simpler A code block in JavaScript is a set of statements inside curly braces {} that execute together.
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.