I am taking a class right now and I want to learn JavaScript because I would love to do this as a career in the future.
The assignment is to Create a Web page that allows a user to enter a purchase price into a text box; include a JavaScript function that calculates
shipping and handling. Add functionality to the script that adds a
minimum shipping and handling fee of $1.50 for any purchase that is
less than or equal to $25.00. For any orders over $25.00, add 10% to
the total purchase price for shipping and handling, but do not include
the $1.50 minimum shipping and handling fee. Th e formula for calculating
a percentage is price * percent / 100. For example, the formula
for calculating 10% of a $50.00 purchase price is 50
results in a shipping and handling fee of $5.00. After you determine
the total cost of the order (purchase plus shipping and handling),
display it in an alert dialog box.
Here is what I came up with:
<!DOCTYPE html PUBLIC “-//W3C//DTD XHTML 1.0 Strict//EN”
“
<html xmlns=”
<head>
<meta http-equiv=”Content-Type” content=”text/html; charset=utf-8″ />
<link rel=”stylesheet” href=”js_styles.css” type=”text/css” />
<title>Week 2 Calculating The Shipping Fees</title>
<script type=”text/javascript”>
/* <![CDATA[
function calcShipping();
{
if (price <= 25);
shipping = 1.50 ;
shipping = (price *(10/100);
}
/
</script>
</head>
<body>
<script type=”text/javascript”>
/* <![CDATA[
document.write(“Purchase price and shipping total”);
/* ]]>
</script>
<script type=”text/javascript”>
/* <![CDATA[
var price=prompt(“What is the purchase price?”);
function calcShipping();
document.write (“The purchase price is $” ” + (price) + “);
document.write (“The cost of shipping is $” ” + (shipping) + “);
var total = price + shipping;
document.write(“Your total price with shipping is $ ” + (total) + “);
/* ]]>
</script>
</body>
</html>