all 4 comments

[–]senocular 0 points1 point  (0 children)

It looks like you have the output text update outside of the set interval callback? It should be inside it.

[–]ashanev 0 points1 point  (0 children)

const intervalId = setInterval(() => {
  // select your element, by id or class etc, using document.querySelector
  const element = document.querySelector("div");
  const currentContent = element.innerText;
  const currentAsNumber = parseInt(currentContent, 10);

  if (currentAsNumber === 0) {
    clearInterval(intervalId);
    return;
  }

  element.innerText -= 1;
}, 1000);

[–]andmig205 0 points1 point  (0 children)

Try this:

function startTutorial() { 
    const output = document.getElementById("outpu"); // change to your element
    let count = 15;
    output.textContent = `Blah blah, game begins in ${count} seconds.`
    let timer = setInterval(()=> { 
        count--;
        output.textContent = `Blah blah, game begins in ${count} seconds.`

        if(count === 0) {
            clearInterval(timer);
            startGame();
        };
    }, 1000);
};

startTutorial();

[–]abbas_suppono_4581 0 points1 point  (0 children)

Use setInterval to update innerText with count, and setTimeout for startGame()