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 directs the flow of a program by executing code based on specific conditions.

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.

Other JavaScript control structures include: switch for multi-way branching, for, while, and do...while loops, break and continue for flow control, and try...catch for error handling.

Question 3

What is a boolean expression?

A boolean expression is a statement that evaluates to true or false, using comparison or logical operators. It involves operators like ==, !=, <, >, <=, and >=.

Question 4

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

The equality operator (`==`) checks if two values are equal, returning true or false. The assignment operator (=) assigns a value to a variable.

Question 5

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

Indentation improves readability, organizes structure, aids debugging, encourages collaboration, and aligns with coding best practices.

Question 6

What is a code block in JavaScript?

A code block in JavaScript is a group of statements enclosed in curly braces {}. It defines a scope for variables and controls the flow of execution, commonly used in functions, loops, and conditionals.

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.