I'm just building an basic freight calculator for my site. When the user enters the parcels weight in kilograms in to the text box and clicks on the "Calculate Postage" button, your application will calculate the cost and display the amount in a paragraph.
So calculating the freight are as follows:
If the weight is greater than 0 and less than or equal to 5kg the freight is $7.50
Greater than 5kg and less than or equal 15kg the freight is $12.60
Anything above 15kg is a flat freight charge of $20.00
If the user does not enter a positive number, display an error message
And here is my code so fair,
JavaScript,
};
var price = 0;
var shipping = calculateShipping(price);
function calculate() {
var result = 0;
if (price <= 25){
result = 5kg;
}
else{
result = price * 10 / 100;
}
var total = result + (price - 0);
window.alert("Shipping is $" + result + ". Total is $" + total +".");
}
}
HTML
<!doctype html>
<html lang="en">
<html>
<head>
<meta charset="utf-8">
<title>Empire's Calculate Shipping</title>
<link rel="stylesheet" href="style.css">
<script src="javascript.js"></script>
</head>
<body><h1>Empire's Calculate Shipping</h1>
<p>Entre Your Postage Weight:
<input type="text" name="text" id="input" />kg
<input type="button" value="Calculate Shipping" onclick="calculateShipping(document.getElementById('price').value);" /></p>
</body>
</html>