Using Logical Operators : Can I drive ? A Simple JavaScript Console Program
Program to find whether you are eligible to drive
A simple example of how logical operators works
const hasDriversLicense = true; // A
const hasGoodVision = false; // B
console.log(hasDriversLicense && hasGoodVision); // T && F = F
console.log(hasDriversLicense || hasGoodVision); // T || F = 1
console.log(!hasDriversLicense); // !T = F
if (hasDriversLicense && hasGoodVision) {
console.log('Sarah is able to drive!');
} else {
console.log('Someone else should drive...');
}
Can I drive ? Logical Operators to find out
const age = 18;
const yearsLeft = 18 - age;
if (age >= 18) {
console.log('You can start driving license')
} else {
console.log("You are too young, Wait another", yearsLeft, "years")
}