Answered step by step
Verified Expert Solution
Question
1 Approved Answer
if ( document . readyState = = = 'loading' ) { document.addEventListener ( ' DOMContentLoaded ' , calculateCost ) } else { calculateCost ( )
ifdocumentreadyState 'loading'
document.addEventListenerDOMContentLoadedcalculateCost
else
calculateCost;
function calculateCost
const backpackPrice NumberdocumentgetElementByIdbackprice'textContent;
const calculatorPrice NumberdocumentgetElementByIdcalcprice'textContent;
const textbookPrice NumberdocumentgetElementByIdtextprice'textContent;
const taxRate ;
const subTotal calculateSubtotalbackpackPrice calculatorPrice, textbookPrice;
const salesTax calculateSalesTaxsubTotal;
const totalCost calculateTotalsubTotal salesTax;
console.logSubtotal: $ subTotal.toFixed;
console.logSales Tax: $ salesTax.toFixed;
console.logTotal Cost: $ totalCost.toFixed;
function calculateSubtotalbackpack calculator, textbook
return backpack calculator textbook;
function calculateSalesTaxsubTotal
const salesTax
return subTotal salesTax;
function calculateTotalsubTotal salesTax
return subTotal salesTax;
Use document.querySelectorAll to read the 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
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started