Answered step by step
Verified Expert Solution
Question
1 Approved Answer
Go to the project 0 2 - 0 4 . html file in your code editor and in the head section add a script element
Go to the projecthtml file in your code editor and in the head section add a script element to load
the projectjs file, deferring the loading the external script file until the entire page is loaded. Review the
handson projEcts
contents of the HTML file, noting the ids of different page elements. You will display the calculated values in
span elements with ids of foodTotalfoodTax and totalBill Save your changes to the file.
Go to the projectjs file in your code editor. Below the comment section, declare the following constants
with their initial values: CHICKENPRICE HALIBUTPRICE BURGERPRICE SALMON
PRICE SALADPRICE and SALESTAX
Create the calcTotal function containing the following:
a Declare the cost variable with an initial value of
b Declare the buyChicken variable equal to the checked property of the element with the id chicken In
the same way, declare the buyHalibut, buyBurger, buySalmon, and buySalad variables equal to the
checked property of elements with ids of halibutburgersalmon and salad respectively.
c Use a comparison operator to increase the value of the cost variable by the value of the CHICKENPRICE
constant if buyChicken is true or by if otherwise see Figure as an example of your code Do the
same for the buyHalibut, buyBurger, buySalmon, and buySalad variables, increasing the value of
total cost by the value of HALIBUTPRICE, BURGERPRICE, SALMONPRICE, and SALADPRICE, respectively.
d Set the innerHTML property for the element with the id foodTotal to the value returned by the
formatCurrency function using cost as the parameter value.
e Declare the tax variable, setting its value equal to the cost variable multiplied by SALESTAX.
f Set the innerHTML property for the element with the id foodTax to the value returned by the
formatCurrency function using tax as the parameter value.
g Declare the totalCost variable, setting its value equal to the cost variable plus the tax variable.
h Set the innerHTML property for the element with the id totalBill to the value returned by the
formatCurrency function using totalCost as the parameter value.
Directly above the calcTotal function, insert an event handler that runs the calcTotal function when
the element with id chicken is clicked. Repeat this for the elements with the id halibutburgersalmon
and salad
Save your changes to the file and then open projecthtml in your web browser. Verify that when you click
each of the menu items the calculated cost and tax is automatically updated to reflect your choices.
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