Javascript Health & Damage
Hello sololearners! I'm still struggling with JScript here, im trying to make a simple battle as an exercise to practice: document.getElementById("Damage").addEventListener("click", attack); let goblinHP = 50; function attack(){ let dPoint = Math.floor((Math.random()*10) + 1); let goblinHP = goblinHP - dPoint; return goblinHP; document.getElementById('textbox').innerHTML = `Goblin received ${dPoint} points of damage!`; document.getElementById('health').innerHTML = `${goblinHP} HP`; } So basically i have an enemy called "goblin", and a button with id "damage" on it, which generates a random between 1 - 10 to deal damage to the "goblin", then there <p> element with id "Health" ( <p id="health">50 HP</p> ) , which i want to change each time i press "attack". I thought my code would work but it doesn't. Am i messing up the scope? Thanks !