Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Write a JavaScript program that calculates the sales tax and total price of an i

ID: 3720971 • Letter: W

Question

Write a JavaScript program that calculates the sales tax and total price of an item. Assume a sales tax rate of 8%, which means you will multiply the cost of the item by .08 in order tocalculate the tax amount. 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.

1. you must use prompt

2. You must declare variables

3. You must use document.write or Alert output

4. You must use parseFloat

6. You must NOT use console.log, Input, Type, Events or functions - These are advanced topics. This was not part of the lecture.

Explanation / Answer

<!DOCTYPE html>
<html>
<body>

<script>
var itemPrice = parseFloat(prompt("Enter the price: "));
var salesTaxRate = 0.08;
var salesTax = itemPrice*salesTaxRate;
var totalCost = itemPrice+salesTax;
document.write("Item Cost: "+itemPrice+"<br>");
document.write("Sales Tax: "+salesTax+"<br>");
document.write("Total Cost: "+totalCost+"<br>");
</script>

</body>
</html>

Output:

Item Cost: 1000
Sales Tax: 80
Total Cost: 1080

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote