Skip to content

Instantly share code, notes, and snippets.

@sandrabosk
Created April 29, 2020 17:14
Show Gist options
  • Save sandrabosk/b305f3a1d776c55fd9718310c0a8065b to your computer and use it in GitHub Desktop.
Save sandrabosk/b305f3a1d776c55fd9718310c0a8065b to your computer and use it in GitHub Desktop.
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