I have made a variable called total and an if statement that check if total is above or equal to 10 then it write some text but the if statement is not refreshing when I am changing variable total somebody told me I need to use events in that case but I didn't know how
var price = 5;
var quantity = 0;
var ldiscountrate = 0.05;
var hdiscountrate = 0.1;
var total = 0;
var oldtotal = price * quantity;
if (oldtotal >= 10) {
discounttotal = total * ldiscountrate;
document.write("you have a discount total was " + oldtotal + "total after discount " + total);
}
else if (oldtotal >= 15) {
total = oldtotal * hdiscountrate;
document.write("you have a discount total was " + oldtotal + "total after discount " + total);
}
else {
total = oldtotal
document.write("you don't have a discount the total is " + total + "$");
}
<!DOCTYPE html>
<!--
To change this license header, choose License Headers in Project Properties.
To change this template file, choose Tools | Templates
and open the template in the editor.
-->
<html>
<head>
<title>Shopping</title>
<script type="text/javascript" src="JavaScript.js"></script>
</head>
<body>
<button type="button" onclick="var quantity+1">Add one item</button>
<button type="button" onclick="var quantity-1">Remove one item</button>
</body>
</html>
Aucun commentaire:
Enregistrer un commentaire