From 504ac14c3201dda8f55af489a70b935a87e77ef8 Mon Sep 17 00:00:00 2001 From: Dorstener Date: Mon, 29 Apr 2024 20:30:37 +0200 Subject: [PATCH] adjusted the function attack local storage and now it properly reflects the changes in health when being attacked --- script.js | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/script.js b/script.js index bbf137e..5a7b897 100644 --- a/script.js +++ b/script.js @@ -236,13 +236,14 @@ function attack() { text.innerText = "The " + monsters[fighting].name + " attacks."; let actualWeapon = localStorage.getItem("Current Weapon"); text.innerText += " You attack it with your " + weapons[actualWeapon].name + "."; - health -= getMonsterAttackValue(monsters[fighting].level); + let actualHealth = localStorage.getItem("Health"); + actualHealth -= getMonsterAttackValue(monsters[fighting].level); if (isMonsterHit()) { monsterHealth -= weapons[actualWeapon].power + Math.floor(Math.random() * xp) + 1; } else { text.innerText += " You miss."; }; - let actualHealth = localStorage.getItem("Health"); + healthText.innerText = actualHealth; monsterHealthText.innerText = monsterHealth; if (actualHealth <= 0) {