Answer to Question #228714 in Java | JSP | JSF for jai

Question #228714

Gardening

We have a task to do Gardening.

Given two boolean values

isGrassTrimmerFound


and

isWaterHosePipeFound

  1. as inputs, create three JS promises using async/await and try/catch blocks. For cutting the grass,
  • resolve with "Grass Trimmed" text, if the
  • isGrassTrimmerFound
  • is true
  • reject with "Grass Trimmer Not Found" text, if the
  • isGrassTrimmerFound
  • is false
  1. For cleaning the garden,
  • resolve with "Garden Cleaned" text
  1. For watering the plants,
  • resolve with "Watered Plants" text, if the
  • isWaterHosePipeFound
  • is true
  • reject with "Water Hose Pipe Not Found" text, if the
  • isWaterHosePipeFound
  • is false

Input

  • The first line of input contains a boolean
  • isGrassTrimmerFound
  • The second line of input contains a boolean
  • isWaterHosePipeFound

Output

  • The output should be a string with the appropriate messages in separate lines

Sample Input 1

Sample Output 1Sample Input 2Sample Output 2


1
Expert's answer
2021-08-23T07:28:57-0400
<!DOCTYPE html>
<html>
<body>


<h2>Sample Output 1</h2>


<p id="demo1"></p>
<br/>
<p id="demo2"></p>
<br/>
<p id="demo3"></p>


<script>
function display1(some) {
  document.getElementById("demo1").innerHTML = some;
}
function display2(some) {
  document.getElementById("demo2").innerHTML = some;
}
function display3(some) {
  document.getElementById("demo3").innerHTML = some;
}


//Assuming that isGrassTrimmerFound and isWaterHosePipeFound are true


let isGrassTrimmerFound = true;
let isWaterHosePipeFound = true;
//Promise 1
async function promise1() {if(isGrassTrimmerFound == true){return "Grass Trimmed";}
else{
return "Grass Trimmer Not Found";
}


}


promise1().then(
  function(value) {display1(value);},
  function(error) {display1(error);}
);
//Promise 2
async function promise2() {if(isWaterHosePipeFound == true){return "Garden Cleaned";}
else{
return "Garden is not cleaned";
}


}


promise2().then(
  function(value) {display2(value);},
  function(error) {display2(error);}
);


//Promise 3
async function promise3() {if(isWaterHosePipeFound == true){return  "Watered Plants";}
else{
return "Water Hose Pipe Not Found";
}


}


promise3().then(
  function(value) {display3(value);},
  function(error) {display3(error);}
);




</script>


</body>
</html>

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