daily pastebin goal
53%
SHARE
TWEET

Untitled

mia10 Dec 12th, 2018 72 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. "use strict";
  2.  
  3. /*
  4.    New Perspectives on HTML5 and CSS3, 7th Edition
  5.    Tutorial 10
  6.    Case Problem 1
  7.  
  8.    Author: Minerva Igama
  9.    Date:   Dec. 1 2018
  10.    
  11.    Filename: tc_cart.js
  12.    
  13. */
  14.  
  15. // Variables
  16. var orderTotal = 0; //var with 0 value
  17. var cartHTML = "<table>";
  18. cartHTML += "<tr><th>Item</th><th>Description</th><th>Price</th><th>Qty</th><th>Total</th></tr>"; //puts header to table
  19.  
  20. //For loop
  21. for (var i = 0; i < item.length; i++) {// looping through loop for 0 till length
  22.   cartHTML += "<tr>";
  23.   cartHTML += "<td>" + "<img src='tc_" + item[i] + ".png' alt='" + item[i] + "'> </td>";
  24.   cartHTML += "<td>" + itemDescription[i] + "</td>";
  25.   cartHTML += "<td>$" + itemPrice[i] + "</td>";
  26.   cartHTML += "<td>" + itemQty[i] + "</td>";
  27.  
  28. var itemCost = itemPrice[i] * itemQty[i]; //item cost for each item
  29.  
  30. cartHTML += "<td>$" + itemCost + "</td>";
  31. cartHTML += "</tr>"
  32.  
  33. orderTotal += itemCost; //add to total
  34. }
  35.  
  36. // For loop Completion
  37. cartHTML += "<tr><td colspan='4'>Subtotal</td>";
  38. cartHTML += "<td>$" + orderTotal + "</td></tr>";
  39. cartHTML += "</table>"; //the order total
  40.  
  41. document.getElementById("cart").innerHTML = cartHTML; //place table in the HTML using the div id
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top