My code doesnt work. | Sololearn: Learn to code for FREE!
Neuer Kurs! Jeder Programmierer sollte generative KI lernen!
Kostenlose Lektion ausprobieren
0

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

22nd Dec 2017, 8:51 PM
Zakariya
Zakariya - avatar
2 Antworten
+ 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; } }
22nd Dec 2017, 9:12 PM
ChaoticDawg
ChaoticDawg - avatar
+ 1
thanks
22nd Dec 2017, 9:13 PM
Zakariya
Zakariya - avatar