Question #327094

Creating and consuming promises.

1.For taking shower,

resolve with "Taken Shower" text,if the isHotWaterReady is true.and reject with "Hot Water Not Ready",text if the isHotWaterReady is false.

2.For having breakfast,

resolve with "Had Breakfast",text,if the isBreakfastReady is true and reject with "Breakfast Not ready" text,if the isBreakfastReady is false

3.For getting to work,

resolve with "Got ti Work",text

i/p:the 1st line of i/p contains a boolean isHotWaterReady

the second line of i/p contains a boolean isBreakfastReady

input:

true

true

output;Taken Shower

Had Breakfast

Got to Work

input:true

false

output:

Taken Shower

Breakfast Not Ready

input:false

false

o/p:Hot Water Not Ready

i/p:false

true

o/p:Hot Water Not Ready


Expert's answer

function main() {
   const isHotWaterReady = JSON.parse(readLine());
   const isBreakfastReady = JSON.parse(readLine());
   
   try {
       console.log(getIsHotWaterReady(isHotWaterReady));
       console.log(getIsBreakfastReady(isBreakfastReady)); 
       console.log(getGotToWork());
   } 
   catch (error){
       console.error(error);
   }
}   
 async function getIsHotWaterReady(bool) {
   if(isHotWaterReady){
   return "Taken Shower";
   }
   return "Hot Water Not Ready";
 }



 async function getIsBreakfastReady(bool) {
   if(isBreakfastReady){
   return "Had Breakfast";
   }
   return "Breakfast Not Ready";
 }



 async function getGotToWork(bool,bool) {
         if(isBreakfastReady && isHotWaterReady){
       return "Got to Work";
   }
   return "";
 }

Need a fast expert's response?

Submit order

and get a quick answer at the best price

for any assignment or question with DETAILED EXPLANATIONS!

LATEST TUTORIALS
APPROVED BY CLIENTS