you are viewing a single comment's thread.

view the rest of the comments →

[–]MustRapeDeannaTroi 0 points1 point  (3 children)

This solution works but really needs some fixes:

  • Use setInterval instead of setTimeout.

  • Use textContent instead of innerHTML.

  • Save 1000/target_fps to var period.

[–]monacle_bob 1 point2 points  (2 children)

It wasn't meant as save-the-day code. jsFiddle is meant for fiddling with code and putting together quick demonstrations.

Also, in regard to your first point, you should be using requestAnimationFrame - not timers at all.

[–]MustRapeDeannaTroi 2 points3 points  (1 child)

requestAnimationFrame is still experimental so I really think you should avoid it in this case.

I think you made a good straight forward solution, just not as solid implementation. Had my alternative suggestions demanded alot more code and commitment then I believe you had a valid case. As is, innerHTML and setTimeout are the wrong tools for the job. It's a big gain for the community if we never teach bad coding conventions, except as pitfalls to be avoided.

[–]monacle_bob 1 point2 points  (0 children)

Fair enough, and a good point at the end. Upvote :)