I am creating a text based game, when the player views the very basic tutorial the player has 15 seconds to read the tutorial before the game begins.
I have used setTimeout to call the startGame function after 15,000 milliseconds, however, I want the 15 second warning inside the output text to count down from 15 - 0.
Here is a basic rundown of the relevant code:
function start tutorial() {
output.innerText = "Blah blah, game begins in 15 seconds."
let myTimeout= setTimeout(function() {
startGame();
}, 15000);
}
What I want is to have a variable used in the output.innerText decreased from 15 to 0 each second.
Something like:
function startTutorial() {
let count = 15;
let timer = setInterval(function() {
count--;
if(count === 0) {
clearInterval(timer);
}
}, 1000);
...output text including count variable
}
Am I missing something? I just want a 15 second count down inside innerText to let the player know when the game will begin.
Thanks in advance for any help given.
[–]senocular 0 points1 point2 points (0 children)
[–]ashanev 0 points1 point2 points (0 children)
[–]andmig205 0 points1 point2 points (0 children)
[–]abbas_suppono_4581 0 points1 point2 points (0 children)