Like most things in programming, there's a bunch of different ways we could go about this -- each with their own pluses and minuses. Two alternatives that come to mind are:
- We could create another timer that fires every 1000 milliseconds (once per second), and which subtracts 1 from time_remaining
- Or, we could use our 40FPS timer, and subtract 1/40th of a second from time_remaining each time.
We'll take the second approach. Obviously that will lead to some funky fractional values in time_remaining, but we'll just
round it as we display it:
time_remaining = time_remaining - 1/40;
ctx.fillText("Time Remaining: " + Math.round(time_remaining), 0, 45);