Today you will learn:
if and elseBy the end, you will be able to control the flow of your program based on conditions.
Conditions allow your program to make decisions.
Example questions:
if checks if a condition is true.
let age = 20;
if (age >= 18) {
console.log("Adult");
}
else runs if the condition is false.
let age = 20;
if (age >= 18) {
console.log("Adult");
} else {
console.log("Minor");
}
Explanation:
else block runs
let age = 20;
if (age >= 18) {
console.log("Adult");
} else {
console.log("Minor");
}
Create a program that checks a score:
Example:
let score = 60;
if (score > 50) {
console.log("Pass");
} else {
console.log("Fail");
}