Advertisement
Guest User

Untitled

a guest
Feb 21st, 2019
63
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.35 KB | None | 0 0
  1. function random(){
  2. return Math.floor(Math.random() * 10);
  3. }
  4.  
  5. function getJSON() {
  6. return new Promise(function (resolve, reject) {
  7. setTimeout(() => resolve('Yes'),random());
  8. setTimeout(() => reject('No'), random());
  9. });
  10. }
  11.  
  12. var promise = getJSON()
  13. .then((data) => {
  14. console.log(data);
  15. }).catch((data) => {
  16. console.log(data);
  17. });
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement