To facilitate learning and practice with JavaScript Promises, we'll convert the return types of the taxCalculator and InsuranceCalculator functions from synchronous to asynchronous using Promises.
Tasks:
Convert return type of taxCalculator & InsuranceCalculator to Promise:
Modify the taxCalculator function in taxCalculator.js to return a Promise.
Similarly, update the InsuranceCalculator function in insuranceCalculator.js to return a Promise instead of a synchronous result.
Any Validation error may need to use Promise reject.
Update Unit Tests:
Adjust the unit tests in the respective test files (taxCalculator.test.js and insuranceCalculator.test.js) to accommodate the asynchronous nature of the updated functions.
Ensure that the tests appropriately handle Promise resolution and rejection scenarios.
Story of Promise
Once upon a time, there was a hardworking citizen named Alex who needed to calculate their personal income tax (PIT) and arrange insurance coverage. However, these tasks required interacting with external government services, which could take a few days to process.
Alex decided to use JavaScript to automate these processes. They created functions to handle PIT and insurance calculations, but instead of getting immediate results, these functions promised to deliver the information when the government services responded.
With Promises in place, Alex's application could start the calculations and continue with other tasks while waiting for the government services to respond. This saved Alex time and effort, as they didn't have to wait around for the calculations to finish.
In the end, Alex's application was able to efficiently handle PIT and insurance calculations, thanks to the power of Promises, making Alex's life a lot easier!
Objective:
To facilitate learning and practice with JavaScript Promises, we'll convert the return types of the taxCalculator and InsuranceCalculator functions from synchronous to asynchronous using Promises.
Tasks:
Convert return type of taxCalculator & InsuranceCalculator to Promise:
taxCalculator.js
to return a Promise.insuranceCalculator.js
to return a Promise instead of a synchronous result.Update Unit Tests:
taxCalculator.test.js
andinsuranceCalculator.test.js
) to accommodate the asynchronous nature of the updated functions.Story of Promise
Once upon a time, there was a hardworking citizen named Alex who needed to calculate their personal income tax (PIT) and arrange insurance coverage. However, these tasks required interacting with external government services, which could take a few days to process.
Alex decided to use JavaScript to automate these processes. They created functions to handle PIT and insurance calculations, but instead of getting immediate results, these functions promised to deliver the information when the government services responded.
With Promises in place, Alex's application could start the calculations and continue with other tasks while waiting for the government services to respond. This saved Alex time and effort, as they didn't have to wait around for the calculations to finish.
In the end, Alex's application was able to efficiently handle PIT and insurance calculations, thanks to the power of Promises, making Alex's life a lot easier!