IF Statement Worksheet

Question 1

Why is an IF statement known as a control structure?

IF statement is known as a control structure because it controls the way your code executes.

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.

1. Conditional Statements These are used to execute different blocks of code based on conditions. if statement if...else statement if...else if...else statement Ternary operator (condition ? trueValue : falseValue) switch statement

2. Looping Structures (Iteration) These are used to repeat blocks of code multiple times. for loop while loop do...while loop for...in loop (iterates over object properties) for...of loop (iterates over iterable objects like arrays)

3. Exception Handling Used to manage errors in code execution. try...catch finally throw

4. Control Flow Keywords These control the execution flow directly. break (exits a loop or switch statement early) continue (skips the current loop iteration and moves to the next) return (exits a function and returns a value)

Question 3

What is a boolean expression?

A boolean expression is something that results in true or false that is all

Question 4

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

The equality operator makes it so when we want to see if input IS equal to the value that we set. Like comparing the two

Question 5

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

It is always important to properly indent your code but even more so when writing IF statements because, they hold alot of code within the body of the statements.

Question 6

What is a code block in JavaScript?

Curly Braces are considered the Code Blocks or aka Code Branches

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.