Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /**
- * 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
- */
- function countDown(x) {
- return new Promise(function(response,reject){
- var coder = setInterval(function(){
- --x;
- console.log(x);
- if(x === 0){
- clearInterval(coder);
- response();
- }
- },1000);
- })
- }
- function sayHappyNewYear() {
- console.log('Happy new year');
- }
- countDown(5).then(sayHappyNewYear);
Add Comment
Please, Sign In to add comment