Minus the value of a var every second. Please Help

Hello there,

I have a var that generates a random value between 40 and 60.

var rand = Math.floor(Math.random() * (60 - 40 + 1) + 40);

Could someone knowledgeable assist me, I’d like to minus 1 every second from the var, until it reaches zero then stop.

Been stuck on this for too long.

Thanks for your time and assistance.


Set an interval:

const handle = setInterval(function() {
  if (rand < 0) {
}, 1000);
1 Like

Thank you for the assist!


1 Like

This topic was automatically closed 182 days after the last reply. New replies are no longer allowed.