Topics: The async Keyword, Writing async Functions, Handling Dependent Promises, Handling Errors, Handling Independent Promises, Await Promise.all()
Project Title: Smart House
- Create a html file with your name like john.html
- Add current code to that file:
<!DOCTYPE html> <html> <body> <script> // your code here </script> </body> </html>
When user press energySaving button of smart house remote control, we call these 3 functions sequentially:
Create async function energySaving() and then call above 3 functions sequentially.
function smartTurnOffLight is async and check a current time, if it is between 7am to 6pm it return
TurnOffLight Donestring after 3 seconds else throw exception
Failed to TurnOffLightafter 2 seconds.
function smartTurnOffAirConditioner is async and check a current date, if it is summer it return
TurnOffAirConditioner Donestring after 1 seconds else throw exception
Failed to TurnOffAirConditionerafter 3 seconds.
function smartTurnOffWashingMachine is async and check a current time, if it is between 2pm to 5pm it return
TurnOffWashingMachine Donestring after 1.5 seconds else throw exception
Failed to TurnOffWashingMachineafter 0.5 seconds.
In energySaving function if all functions run successfully console.log("Energy Saving is Off") else show errors.
create energySavingConcurrent function and run all 3 functions concurrently. Log the result all functions into console.
Want to get reviewed?
Send Pull Request. Check how to deliver your code: https://codingwithbasir.com/how-to-deliver-projects/