-
-
Save Akkuma/1355455 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<!DOCTYPE html> | |
<html> | |
<head> | |
<title>JavaScript Assignment 3: Jonathan Waxman</title> | |
</head> | |
<body> | |
<table border="1" width="100%" height="550"> | |
<tr> | |
<th colspan="2" bgcolor="navy" style="color:white"> | |
<h1>JW's Electronic Post - eCommerce</h1> | |
</th> | |
</tr> | |
<tr> | |
<td bgcolor="navy" width='5%'> | |
<a href="home.html"><font color="white">Home</font></a> | |
<a href="pressrelease.html"><font color="white">Press Release</font></a> | |
<a href="products.html"><font color="white">Products</font></a> | |
</td> | |
<td> | |
<table border="1" width="100%" height="500"> | |
<tr> | |
<td height="75" cellpadding="30" align="center" style="color:navy"> | |
<h3>Products</h3> | |
</td> | |
<td height="75" cellpadding="30" align="center" style="color:navy"> | |
<h3>Prices</h3> | |
</td> | |
<td height="75" cellpadding="30" align="center" style="color:navy"> | |
<h3>Discounts</h3> | |
</td> | |
</tr> | |
</td> | |
</tr> | |
<tr align="center" style="color:navy"> | |
<td> | |
<a href="http://www.sennheiserusa.com/around-ear-headphones-acoustic_504631" target="_blank"><font color="navy">Sennheiser HD 558</font></a> | |
</td> | |
<td> | |
Price: $147.87 | |
</td> | |
<td> | |
.10 | |
</td> | |
</tr> | |
<tr align="center" style="color:navy"> | |
<td> | |
<a href="http://www.sennheiserusa.com/over-ear-headphones-acoustic-headphones_504633" target="_blank"><font color="navy">Sennheiser HD 598</font></a> | |
</td> | |
<td> | |
Price: $249.95 | |
</td> | |
<td> | |
.10 | |
</td> | |
</tr> | |
<tr align="center" style="color:navy"> | |
<td> | |
<a href="http://www.sennheiserusa.com/over-ear-headphones-highest-quality-headphones_004465" target="_blank"><font color="navy">Sennheiser HD 600</font></a> | |
</td> | |
<td> | |
Price: $314.95 | |
</td> | |
<td> | |
.10 | |
</td> | |
</tr> | |
<tr align="center" style="color:navy"> | |
<td> | |
<a href="http://www.sennheiserusa.com/high-quality-headphones-around-ear_009969" target="_blank"><font color="navy">Sennheiser HD 650</font></a> | |
</td> | |
<td> | |
Price: $359.17 | |
</td> | |
<td> | |
.10 | |
</td> | |
</tr> | |
</table> | |
<tr> | |
<td colspan="2" bgcolor="navy" style="color:white"> | |
<b> | |
<p align="center"> | |
<a href="mailto:jwaxman@eden.rutgers.edu"><font color="white"> Email Us! </font></a> | |
732-555-3456 | |
53 Bumble Avenue | |
East Bumble, NJ 99813 | |
</p> | |
</b> | |
</td> | |
</tr> | |
</table> | |
<div id="sales-order"></div> | |
<script type="text/javascript"> | |
/* Jonathan Waxman | |
TA: Bandhan | |
JavaScript 3 | |
Due: November 4th */ | |
var customerName | |
, products = { | |
'sennheiser hd 558': { | |
cost: 147.87 | |
, quantity: 0 | |
} | |
, 'sennheiser hd 598': { | |
cost: 249.95 | |
, quantity: 0 | |
} | |
, 'sennheiser hd 600': { | |
cost: 314.95 | |
, quantity: 0 | |
} | |
, 'sennheiser hd 650': { | |
cost: 359.17 | |
, quantity: 0 | |
} | |
}; | |
function welcome() { | |
customerName = prompt("Welcome to JW's Electronic Post. Please enter your name",""); | |
customerName = customerName || 'customer'; | |
alert("Hello " + customerName + ". Please look through our available products and services before placing your order."); | |
} | |
function orderProduct() { | |
var product = prompt("What product are you ordering?",""); | |
var quantity = prompt("How many " +product + "'s would you like to order?",""); | |
quantity = !isNaN(quantity) ? 1*quantity : 1; | |
if(confirm (customerName + " you ordered "+ quantity + " " + product + ". Is this correct?")) { | |
if (products[product]) { | |
products[product].quantity += quantity; | |
} | |
else { | |
alert("Sorry, " + customerName + ". You entered an invalid product. We will not include this in your order."); | |
} | |
} | |
if(confirm(customerName + ", would you like to order another product?")) { | |
orderProduct(); | |
} | |
else { | |
calculateOrder() | |
} | |
} | |
function calculateOrder() { | |
var discount=0.10; | |
var runningTotal = 0; | |
var purchaseMessage = '<p>Thank you for placing an order with us, <b>' + customerName + '</b></p>'; | |
for(var product in products) { | |
if (products.hasOwnProperty(product) && products[product].quantity) { | |
var productInfo = products[product] | |
, totalProductCost = productInfo.cost * productInfo.quantity | |
, savings = totalProductCost * discount | |
, actualProductCost = totalProductCost * (1-discount); | |
runningTotal += actualProductCost; | |
purchaseMessage += '<p>The cost of buying <b>' + productInfo.quantity + '</b> of <b>' + product + '</b> is $<b>' + Math.round(actualProductCost * 100)/100 + '</b></p>'; | |
purchaseMessage += '<p>The discount for this purchase is $<b>' + Math.round(savings * 100)/100 + '</b></p>'; | |
} | |
} | |
purchaseMessage += '<p>With the discount, your total of your order is $<b>' + Math.round(runningTotal * 100/100) + '</b>.</p>'; | |
document.getElementById('sales-order').innerHTML = purchaseMessage; | |
} | |
welcome(); | |
orderProduct(); | |
</script> | |
</body> | |
</html> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment