Answered step by step
Verified Expert Solution
Link Copied!

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 project02-04.html file in your code editor and in the head section add a script element to load
the project02-04.js file, deferring the loading the external script file until the entire page is loaded. Review the
hands-on projEcts 75
contents of the HTML file, noting the ids of different page elements. You will display the calculated values in
span elements with ids of foodTotal,foodTax, and totalBill. Save your changes to the file.
3. Go to the project02-04.js file in your code editor. Below the comment section, declare the following constants
with their initial values: CHICKEN_PRICE 510.95, HALIBUT_PRICE 513.95, BURGER_PRICE 59.95, SALMON_
PRICE 518.95, SALAD_PRICE 57.95, and SALES_TAX 50.07.
4. Create the calcTotal() function containing the following:
a. Declare the cost variable with an initial value of 0.
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 halibut,burger,salmon, and salad, respectively.
c. Use a comparison operator to increase the value of the cost variable by the value of the CHICKEN_PRICE
constant if buyChicken is true or by 0 if otherwise (see Figure 2-21 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 HALIBUT_PRICE, BURGER_PRICE, SALMON_PRICE, and SALAD_PRICE, 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 SALES_TAX.
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.
5. 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 halibut,burger,salmon,
and salad.
6. Save your changes to the file and then open project02-04.html 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

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_2

Step: 3

blur-text-image_3

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Database And Expert Systems Applications 23rd International Conference Dexa 2012 Vienna Austria September 2012 Proceedings Part 1 Lncs 7446

Authors: Stephen W. Liddle ,Klaus-Dieter Schewe ,A Min Tjoa ,Xiaofang Zhou

2012th Edition

3642325998, 978-3642325991

More Books

Students also viewed these Databases questions

Question

5. Recognize your ability to repair and let go of painful conflict

Answered: 1 week ago