π Training β Conditions
📚 50 questions⏱ 15-20 min🏆 Instant feedback
π Conditional Statements (Conditional Statements) JavaScript
using if, else, switch Ali
π― What You Will Learn in This Training
This interactive training will help you master Conditional Statements JavaScript No :
- β Ali type input string No
- β statement if execution code Check condition
- β if...else execution code
- β using if...else if...else
- β operator (Nested if)
- β switch constant
- β writing using operator No (Ternary Operator)
- β comparison Nested if operator &&
β Conditional Statements (Conditional Statements)?
Conditional Statements code condition (true) (false).
code No No only β¨
let age = 20;
if (age >= 18) {
console.log("You are allowed to enter β ");
}
if (age >= 18) {
console.log("You are allowed to enter β ");
}
π 1οΈβ£ statement if
code execution only Check condition .
let temperature = 30;
if (temperature >25) {
console.log(" π₯΅");
}
if (temperature >25) {
console.log(" π₯΅");
}
π 2οΈβ£ statement if...else
code Check condition, Check.
let age = 15;
if (age >= 18) {
console.log("You are an adult π");
} else {
console.log("You are still a minor πΈ");
}
if (age >= 18) {
console.log("You are an adult π");
} else {
console.log("You are still a minor πΈ");
}
π 3οΈβ£ statement if...else if...else
.
let score = 85;
if (score >= 90) {
console.log("Excellent π₯");
} else if (score >= 75) {
console.log("Good π");
} else {
console.log("Keep trying πͺ");
}
if (score >= 90) {
console.log("Excellent π₯");
} else if (score >= 75) {
console.log("Good π");
} else {
console.log("Keep trying πͺ");
}
π§© 4οΈβ£ (Nested if)
statement if if Check .
let age = 16;
let country = "USA";
let text = "You can Not drive!";
if (country == "USA") {
if (age >= 16) {
text = "You can drive!";
}
}
console.log(text);
let country = "USA";
let text = "You can Not drive!";
if (country == "USA") {
if (age >= 16) {
text = "You can drive!";
}
}
console.log(text);
βοΈ 5οΈβ£ Nested if vs Logical AND (&&)
Nested if operator && code.
// Nested if
if (age >= 18) {
if (hasLicense) {
message = "You can drive.";
}
}
// using && ( )
if (age >= 18 && hasLicense) {
message = "You can drive.";
}
if (age >= 18) {
if (hasLicense) {
message = "You can drive.";
}
}
// using && ( )
if (age >= 18 && hasLicense) {
message = "You can drive.";
}
ποΈ 6οΈβ£ statement switch
constant Check , No using if...else.
let day = "Monday";
switch (day) {
case"Monday":
console.log("Start of the week πΌ");
break;
case"Friday":
console.log("Weekend is near π");
break;
default:
console.log("Just another day π");
}
switch (day) {
case"Monday":
console.log("Start of the week πΌ");
break;
case"Friday":
console.log("Weekend is near π");
break;
default:
console.log("Just another day π");
}
β 7οΈβ£ operator No (Ternary Operator)
writing condition if...else.
let age = 20;
let message = (age >= 18) ? "Adult π" : "Minor πΈ";
console.log(message);
let message = (age >= 18) ? "Adult π" : "Minor πΈ";
console.log(message);