given two boolean values isgrasstrimmedfound and iswaterhosepipefound as inputs, create three js promises using async/await and try/catch blocks
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