ASDV-WebDev/Semester 1/Assignments/JavaScript/MP09_CalebFontenot/public_html/Problem 6.html

41 lines
1.5 KiB
HTML

<!DOCTYPE html>
<!--
Click nbfs://nbhost/SystemFileSystem/Templates/Licenses/license-default.txt to change this license
Click nbfs://nbhost/SystemFileSystem/Templates/ClientSide/html.html to edit this template
-->
<html>
<head>
<title>TODO supply a title</title>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
</head>
<body>
<h1>Purchase items!</h1>
<p id="funds"></p>
<p>Click on an item to purchase it.</p>
<input type="button" onclick="updateFunds(900, 'Phone')" value="Phone ($900)">
<input type="button" onclick="updateFunds(150, 'Water Skin')" value="Water skin ($150)">
<input type="button" onclick="updateFunds(100, 'Sword')" value="Sword ($100)">
<input type="button" onclick="updateFunds(250, 'Invisibility Charm')" value="Invisibility Charm ($250)">
<script>
var points = prompt("Enter the number of points you've obtained.");
updateFunds(0);
function updateFunds(cost, item) {
if (points - cost >= 0) {
points -= cost;
if (item != undefined) {
alert(item + " has been added to your inventory.");
}
} else {
alert("Insufficient funds!");
}
document.getElementById("funds").innerHTML = "Remainding funds: $" + points;
}
</script>
</body>
</html>