用于测验的 JavaScript 计时器

Nen*_*nad 3 html javascript dom

我正在为 HTML 和 JavaScript 项目制作问答游戏。对于每个问题,玩家有 15 秒的时间来回答。我设法这样做:

<body onload="setTimeout(Timer,15000)">
Run Code Online (Sandbox Code Playgroud)

然后在 Js 中:

function Timer()
    {
         alert("You are out of time!");
    }
Run Code Online (Sandbox Code Playgroud)

但是,我希望能够显示玩家在<p>标签中剩余的时间。我怎么能那样做?

Sac*_*osh 6

<div id="count">Start</div>

var count = 15;
var interval = setInterval(function(){
  document.getElementById('count').innerHTML=count;
  count--;
  if (count === 0){
    clearInterval(interval);
    document.getElementById('count').innerHTML='Done';
    // or...
    alert("You're out of time!");
  }
}, 1000);
Run Code Online (Sandbox Code Playgroud)