Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

if ( document . readyState = = = 'loading' ) { document.addEventListener ( ' DOMContentLoaded ' , showItems ) ; } else { showItems (

if(document.readyState === 'loading'){
document.addEventListener('DOMContentLoaded', showItems);
} else{
showItems();
}
function showItems(){
const backPrice = document.getElementsByClassName("price");
const calcPrice = document.getElementsByClassName("price");
const textPrice = document.getElementsByClassName("price");
const backpackPrice = backPrice.textContent;
const calculatorPrice = calcPrice.textContent;
const textbookPrice = textPrice.textContent;
const prices =[Number("backPackPrice"),Number(calculatorPrice),Number(textPrice)];
return prices;
}
function pricesAdd(prices){
let sum =0;
for (let i =0; i < prices.length; i++){
sum += Number(prices[i]);
}
return sum;
}
function calcSum(){
const prices = showItems;
const subTotal = pricesAdd(prices);
return subTotal;
}
function taxRate(){
const taxRate =0.13;
return taxRate;
}
function calcTax(sum){
let taxAmount =0;
const rate = taxRate();
taxAmount = sum * rate;
return taxAmount;
}
function calcFinalCost(sum, tax){
const finalCostAmount = sum + tax;
document.getElementById("sub-total").textContent = sum.toFixed(2);
document.getElementById("tax-amount").textContent = tax.toFixed(2);
document.getElementById("total").textContent = finalCostAmount.toFixed(2);
}
(function(){
const sum = calcSum();
const tax = calcTax(sum);
calcFinalCost(sum, tax);
})();
Can you fix code with proper way of using getElementbyClassName
Also correct what needs to be corrected to not bring up errors

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Students also viewed these Databases questions

Question

Distinguish between poor and good positive and neutral messages.

Answered: 1 week ago

Question

Describe the four specific guidelines for using the direct plan.

Answered: 1 week ago