Question: if ( document . readyState = = = 'loading' ) { document.addEventListener ( ' DOMContentLoaded ' , calculateCost ) } else { calculateCost ( )
ifdocumentreadyState 'loading'
document.addEventListenerDOMContentLoadedcalculateCost
else
calculateCost;
function calculateCost
const salesTaxRate ;
const salesTax subTotal salesTaxRate;
const total subTotal salesTax;
const subTotalOutput document.getElementByIdsubTotal;
const taxAmountOutput document.getElementByIdtaxAmount;
const totalOutput document.getElementByIdtotal;
const prices document.querySelectorAllprice';
subTotal.textContent new Intl.NumberFormatenUS style: 'currency', currency: 'USD' formatsubtotal;
taxAmountOutput.textContent new Intl.NumberFormatenUS style: 'currency', currency: 'USD' formatsalesTax;
totalOutput.textContent new Intl.NumberFormatenUS style: 'currency', currency: 'USD' formattotal;
;
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
Question Has Been Solved by an Expert!
Get step-by-step solutions from verified subject matter experts
Step: 2 Unlock
Step: 3 Unlock
