Last active
July 5, 2022 07:17
-
-
Save samuraijane/4529180fb3f885d9246f0c7b4f2cc769 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 shoppingList = ['apples', 'biscuits', 'cabbage', 'dip']; | |
const isCode200 = () => Math.random() >= 0.5; | |
function getShoppingList() { | |
return new Promise((resolve, reject) => { | |
setTimeout(() => { | |
if (isCode200()) { | |
resolve(shoppingList); | |
} else { | |
reject('There was a problem with the server, please try again.'); | |
} | |
}, 500); | |
}); | |
} | |
getShoppingList() | |
.then(data => console.log(data)) | |
.catch(err => console.error(`ERR: ${err}`)); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment