the goal of this code is to quickly get you off the ground with Creating and Consuming Promises.
input
output
based on inputs
sampleinput1
true
true
sampleoutput1
Taken Shower
Had Breakfast
Got to Work
function main() {
const isHotWaterReady = JSON.parse(readLine());
const isBreakfastReady = JSON.parse(readLine());
/* Please do not modify anything above this line */
// Write your code here
const takingShower = () => {
return new Promise((resolve,reject) => {
isHotWaterReady ? resolve("Taken Shower") : reject ("Hot Water Not Ready")
});
}
const breakFast = () => {
return new Promise((resolve,reject) => {
isBreakfastReady ? resolve("Had Breakfast") : reject ("Breakfast Not Ready")
});
}
function main() {
const isHotWaterReady = JSON.parse(readLine());
const isBreakfastReady = JSON.parse(readLine());
/* Please do not modify anything above this line */
// Write your code here
const takingShower = () => {
return new Promise((resolve,reject) => {
isHotWaterReady ? resolve("Taken Shower") : reject ("Hot Water Not Ready")
});
}
const breakFast = () => {
return new Promise((resolve,reject) => {
isBreakfastReady ? resolve("Had Breakfast") : reject ("Breakfast Not Ready")
});
}
takingShower()
.then(result => {
console.log(result);
return breakFast();
})
.then(result => {
console.log(result)
return "Got to work"
})
.then(result => console.log(result))
.catch(error => console.log(error))
}
Comments
Leave a comment