startit/team/variabler/healthMana.html

83 lines
2.5 KiB
HTML
Raw Normal View History

2024-08-12 11:13:45 +02:00
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
2024-08-14 14:52:08 +02:00
<title>Health og Mana</title>
<style>
body {
margin: 0;
padding: 0;
}
.container {
border: 10px solid greenyellow;
display: grid;
grid-template-columns: repeat(4, 1fr);
height: 10vh;
}
.header{
border: 10px solid grey;
border-radius: 10px;
background-color: antiquewhite;
font-size: x-large;
}
</style>
2024-08-12 11:13:45 +02:00
</head>
<body>
2024-08-14 14:52:08 +02:00
<div class="header">Add or delete potions from inventory</div>
<div class="container">
2024-08-12 14:43:57 +02:00
<button onclick="addHealth()">add health potion</button>
<button onclick="delHealth()">delete health potion</button>
<button onclick="addMana()">add mana potion</button>
<button onclick="delMana()">delete mana potion</button>
</div>
<div>
<div onclick="showHideInventory()">
2024-08-14 14:52:08 +02:00
<div class="header">Inventory</div>
2024-08-12 14:43:57 +02:00
</div>
<div id="inventory">
</div>
</div>
<script>
var healthTotal = 0;
var manaTotal = 0;
var inventoryOpen = Boolean(false);
function addHealth() {
++healthTotal
document.getElementById("healthTotal").innerHTML = healthTotal;
}
function delHealth() {
--healthTotal
document.getElementById("healthTotal").innerHTML = healthTotal;
}
function addMana() {
++manaTotal
document.getElementById("manaTotal").innerHTML = manaTotal;
}
function delMana() {
--manaTotal
document.getElementById("manaTotal").innerHTML = manaTotal;
}
function showHideInventory() {
if (inventoryOpen != true) {
document.getElementById('inventory').innerHTML = /*HTML*/ `
2024-08-14 14:52:08 +02:00
<div class="container">Health<div id="healthTotal"></div>
2024-08-12 14:43:57 +02:00
Mana<div id="manaTotal"></div>
</div>`;
document.getElementById("manaTotal").innerHTML = manaTotal;
document.getElementById("healthTotal").innerHTML = healthTotal;
inventoryOpen = true;
} else {
blankAll()
inventoryOpen = false;
}
}
function blankAll() {
document.getElementById('inventory').innerHTML = '';
}
</script>
2024-08-12 11:13:45 +02:00
</body>
</html>