Guest User

Untitled

a guest
Oct 20th, 2018
83
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.50 KB | None | 0 0
  1. /**
  2. * Viết hàm countDown đếm ngược từ x về 0, mỗi lần đếm cách nhau 1s, trả về promise, promise này resolve sau khi đã đếm xong
  3. */
  4. function countDown(x) {
  5. return new Promise(function(response,reject){
  6. var coder = setInterval(function(){
  7.  
  8. --x;
  9. console.log(x);
  10. if(x === 0){
  11. clearInterval(coder);
  12. response();
  13. }
  14. },1000);
  15. })
  16. }
  17.  
  18. function sayHappyNewYear() {
  19. console.log('Happy new year');
  20. }
  21.  
  22. countDown(5).then(sayHappyNewYear);
Add Comment
Please, Sign In to add comment