Given two boolean values
isGrassTrimmerFound and isWaterHosePipeFound as inputs, create three JS promises using async/await and try/catch blocks.
Input
The first line of input contains a boolean isGrassTrimmerFound
The second line of input contains a boolean isWaterHosePipeFound
Sample Input 1
true
true
Sample Output 1
Grass Trimmed
Garden Cleaned
Watered Plants
Sample Input 2
true
false
Sample Output 2
Grass Trimmed
Garden Cleaned
Water Hose Pipe Not Found
"use strict";
/* Please do not modify anything above this line */
function main() {
const isGrassTrimmerFound = JSON.parse(readLine());
const isWaterHosePipeFound = JSON.parse(readLine());
/* Write code */
const myPromise = async () => {
try {
/* Write code */
} catch(error) {
/* Write code */
}
};
myPromise();
}
function main() {
const isGrassTrimmedFound = JSON.parse(readLine());
const isWaterHosePipeFound = JSON.parse(readLine());
const myPromise1 = async() => {
try {
if (!isGrassTrimmedFound) throw new Exception();
else {
return await Promise.resolve("Grass Trimmed");
}
} catch(e) {
return await Promise.reject("Grass Trimmer Not Found")
}
}
const myPromise2 = async() => {
return await Promise.resolve("Garden Cleaned");
}
const myPromise3 = async() => {
try {
if (!isWaterHosePipeFound) throw new Exception();
else {
return await Promise.resolve("Watered Plants");
}
} catch(e) {
return await Promise.reject("Water Hose Pipe Not Found")
}
}
}
Comments
Leave a comment