so in Javascript I am trying to display the text "halfWayDown" when My hP variable is equal or less than itself divided by 2. I am using a querySelectorAll and a "for loop" on essentially all of my elements, so I don't needlessly have to duplicate my code. Accordingly, for all of my code I am able to increment an individual variable at a time though there are others with the same class name; with the exception of my halfWayDown "div". It displays the text per "div" with the same class name. I am pretty new to programming and am self-taught. I am eager to learn, so any help is greatly appreciated. Here is my relevant code.
for (let i=0;i<hpDeductionBtn.length;i++){hPDeductinBtn[i].addEventListener("click",function(){
healthPointsDisplay[i].innerText= hP - parseInt(inputHpDeduction[i].value) + " Healthpoints";
hP=hP - parseInt(inputHpDeduction[i].value);
console.log(parseInt(inputHpDeduction[i].value))
if(hP<=initalHp/2){
for (let i=0;i<halfWayDownText.length;i++){
halfWayDownText[i].innerText="Halfway Down"};
}
clearDeductionInput();
})}
Thank you.
Via Active questions tagged javascript - Stack Overflow https://ift.tt/BpEImlW
Comments
Post a Comment