- Joined
- Jan 29, 2020
- Messages
- 18
- Reaction score
- 0
so i have this assignment and for the life of me i cant figure it out or even begin anywhere im hoping this will be enough information for some one to kinda give me a head in the right direction, ive tried reading all kinds everywhere and just dont know where to begin.
above is the code and below are my directions
Bug report: the previous algorithm allows people to buy things when they don't have enough money.
Correct that bug: Perform some maintenance on your Button's program.
JavaScript:
<!DOCTYPE html>
<html><head><style>p {font-family: arial; font-size: 20px;} </style></head>
<body>
<button onclick='buyApple()'>Purchase Appple</button>
<button onclick='buyOrange()'>Purchase Orange</button>
<button onclick='buyTortilla()'>Purchase Tortilla</button>
<button onclick='freeMoney()'>Found Money</button>
<!-- This marks space for a paragraph that we can update during the program -->
<p id="balance"></p>
<script>
// javascript code begin
// Step 1. initialize variables:
change=100 // starting balance
apple=10 // price of 1 apple
orange=20 // price of 1 orange
tortilla=30 // price of 1 tortilla
foundMoney=25 // pretend found $25
// initialize the user-interface when this page loads:
document.getElementById("balance").innerHTML = "$"+change;
// Step 2. define event functions for each button
function buyApple(){
change -= apple;
document.getElementById("balance").innerHTML = "$"+change;
}
function buyOrange(){
change -= orange;
document.getElementById("balance").innerHTML = "$"+change;
}
function buyTortilla(){
change -= tortilla;
document.getElementById("balance").innerHTML = "$"+change;
}
function freeMoney(){
change += foundMoney;
document.getElementById("balance").innerHTML = "$"+change;
}
// javascript code end
</script>
</body>
</html>
above is the code and below are my directions
Bug report: the previous algorithm allows people to buy things when they don't have enough money.
Correct that bug: Perform some maintenance on your Button's program.
- Don't allow purchases when the change is less than the purchase.
- Provide some feedback when that happens.
- Using conditionals, prevent people from buying things when they don't have enough money.
- For each button function, add some type of notification in your if-statments when that happens such as
- You could give them a popup alert:
alert("Denied: Insufficient balance");
- You could give them a popup alert:
- Or write a message:
document.write("Denied: Insufficient balance"); - Or update a spot on the page (best method):
document.getElementById("message").innetHTML= "Denied: Insufficient balance");
- Or write a message: