function StartStatsModule () { var updateGameTimeEvent = function() { $.getJSON( "../api/getstats") .done(function(data) { var time = "Day " + data.gametime.days + ", "; if (data.gametime.hours < 10) time += "0"; time += data.gametime.hours; time += ":"; if (data.gametime.minutes < 10) time += "0"; time += data.gametime.minutes; $("#stats_time").html (time); $("#stats_players").html (data.players); }) .fail(function(jqxhr, textStatus, error) { console.log("Error fetching game stats"); }) .always(function() { }); window.setTimeout(updateGameTimeEvent, 2000); }; updateGameTimeEvent(); }