I'm new to HTML and I am trying to make a postage calculator using HTML and Javascript, the user inputs name weight of the package if they want express delivery. All the options affect the price but for some reason my variable express cost is stuck at £5.
<!DOCTYPE html>
<html>
<head>
<title>Postage Calculator</title>
<script>
function calCost() {
console.log("Invoked calCost()")
document.getElementById('displayName').innerHTML = document.getElementById("name").value;
var expressCost = 0;
if (document.getElementById('express').checked) ; //always checked
{
console.log("yup"); // this was to test if it was staying checked which it does.
expressCost = 5;
}
if (document.getElementById('r1').checked) {
document.getElementById('displayCost').innerHTML = "\u00A3" + (2 * document.getElementById("weight").value + expressCost);
}
else if (document.getElementById('r2').checked) {
document.getElementById('displayCost').innerHTML = "\u00A3" + (10 * document.getElementById("weight").value + expressCost);
}
else {
document.getElementById('displayCost').innerHTML = "\u00A3" + (5 * document.getElementById("weight").value + expressCost);
}
}
</script>
<label> Enter your name <input type = "text" name="name" id="name"></label><br>
<br>
<label> Enter weight <input type = "text" name="weight" id ="weight"></label> Kilograms<br>
<br>
<label>Do you want express delivery?<input type="checkbox" name="express" id="express"></label> Additional 5 Pounds <br>
<br>
<input type="radio" id="r1" name="rate" value="United Kingdom" checked="checked"> United Kingdom - 2 per Kilo<br>
<input type="radio" id="r2" name="rate" value="United States"> United States - 10 per Kilo<br>
<input type="radio" id="r3" name="rate" value="Europe"> Europe - 5 per Kilo <br>
This is the javascript for working out the total cost, i've tested starting up the program and submitting and instantly £5 is added to total even without it being checked and I have no idea.
Also just noticed that my variable is "variable initializer is redundant"