Sololearn: Learn to Code
New course! Every coder should learn Generative AI!
Try a free lesson
+ 2
As soon as this statement is read: setInterval(checkturn, 1000); it starts working so checkturn tries to getElementById("turned") since turni equals 2, but that #turned element still not part of the DOM, hasn't been created yet, that's why it throws error null every second.
5th Oct 2022, 1:24 AM
Arturop
Arturop - avatar
+ 1
After your first attack, turni is decremented from 2 to 1. now that turni=1, every if (turni == 1) return; will exit the corresponding function either attack() or heal(). var turni stays the same 1.
5th Oct 2022, 1:37 AM
Arturop
Arturop - avatar