Conditionals in Javascript by Ctrl-Zombies
Conditionals homework in Javascript
Nested Conditionals Javascript Homework
Practice Problems:
Problem 1: Age and Movie Rating
Write a program that asks for a person’s age. If they are under 13, print “You can watch G or PG movies.”
- If they are 13–17, print “You can watch PG-13 movies.”
- If they are 18 or older, print “You can watch R-rated movies.”
let age = parseInt(prompt("Enter age:"));
// TODO: Write nested conditionals here
if (age < __) {
console.log("Text");
} else {
if (age < __) {
console.log("Text");
} else {
console.log("Text");
}
}
Problem 2: Grade Categorizer
Ask the user for a grade percentage (0–100).
- If the grade is 90 or higher, log “A”.
- Else if it is 80–89, log “B”.
- Else if it is 70–79, log “C”.
- Else if it is 60–69, log “D”.
- Otherwise, log “F”
let grade = parseInt(prompt("Enter grade percentage:"));
// TODO: Write your nested conditionals here
if (grade >= __) {
console.log("letter");
} else {
if (grade >= __) {
console.log("letter");
} else {
if (grade >= __) {
console.log("letter");
} else {
if (grade >= __) {
console.log("letter");
} else {
console.log("letter");
}
}
}
}