Created
April 29, 2020 17:14
-
-
Save sandrabosk/b305f3a1d776c55fd9718310c0a8065b 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
function eligibleToDrink (age) { | |
return new Promise((resolve, reject) => { | |
if(age >= 18) { | |
resolve(`Being ${age} years old, you are eligible to drink.`); | |
} else { | |
reject(`${age} years is underage. Here is a fresh squeezed orange juice for you!`); | |
} | |
}) | |
} | |
eligibleToDrink(15) | |
.then(result => console.log(result)) | |
.catch(error => console.log(error)) | |
// => 15 years is underage. Here is a fresh squeezed orange juice for you! | |
eligibleToDrink(18) | |
.then(result => console.log(result)) | |
.catch(error => console.log(error)) | |
// => Being 18 years old, you are eligible to drink. |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment