Topics: The async Keyword, Writing async Functions, Handling Dependent Promises, Handling Errors, Handling Independent Promises, Await Promise.all()
- 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:
- smartTurnOffLight()
- smartTurnOffAirConditioner()
- smartTurnOffWashingMachine()
-
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 Done
string after 3 seconds else throw exceptionFailed to TurnOffLight
after 2 seconds. -
function smartTurnOffAirConditioner is async and check a current date, if it is summer it return
TurnOffAirConditioner Done
string after 1 seconds else throw exceptionFailed to TurnOffAirConditioner
after 3 seconds. -
function smartTurnOffWashingMachine is async and check a current time, if it is between 2pm to 5pm it return
TurnOffWashingMachine Done
string after 1.5 seconds else throw exceptionFailed to TurnOffWashingMachine
after 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.
Send Pull Request. Check how to deliver your code: https://codingwithbasir.com/how-to-deliver-projects/
Download Learn JavaScript eBook from https://codingwithbasir.com/learn-javascript