Question: Write a JavaScript program that solves the following problem: Youie buys 3 items at the campus bookstore. A backpack, a calculator, and a textbook. The

Write a JavaScript program that solves the following problem:

Youie buys 3 items at the campus bookstore. A backpack, a calculator, and a textbook.

The backpack costs $56.99. The calculator costs $104.89. The textbook costs $51.97.

The bookstore charges 13% sales tax.

What is the subtotal amount for the 3 items?

What is the sales tax amount for the 3 items?

What is the total cost for the 3 items after the sales tax is added to the subtotal?

 

This is html code:

  • Demonstrate skills/techniques learned from earlier assignments.
  • Demonstrate the use of document.getElementById to read and change elements from the DOM.
  • Demonstrate the use of textContents to read and change the text contents of an element in the DOM.

Purchased Items

Item Name Item Price Quantity
Backpack156.99
Calculator1104.89
Textbook151.97
Subtotal
Tax
Total Cost

Instructions

you will read several HTML elements from the provided HTML file using getElementById method.

Then you will read the text content from the HTML elements using "textContent", convert the text into numbers using the Number() property.

Like in the previous assignments, you will do some calculations.

Finally, you will output several values to the console.

This program needs to be written as functions. There must be no variables declared or used in the global scope.

The program must meet these criteria:

  1. Must follow the standards followed in previous programs: include meaningful comments, is formatted in an easy to read manner, uses strict mode to enforce good coding practices. Variables are initialized at the beginning. Uses "const" and "let" correctly. It does not use "var" to initialize variables. Variables are kept out of global scope by compartmentalizing them inside functions.
  2. Use document.getElementById to read the prices of the 3 elements from the DOM: back-price, calc-price, and text-price.
  3. Use the textContent property of the elements to read the text contents from the 3 DOM elements.
  4. Convert the text content from the 3 DOM elements into numbers using the Number() method.
  5. Calculate the sum of the item prices.
  6. Calculate the amount of sales tax.
  7. Calculate the total price.
  8. Output the following information to the console using template literals: Sum of the item prices Sales tax amount Total price

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!