Fall 2024 - P4
Big Idea 3 | .1 | .2 | .3 | .4 | .5 | .6 | .7 | .8 | .10 |
CSP Period 4 Unit 3.7.4 Nested Conditionals Javascript Hacks
In this lesson on nested conditionals in Javascript, students will explore how to create decision-making structures that involve multiple layers of conditions. By learning how to nest if, elif, and else statements, they will be able to write more precise and complex programs where one condition is checked only after another condition is met. The lesson will include hands-on exercises to help students understand when and how to apply nested conditionals for better control flow and logical clarity in their code.
Javascript Nested Conditionals Hacks Below
Check the following conditions:
You must have your study materials (books, notes, etc.).
You must have a quiet place to study.
You must not be feeling too tired.
If all conditions are met, print that you are ready to study.
If you don’t have a quiet place, suggest finding a quiet location.
If you are too tired, suggest taking a nap or resting first.
If you don’t have your study materials, print that you need to gather them first.
Check the following conditions:
You must have all the ingredients (flour, eggs, sugar).
Your oven must be working.
You must have at least 2 hours to bake and cool the cake.
If all conditions are true, print that you can start baking.
If you don't have enough time, print that you need to find more time.
If the oven is not working, print that you need to fix or replace the oven.
If you don't have all the ingredients, print what you are missing.
Use the following conditions:
The weather must be clear.
You must have a tent.
You must have enough food and water for the trip.
If all conditions are met, print that you are ready to go camping.
If you don’t have a tent, print that you need to buy or borrow a tent.
If you don’t have enough food and water, print that you need to pack more.
If the weather is not clear, print that it’s not a good time for camping.
Javascript Quiz
Question 1:
What will be the output of the following code?
let score = 85;
let hasExtraCredit = false;
if (score >= 90) {
console.log("Grade: A");
} else {
if (score >= 80) {
if (hasExtraCredit) {
console.log("Grade: A");
} else {
console.log("Grade: B");
}
} else {
console.log("Grade: C or below");
}
}
A. Grade: A B. Grade: B C. Grade: C or below
Question 2:
Given the following code, what will be printed if age = 30 and isMember = true?
let age = 30;
let isMember = true;
if (age < 18) {
console.log("Child discount applies.");
} else {
if (isMember) {
console.log("Member discount applies.");
} else {
console.log("No discount available.");
}
}
A. Child discount applies. B. Member discount applies. C. No discount available.
Question 3:
What will be the output of the following code?
let day = "Saturday";
let weather = "sunny";
if (day === "Saturday") {
if (weather === "sunny") {
console.log("Let's go to the park!");
} else {
console.log("Let's stay indoors.");
}
} else {
console.log("It's a weekday, time to work.");
}
A. Let’s go to the park! B. Let’s stay indoors. C. It’s a weekday, time to work.