Description
New Perspectives HTML5 and CSS3 7th Edition Tutorial 10 Case 1 Trophy Case Sports
Trophy Case Sports Sarah Nordheim manages the website for Trophy Case Sports, a sports memorabilia store located in Beavercreek, Ohio. She has asked you to work on creating a script for a shopping cart page. The script should take information on the items that the customer has purchased and present in it table form, calculating the total cost of the order. A preview of the page you will create is shown in Figure 10-35.
Sarah has already designed the page layout. Your job will be to use JavaScript to enter the order information (this task will later be handled by a script running on website) and to write a script that generates the HTML code for the shopping cart table.
Complete the following:
1. Use your editor to open the tc_cart_txt.html, tc_cart_txt.js and tc_order_txt.js files from the htm10 case 1 folder. Enter your name and the date in the comment section of each file, and save them as tc_cart.html, tc_cart.js and tc_order.js respectively.
2. Go to the tc_cart.html file in your editor. Directly above the closing tag, insert script elements to link the page to the tc_order.js and tc_cart.js files in that order. Defer the loading and running of both script files until after the page has loaded.
3. Scroll down the file and directly below the h1 heading titled “Shopping Cart” insert a div element with the ID cart.
4. Save your changes to the file and go to the tc_ordet.js file in your editor.
5. Within the tc_order.js file, you will create arrays containing information on a sample customer order. Create an array named item that will contain the ID numbers of the items purchased by the customer. Add the following four item numbers to the array: 10582, 23015, 41807, and 10041.
6. Create an array named itemDescription containing the following item descriptions:
• 1975 Green Bay Packers Football (signed), Item 10582
• Tom Land, 1955 Football Card (unsigned), Item 23015
• 1916 Army-Navy Game, Framed Photo (signed), Item 41807
• Protective Card Sheets, Rem 10041
7. Create an array named itemPrice containing the following item prices: 149.93, 89.98, 334.93, and 22.67.
8. Create an array named itemQty containing the following quantities that the customer ordered of each item: 1, 1, 1, and 4.
9. Save your changes to the file, and then open the tc_cart.js file in your editor.
10. In your script, you will calculate a running total of the cost of the order. Declare a variable named orderTotal and set its initial value to 0.
11. Declare a variable named cartHTML that will contain the HTML code for the contents of the shopping cart, which will be displayed as a table. Set its initial value to the text string:
Item | Description | Price | Qty | Total |
---|---|---|---|---|
description | price | quantity | $cost | |
Subtotal | Total |
where total is the value of the orderTotal variable, preceded by a $ symbol.
14. Apply the cartHTML value to the inner HTML of the div element with the ID cart.
15. Document your script file with appropriate comments, and then save your work.
16. Open the tc_cart.html file in your browser and verify that the page now shows the shopping cart data for the sample customer order.
Reviews
There are no reviews yet.