Created
September 21, 2019 09:37
-
-
Save hustKiwi/84e208b0abe4b95caf3754fe36d2d64a to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const car = { | |
size: 3, | |
wheel: 4, | |
type: 'LPG' | |
}; | |
if (car.size >= 10) { | |
console.log('This car is large.'); | |
} else if (car.wheel !== 4) { | |
console.log('This car is broken.'); | |
} else { | |
console.log('This car is boring.'); | |
} | |
const FUEL_TYPES = { | |
PETROL: 'petrol', | |
DIESEL: 'diesel', | |
HYBIRD: 'hybird', | |
ELECTRIC: 'electric' | |
}; | |
switch (car.type) { | |
case FUEL_TYPES.PETROL: | |
console.log("It's a petrol car."); | |
break; | |
case FUEL_TYPES.DIESEL: | |
console.log("It's a diesel car."); | |
break; | |
case FUEL_TYPES.HYBIRD: | |
console.log("It's a hybird car."); | |
break; | |
case FUEL_TYPES.ELECTRIC: | |
console.log("It's a electric car."); | |
break; | |
default: | |
console.log('The fuel type of the car is unknown.'); | |
} | |
switch (car.type) { | |
case FUEL_TYPES.PETROL: | |
case FUEL_TYPES.DIESEL: | |
case FUEL_TYPES.HYBIRD: | |
case FUEL_TYPES.ELECTRIC: | |
console.log(`It's a ${car.type} car.`); | |
break; | |
default: | |
console.log('The fuel type of the car is unknown.'); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment