PromisThefuckAgain

This commit is contained in:
2024-10-24 15:21:04 +02:00
parent 9e8df7c127
commit b907fa988b
3 changed files with 71 additions and 2 deletions

View File

@ -0,0 +1,15 @@
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>PROMISE</title>
</head>
<style>
</style>
<body>
<script src="script.js"></script>
</body>
</html>

View File

@ -0,0 +1,71 @@
//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);
})