Skip to content

Commit 1587d0a

Browse files
Jim Lystgitbook-bot
authored andcommitted
GitBook: [master] one page modified
1 parent 5f86795 commit 1587d0a

File tree

1 file changed

+7
-0
lines changed

1 file changed

+7
-0
lines changed

docs/advanced/code-mod-examples/add-a-question-timer-with-pause-button.md

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ Add the following HTML element insider your question screen section--possibly at
2121
Add the code shown below to your `displayQuestion ( )` function inside the curly braces `{ }` of the function's code block. The Javascript function called `setInterval` runs a block of code at a set interval. In this example, we run a block of code every 100 milliseconds that allows us to update the countdown timer accurately. If the timer reaches zero, it triggers an incorrect answer using `trivia.triggerAnswer(false)`. Notice that you can adjust the time limit by changing the `timeLimit` variable.
2222

2323
```javascript
24+
$("#pause-game").show(); //in case it was hidden
2425
$("#pause-game").html("Pause");
2526
var timeLimit = 10;
2627
var startTime = Date.now();
@@ -56,6 +57,12 @@ function togglePause() {
5657
}
5758
```
5859

60+
Add the following line to the top \(but inside the curly braces\) of your `onClickedAnswer` function. This will hide the pause button after an answer is clicked. It probably doesn't make sense to have that button showing after the answer is clicked.
61+
62+
```javascript
63+
$("#pause-game").hide();
64+
```
65+
5966
### CSS
6067

6168
Below is an example of some basic CSS properties you could apply in your stylesheet. Adjust as needed.

0 commit comments

Comments
 (0)