Answer to Question #295970 in HTML/JavaScript Web Application for chethan

Question #295970

the goal of this code is to quickly get you off the ground with Creating and Consuming Promises.

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

  

 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")

   });

 }



1
Expert's answer
2022-02-11T18:37:25-0500
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))
}

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!

Comments

No comments. Be the first!

Leave a comment

LATEST TUTORIALS
New on Blog
APPROVED BY CLIENTS