Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

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

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

25.0 m C B A 52.0 m 65.0 m

Answered: 1 week ago