troubleshooting Question

javascript counter year to date

Avatar of eezar21
eezar21 asked on
Web Languages and StandardsJavaScriptjQuery
7 Comments1 Solution398 ViewsLast Modified:
Hi,

I'm trying to create a counter to put on our website to show how many units we have sold this year to date.

I have attached the code below.  I have an average number of 1543 units sold per second, which would give me an approx number of 24 billion by end of June, but I can't seem to reach that number with what I have written.  Also the number generated seems to always start with a rounded number which isn't correct.

Any pointers would be really helpful.

Many thanks


<html>
<head>

</head>

<body>
test counter

<div id="counter">



</div>

<script type="text/javascript" src="http://code.jquery.com/jquery-1.7.1.min.js"></script>
<script>
// Set the unit values in milliseconds.
var msecPerMinute = 1000 * 60;
var msecPerHour = msecPerMinute * 60;
var msecPerDay = msecPerHour * 24;

// Set a date and get the milliseconds
var date = new Date('1/6/2013');
dateMsec = date.getTime();

// Set the date to January 1, at midnight, of the specified year.
date.setMonth(0);
date.setDate(1);
date.setHours(0, 0, 0, 0);

// Get the difference in milliseconds.
var interval = dateMsec - date.getTime(); 

//document.write (interval);

var counter = interval;

setInterval("timer()",1); 

function timer() {

counter++;

$('#counter').text(counter);	

}

</script>
Join the community to see this answer!
Join our exclusive community to see this answer & millions of others.
Unlock 1 Answer and 7 Comments.
Join the Community
Learn from the best

Network and collaborate with thousands of CTOs, CISOs, and IT Pros rooting for you and your success.

Andrew Hancock - VMware vExpert
See if this solution works for you by signing up for a 7 day free trial.
Unlock 1 Answer and 7 Comments.
Try for 7 days

”The time we save is the biggest benefit of E-E to our team. What could take multiple guys 2 hours or more each to find is accessed in around 15 minutes on Experts Exchange.

-Mike Kapnisakis, Warner Bros