I am supposed to figure shipping cost when a user enters the information in the field. If it is under $25 then it is supposed to charge a flat $1.50, but if they spend more than $25.00 it is supposed to add 10% for sales tax. Also it alerts them that they are entitled to a gift when they spend over $100. When I enter a value under $25 it works, but anything over $25 and it puts it together as a ‘string’ and shows some crazy numbers. I am still learning, but can anyone help me to understand why this is. Here is my code:
Code:
<!Doctype html>
<head>
<title>Total Cost</title>
<meta http-equiv="content-type" content="text/html;charset=utf-8" />
<script type="text/javascript">
function applyShipping() {
var salesPrice = parseFloat(document.sales.Price.value);
var minCharge = salesPrice + 1.50;
var shipping = salesPrice * 10 / 100;
if (salesPrice <= 24.99) {
window.alert("Your sales total including shipping is $" + minCharge);
} else {
window.alert("Your sales total including shipping is $" + salesPrice + shipping);
}
if (salesPrice >= 100.00){
window.alert("you are entitled to a free gift.")
}
}
</script>
</head>
<body>
<form id="sales">
<div >
<p>Enter Purchase Price</p>
<input type="text" name="Price" /><br /><br />
<input type="button" name="Calculate" value="Calculate Shipping"
onclick="applyShipping()" />
</div>
</form>
</body>
</html>