Question: if ( document . readyState = = = 'loading' ) { document.addEventListener ( ' DOMContentLoaded ' , calculateCost ) } else { calculateCost ( )

if(document.readyState === 'loading'){
document.addEventListener('DOMContentLoaded',calculateCost )
} else{
calculateCost();
}
function calculateCost (){
const backpackPrice = Number(document.getElementById('back-price').textContent);
const calculatorPrice = Number(document.getElementById('calc-price').textContent);
const textbookPrice = Number(document.getElementById('text-price').textContent);
const taxRate =0.13;
const subTotal = calculateSubtotal(backpackPrice, calculatorPrice, textbookPrice);
const salesTax = calculateSalesTax(subTotal);
const totalCost = calculateTotal(subTotal, salesTax);
console.log('Subtotal: $'+ subTotal.toFixed(2));
console.log('Sales Tax: $'+ salesTax.toFixed(2));
console.log('Total Cost: $'+ totalCost.toFixed(2));
}
function calculateSubtotal(backpack, calculator, textbook){
return backpack + calculator + textbook;
}
function calculateSalesTax(subTotal){
const salesTax =0.13
return subTotal * salesTax;
}
function calculateTotal(subTotal, salesTax){
return subTotal + salesTax;
}
Use document.querySelectorAll to read the 3 elements that have a class attribute of "price" from the DOM. You will use ".price" as the CSS selector to use with the querySelectorAll method to read the prices.
How do I interpret document.querySelectorAll into my code

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!