xxxxxxxxxx
if (person.age >= 16) { person.driver = 'Yes';} else { person.driver = 'No';}
xxxxxxxxxx
If - Else Statements
if (condition) {
// what to do if condition is met
} else {
// what to do if condition is not met
}
xxxxxxxxxx
if (5 < 10) {
console.log("5 is less than 10");
} else {
console.log("5 is now bigger than 10")
}
xxxxxxxxxx
var x = 1;
if(x==1)
{
console.log("x equals to 1")
}
else
{
console.log("x is not equal to 1");
}
xxxxxxxxxx
const count = 20;
if (count === 0) {
console.log('There are no students');
} else if (count === 1) {
console.log('There is only one student');
} else {
console.log(`There are ${count} students`);
}
xxxxxxxxxx
if (condition) {
// what to do if condition is met
} else {
// what to do if condition is not met
}
if (condition) {
// what to do if condition is met
} else if (condition) {
// what to do if condition is not met
}
xxxxxxxxxx
const randomObject = 5;
if(randomObject < 2) {
console.log("The Random Object has a value more than 2");
}
else {
console.log("The Random Object has a value less than 2");
}
xxxxxxxxxx
const number = (Math.random() - 2.5) * 5;
if (number < 0) {
console.log('Number is negative');
}
if (number = 0) {
console.log('Number is zero');
}
if (number > 0) {
console.log('Number is positive');
}
xxxxxxxxxx
if (a > 0) {
result = 'positive';
} else {
result = 'NOT positive';
}