IF Statement Worksheet
Question 1
Why is an IF statement known as a control structure?
It is called that because it controles the flow of the program.
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 strutures include Loops, and Jump Statements.
Question 3
What is a boolean expression?
A boolean expression is a true or false statement.
Question 4
What is the 'equality operator', and what is it used for? How is it different from the assignment operator?
The equality operator is two equal signs next to each other with no spaces. It is used to compare if the two values equal one another. It is different from the assignment operator because it uses two equal signs.
Question 5
Why is it important to properly indent your code when writing IF statements?
It's important to indent your code because it makes it more clear and easier to read. It can also help with debugging. I'd say the main point is to show which code belongs to correct block.
Question 6
What is a code block in JavaScript?
It's a group of statements enclosed in curly braces.
Question 7
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");
}
It's missing a else statement. If a user were to type anything besides y or n the code just cuts of saying nothing.
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.