Lesson 4 Exercises
4_1. Sales Tax Calculator:
Use prompt and parseFloat to ask the user to input the item’s cost and convert it to a numeric format. Declare a variable salesTax and use the formula above to calculate the sales tax amount. Declare a variable totalCost, add the item’s cost plus the sales tax amount, and store it in totalCost. Output the Item cost, tax amount, and total cost on separate lines in the form of a receipt.
Don’t assume a tax rate of 8%. Instead, ask the user to input the tax rate in the form
of a decimal, i.e. .05, .03, etc., and use this tax rate for the calculations.
Display the tax amount in a different color.
Depending on the price of an item, you may end up with a tax amount that takes up
more than 2 decimal places. Use the following code to round the tax amount to two decimal places:
var taxAmtRnd = Math.round(taxAmount*100); taxAmtRnd = taxAmtRnd/100;
This code multiplies the tax amount by 100, rounds it off, then divides by 100. This drops any extra decimal places from the tax amount. The rounded tax amount is in the variable taxAmtRnd.