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

if(document.readyState === 'loading'){
document.addEventListener('DOMContentLoaded',calculateCost )
} else{
calculateCost();
}
function calculateCost (){
const salesTaxRate =0.13;
const salesTax = subTotal * salesTaxRate;
const total = subTotal + salesTax;
const subTotalOutput = document.getElementById('subTotal');
const taxAmountOutput = document.getElementById('taxAmount');
const totalOutput = document.getElementById('total');
const prices = document.querySelectorAll('.price');
subTotal.textContent = new Intl.NumberFormat('en-US',{ style: 'currency', currency: 'USD' }).format(subtotal);
taxAmountOutput.textContent = new Intl.NumberFormat('en-US',{ style: 'currency', currency: 'USD' }).format(salesTax);
totalOutput.textContent = new Intl.NumberFormat('en-US',{ style: 'currency', currency: 'USD' }).format(total);
};
Can you fix my code. The error i am getting is saying "subTotal is not defined at calculateCost."

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!