Monday, June 3, 2024
 Popular · Latest · Hot · Upcoming
13
rated 0 times [  17] [ 4]  / answers: 1 / hits: 19987  / 7 Years ago, thu, june 1, 2017, 12:00:00

I am making a quiz game for a project in HTML and JavaScript. On every question, the player has 15 seconds to answer. I managed to do it like this:



<body onload=setTimeout(Timer,15000)>


and then in Js:



function Timer()
{
alert(You are out of time!);
}


However, I want to be able to display how much time the player has left in a <p> tag. How could I do that?


More From » html

 Answers
19

<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);

[#57587] Wednesday, May 31, 2017, 7 Years  [reply] [flag answer]
Only authorized users can answer the question. Please sign in first, or register a free account.
dewayneh

Total Points: 538
Total Questions: 114
Total Answers: 97

Location: Liberia
Member since Fri, Oct 22, 2021
3 Years ago
dewayneh questions
Sat, Sep 4, 21, 00:00, 3 Years ago
Sun, Nov 1, 20, 00:00, 4 Years ago
Wed, Sep 23, 20, 00:00, 4 Years ago
Fri, Aug 7, 20, 00:00, 4 Years ago
Wed, Jul 29, 20, 00:00, 4 Years ago
;