| <SCRIPT>
var digits =
4; //
the number of digits want
var visits = getCookie("counter");
/*
first check to see if the counter exists, if doesn't then set visits to
1 else increment the visits count by 1 to reflect the situation that
this page currently being loaded
*/
if
(!visits) visits = 1
else visits = parseInt(visits)
+ 1;
var
number = visits;
/*
loop through digits times (in this case 4) to setup by each individual
gif digit. Since we want the highest power displayed first (going left
to right) we'll start with digits (in this case 4) and work our way down
from 103 to 100 (Math.pow(10,
i - 1)). Using modulo we can get the remainder. By subtracting the
remainder from the visits number we end up with number in the form
(single digit) * 103. Now by dividing this number by
the Math.pow(10,
i - 1) we end up with a single digit number which we can
"associate" with a gif.
An
example for the first iteration using the following information:
digits =
4
visits = 2346
number = 2346
the for
loop goes from 4 to 1
1st Loop:
divisor =
Math.pow(10,
3) = 1000
remainder = 2346 % 1000 = 346
digit = (2346 - 346) / 1000 = 2
results in the
number 2 (two thousand) being placed in the left most position.
2nd Loop:
divisor =
Math.pow(10,
2) = 100
remainder = 346 % 100 = 46
digit = (346 - 46) / 100 = 3
results in the
number 3 (three hundred) being placed in the 2nd most left position.
continue this
process until all the digits have been evaluated.
*/
for (var
i = digits; i >= 1; i--) {
divisor = Math.pow(10,
i - 1);
remainder = visits % divisor;
digit = ((number - remainder) / divisor);
number = remainder;
counterStr += '<IMG SRC="odometer/' + digit + '.gif">';
}
setCookie("counter",
visits);
</SCRIPT>
<BODY>
etc...
<SCRIPT>
document.write(counterStr);
</SCRIPT>
</BODY> |