Countdown, click event?

A timing examination system is triggered if the click event is triggered within 5 seconds, and if it is not triggered, the system marks the correct answer at the end of the countdown. How to implement

Feb.26,2021

setTimeout , setTimeout has a return value, first receive it with a variable, and then empty the variable according to the situation to mark whether 5 seconds have elapsed:

var timeout;
timeout = setTimeout(function() {
  console.log('Timeout exceeded');
  showAnswer();
  timeout = null;
}, 5000);

$('-sharpsomeID').click(function() {
  console.log('User clicked!');
  if(timeout) {
    // 5
    clearTimeout(timeout);  // 
    // Do something here
  } else {
    // 5
    // Do something here
  }
});
Menu