71 lines
1.5 KiB
JavaScript
71 lines
1.5 KiB
JavaScript
//PROMISE Object
|
|
|
|
//Do the chores in order: walk the dog, clean up the kitchen and tak out the trash
|
|
|
|
// function walkdog(callback) {
|
|
// setTimeout(() => {
|
|
// console.log("WALKING THE DOG");
|
|
// callback();
|
|
// }, 3000);
|
|
// }
|
|
// function cleanKitchen(callback) {
|
|
// setTimeout(() => {
|
|
// console.log("CLEANING THE KITCHEN");
|
|
// callback();
|
|
// }, 13000);
|
|
// }
|
|
// function takeTrash(callback) {
|
|
// setTimeout(() => {
|
|
// console.log("TAKING THE TRASH");
|
|
// callback();
|
|
// }, 1000);
|
|
// }
|
|
|
|
// walkdog(() => {
|
|
// cleanKitchen(() => {
|
|
// takeTrash(() => {
|
|
// console.log("DONE");
|
|
// });
|
|
// })
|
|
// })
|
|
|
|
function walkdog() {
|
|
setTimeout(() => {
|
|
console.log("WALKING THE DOG");
|
|
}, 3000);
|
|
|
|
return new Promise((resolve, reject) => {
|
|
resolve("WALKING THE DOG");
|
|
});
|
|
}
|
|
function cleanKitchen() {
|
|
setTimeout(() => {
|
|
console.log("CLEANING THE KITCHEN");
|
|
}, 13000);
|
|
|
|
return new Promise((resolve, reject) => {
|
|
resolve("Cleaning the kitchen");
|
|
});
|
|
}
|
|
function takeTrash() {
|
|
setTimeout(() => {
|
|
console.log("TAKING THE TRASH");
|
|
}, 1000);
|
|
|
|
return new Promise((resolve, reject) => {
|
|
resolve("TAKING THE TRASH");
|
|
})
|
|
}
|
|
|
|
walkdog()
|
|
.then((result) => {
|
|
console.log(result);
|
|
return cleanKitchen();
|
|
})
|
|
.then((result) => {
|
|
console.log(result);
|
|
return takeTrash();
|
|
})
|
|
.then((result) => {
|
|
console.log(result);
|
|
}) |