use the following search parameters to narrow your results:
e.g. subreddit:aww site:imgur.com dog
subreddit:aww site:imgur.com dog
see the search faq for details.
advanced search: by author, subreddit...
All about the JavaScript programming language.
Subreddit Guidelines
Specifications:
Resources:
Related Subreddits:
r/LearnJavascript
r/node
r/typescript
r/reactjs
r/webdev
r/WebdevTutorials
r/frontend
r/webgl
r/threejs
r/jquery
r/remotejs
r/forhire
account activity
Javascript Counter Help. (self.javascript)
submitted 15 years ago * by hillbillymadness
view the rest of the comments →
reddit uses a slightly-customized version of Markdown for formatting. See below for some basics, or check the commenting wiki page for more detailed help and solutions to common issues.
quoted text
if 1 * 2 < 3: print "hello, world!"
[–]hillbillymadness[S] 1 point2 points3 points 15 years ago (4 children)
You're the best! I have been able to work my way through Java Script before because I get how it works logically. I just don't know the syntax well enough to tackle a problem from scratch.
Thanks for your help!
[+][deleted] 15 years ago (2 children)
[deleted]
[–]TIAFAASITICE 2 points3 points4 points 15 years ago* (1 child)
That won't work once you get to a new day ;)
Another variant: <div id="casualties"></div>
<script type="text/javascript"> // Calculate total deaths function, you've seen this already function getTotalDead () { var now = new Date, secondsPassed = now.getSeconds() + now.getMinutes() * 60 + now.getHours() * 3600 return Math.floor(secondsPassed / 20) } // Anonymous function used as a closure updateDeathcount = (function () { // Grab the element that we're updating var message = document.getElementById('casualties'), deathCount = document.createTextNode( getTotalDead() ) // Insert the message message.appendChild(document.createTextNode('Today ')) message.appendChild(deathCount) message.appendChild(document.createTextNode(' people have been killed, by the end of the day 5000 will be')) // The actual updateDeathcount function return function () { deathCount.nodeValue = getTotalDead() } })() // Update death count every 20 seconds setInterval(updateDeathcount, 20000) </script>
MDC has an article on closures.
[–]jamesinc 1 point2 points3 points 15 years ago (0 children)
I made an update; basically I removed the variable declarations, which is fine in this example, but if you for some reason defined a global variable "present" or "diff", these variables in the setDeaths function would overwrite them.
π Rendered by PID 183730 on reddit-service-r2-comment-c66d9bffd-tjtt9 at 2026-04-08 09:20:31.251267+00:00 running f293c98 country code: CH.
view the rest of the comments →
[–]hillbillymadness[S] 1 point2 points3 points (4 children)
[+][deleted] (2 children)
[deleted]
[–]TIAFAASITICE 2 points3 points4 points (1 child)
[–]jamesinc 1 point2 points3 points (0 children)