some code for teamwork

This commit is contained in:
Geir Okkenhaug Jerstad 2024-08-12 14:43:57 +02:00
parent 57b2ec3c00
commit b920162f3e

View file

@ -6,7 +6,58 @@
<title>Hei på deg!</title> <title>Hei på deg!</title>
</head> </head>
<body> <body>
Hei <div>
<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()">
Inventory
</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*/ `
<div>Health<div id="healthTotal"></div>
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>
</body> </body>
</html> </html>