if (condition) {
// statement 1
} else {
// statement 2
}
- Executes statement 1 if the condition is true, otherwise statement 2.
if (condition1) {
// statement 1
} else if (condition2) {
// statement 2
} else {
// statement 3
}
- JavaScript uses
&&
for "and",||
for "or". &&
requires both conditions to be true.||
requires at least one condition to be true.
if (email === "[email protected]" && password === "123") {
alert("Log in!");
} else {
alert("Incorrect!");
}
if (waterTemp < 32 || waterTemp > 212) {
alert("Don't drink it!");
} else {
alert("Water is safe!");
}
if ((num >= 8 && num >= 6) || num < 10) {
alert("True");
} else {
alert("False");
}
Happy coding! 😊