Looking for a simpler JavaScript timer

413 views Asked by At

Right now i have a text-based game that deals with turns, but i want to upgrade it to a timer system so that when the timer hits 0 then you gain 1 or 2 of whatever action you were doing. Also if you know how to make it randomly pick whether u get 1 item or 2 items could you please elaborate on how to do that? Thank you to all responses.

2

There are 2 answers

0
Andrew Marshall On BEST ANSWER

You can use setTimeout() for delaying actions for a set period of time, or setInterval() if you wish to run it periodically on a given interval.

For getting a random number either 1 or 2 you can use random():

var randomOneOrTwo = Math.floor(Math.random() * 2) + 1;
0
Yoko Zunna On