IF Statement Worksheet

Question 1

Why is an IF statement known as a control structure?

It allows your code to choose a specific path, ex: True or False.

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.

Four Loop - executes a block of code. While Loop - executes a block repeatedly, as long as condition is true. Do while loop - code block is executed at least once before checking the condition. Switch Statement- Used to execute different code blocks based on the value of an expression.

Question 3

What is a boolean expression?

An expression that evaluates either true or false. Used with "if" statements.

Question 4

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

it is used to compare two values and determine if they are equal. The boolean value comes back either: True or False (As Undefined). The equality operator assigns a True/False statement result, and The Assignment Operator assigns the value (ex:x=5) to the variable (x)

Question 5

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

More visual clarity, with indenting: Parent, Children, and Sibling elements. Also easier to fix errors.

Question 6

What is a code block in JavaScript?

A function that is enclosed within curly braces {}, that groups multiple statements and executes them.

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.