Skip to content

Instantly share code, notes, and snippets.

@alejandrolechuga
Created February 19, 2019 00:29
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save alejandrolechuga/3c4793b64cf3c6bd661836a55bc32fe7 to your computer and use it in GitHub Desktop.
Save alejandrolechuga/3c4793b64cf3c6bd661836a55bc32fe7 to your computer and use it in GitHub Desktop.
function random(){
return Math.floor(Math.random() * 10);
}
function getJSON() {
return new Promise(function (resolve, reject) {
setTimeout(() => resolve('Yes'),random());
setTimeout(() => reject('No'), random());
});
}
var promise = getJSON()
.then((data) => {
console.log(data);
}).catch((data) => {
console.log(data);
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment