I'm working on a project that will feature many of these 'second by second' timers that will display how many animals are born per second :) Do you have any suggestions as to how I could best optimize this script for performance and DRY-ish?
JSFiddle here - http://jsfiddle.net/gJy4x/32/
var start = new Date(),
midnight = new Date(start.getFullYear(), start.getMonth(), start.getDate(), 0),
first = new Date(start.getFullYear(), start.getMonth(), 1);
setInterval(function () {
var now = new Date(),
secondsFromStart = Math.floor((now - start)/1000),
secondsFromMidnight = Math.floor((now - midnight)/1000),
secondsFromFirst = Math.floor((now - first)/1000),
puppiesBornPerSec = 3.16,
puppiesStart = Math.round(secondsFromStart*puppiesBornPerSec*100) / 100,
puppiesMidnight = Math.round(secondsFromMidnight*puppiesBornPerSec*100) / 100,
puppiesFirst = Math.round(secondsFromFirst*puppiesBornPerSec*100) / 100;
// 3 puppies born every second
$('#badge01').text(puppiesStart.toFixed(2));
$('#s01 .morning').text(puppiesMidnight.toFixed(2));
$('#s01 .month').text(puppiesFirst.toFixed(2));
// 5 kittens born every second
$('#badge02').text(Math.floor(secondsFromStart*5));
$('#s02 .morning').text(Math.floor(secondsFromMidnight*5));
$('#s02 .month').text(Math.floor(secondsFromFirst*5));
// 7 rats born every second
$('#badge03').text(Math.floor(secondsFromStart*7));
$('#s03 .morning').text(Math.floor(secondsFromMidnight*7));
$('#s03 .month').text(Math.floor(secondsFromFirst*7));
}, 1000);