Answer to Question #323364 in HTML/JavaScript Web Application for CHINNI

Question #323364

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


1
Expert's answer
2022-04-08T16:06:20-0400
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";
  }

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