Now we need some sort of method to end our game when time runs out, or when either our player or enemy's health bar is fully depleted. We'll code this functionality using JavaScript's setTimeout
function, and monitor our fighters' health using something custom.
at 4:30, my clock does NOT do countdown what does it mean?
this is my index.js:
let timer = 10 function decreaseTimer(){ // infinite loop = requestAnimationFrame(animate) if (timer > 0) { setTimeout(decreaseTimer, 1000) timer-- document.querySelector('#timer').innerHTML = timer // innerHTML = cái số 10 á } if (player.health === enemy.health){ console.log('tie') } }
and this is my index.html:
<!-- timer --> <div id="timer" style=" background-color: red; width: 100px; height: 100px; flex-shrink: 0; display: flex; align-items: center; justify-content: center;"> 10 </div>