<html>
<head>
<title> Javascript Assignment 2: Matt Ciullo </title>
<!-- Matt Ciullo Annath JS - Part 2 - Implementation October 16, 2009 -->
</head>
<body bgcolor="99FFFF" >
<h1 align="center"> The Office- eCommerce </h1>
<td> <table width="100%" height="70%" border="3" align="center">
<tr height="30"> <td align="center" valign="top"> <font size="5"> Product name </font> </td> <td valign="top" align="center"> <font size="5"> Price </font> </td>
<td align="center" valign="top"> <font size="5"> Discount </font> </td> </tr>
<tr> <td> Printer </td> <td> $79.99 </td> <td> .1 </td> </tr>
<tr> <td> Chair </td> <td> $189.99 </td> <td> .2 </td>
<tr> <td> Monitor</td> <td> $169.99 </td> <td> .5 </td> </tr>
<tr> <td> Pens </td> <td> $15.99 </td> <td> .05 </td> </tr>
</table>
<script type="text/javascript">
var name;
var product;
var a;
var cost = 0;
var pprice = 0;
var discount = 0;
var quantity = 0;
var totalcost = 0;
var finalcost = 0;
name = prompt("Welcome to The Office Please enter your name." , "");
alert("Hello " + name + " Please look through our available products and services before placing your order." , "");
product = prompt("What product would you like to order today?", "");
pprice = 1*prompt("What's the price of the product you just ordered ?", "");
quantity = 1*prompt("Finally, how many " + product + "s would you like?", "");
a = confirm(name + "You ordered " + quantity + product + "s, Is this ok?");
if (a == false)
{
alert("Sorry, your item has not been found, please refresh and place another order.");
}
totalcost = (quantity*pprice);
if (product == "printer")
{
alert("You receive 10% discount!!!");
totalcost = (quantity*pprice);
cost = 0.9*(totalcost);
discount = .1*(totalcost);
}
else if (product == "chair")
{
alert("You receive 20% discount!!!");
cost = 0.8*(totalcost);
discount = .2*(totalcost);
}
else if (product == "monitor")
{
alert("You receive 50% discount!!!");
cost = 0.5*(totalcost);
discount = .5*(totalcost);
}
else if (product == "pens")
{
alert("You receive 5% discount!!!");
cost = 0.95*(totalcost);
discount = .05*(totalcost);
}
else
document.write(" Sorry," + name + "You entered an invalid product. Refresh the page to reload and place the order again.");
finalcost=(totalcost-discount);
document.write("Thank you for placing an order with us, " + name + ".<br> " );
document.write("The cost of buying " + quantity + " of " + product + "s is $ " + totalcost + ".<br> " );
document.write("The discount for this purchase is $ " + discount + ".<br> ");
document.write("With the discount, your total order cost is $" + finalcost + ".<br> " );
</script>
</body>
</html>
So when I get to the confirm statement, even if I hit cancel when it asks if you're sure you want this, it still prints out the discount, and all of the document.writes even though I do not want it to. If anyone could help it'd be greatly appreciated.

New Topic/Question
Reply



MultiQuote




|