the goal of this code is to quickly get you off the ground with Creating and Consuming Promises.
CREATE 3 JS PROMISES USING ASYNC/AWAIT, TRY/CATCH BLOCKS.
input
the first line of input is containing a boolean isHotWaterReady
the second line of input is containing a boolean isBreakfastReady
output
the output could be multiple strings with the appropriate response in seperate lines
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
function main() {
const isHotWaterReady = JSON.parse(readLine());
const isBreakfastReady = JSON.parse(readLine());
/* Please do not modify anything above this line */
try {
let str = await getIsHotWaterReady(isHotWaterReady)
console.log(str);
str = await getIsBreakfastReady(isBreakfastReady)
console.log(str);
str = await getGotToWork()
console.log(str);
}
catch (error){
console.error(error);
}
}
async function getIsHotWaterReady(bool) {
if(isHotWaterReady){
return "Taken Shower";
}
return "Didn't take a shower";
}
async function getIsBreakfastReady(bool) {
if(isBreakfastReady){
return "Had Breakfast";
}
return "Didn't have breakfast";
}
async function getGotToWork() {
return "Got to Wor";
}
Comments
Leave a comment