New course! Every coder should learn Generative AI!
Try a free lesson0
My code doesnt work.
i was testing my game when i realised it didn't work. You click the energy button. when the value is 20 or more, you can click the shop button and that value will increase and the energy will decrease. however, if you get 50 energy and click shop twice, the energy value will only go down once. and say i click the energy button after the shop button, it goes up in 21 then 1. Please fix. thanks https://code.sololearn.com/WSLJ6Xc80J5K/?ref=app
2 Answers
+ 4
function Func3(){
if(countEn >= 20){
// You need to subtract 20 from countEn and save that value back into countEn
countEn -= 20;
// Then you can just set 'energy' to that value and when 'energy' is clicked the value will increase as it should
document.getElementById('energy').innerHTML = countEn;
document.getElementById('coin').innerHTML = ++countMo;
}
}
+ 1
thanks