Question: 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

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!