IF Statement Worksheet

Question 1

Why is an IF statement known as a control structure?

A IF statement is known as a control structure because it allows you to control the flow of your program by executing certain blocks of 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 control structures in JavaScript include:

Question 3

What is a boolean expression?

A boolean expression is an expression that evaluates to either true or false. It is often used in control structures like IF statements.

Question 4

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

The equality operator (== or ===) is used to compare two values to see if they are equal. The assignment operator (=) is used to assign a value to a variable. The key difference is that (== or ===) operator checks for equality, while (=) operator assigns a value.

Question 5

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

Proper indentation is important when writing IF statements because it makes the code more readable and easier to understand and use. It visually separates different blocks of code, helping to identify which is which.

Question 6

What is a code block in JavaScript?

A code block in JavaScript is a group of statements that are enclosed in curly braces { }. Code blocks are used to define the scope of variables and control structures like in IF statements.

Question 7 (Do not do this)

What is a code block in JavaScript?


		let input = prompt("Are you a vegetarian (y/n)?");

		if(input == "y"){
			console.log("I recommend the pasta salad.");
		}else if(input == "n"){
			console.log("I recommend the prime rib");
		}
		
Replace this text with answer/solution to the above problem

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.