The new Javascript countdown timer
I got a couple of requests for a version of the bond countdown timer that’d work with Blogger or any other non-self-hosted blogging system.
Here it is, with comments and all too. See, two years of teaching programming style haven’t gone down the drain. Much.
<script type=""text/javascript">
function formatAsMoney(mnt) {
mnt -= 0;
mnt = (Math.round(mnt*100))/100;
return (mnt == Math.floor(mnt)) ? mnt + '.00'
: ( (mnt*10 == Math.floor(mnt*10)) ?
mnt + '0' : mnt);
} // from http://www.rgagnon.com/jsdetails/js-0076.html
/*
Simple script that writes out a line of text with how many days
of bond left to go, and how much it's worth right now if paid up.
E.g. "1870 days and $496250.40 left to go". Extremely
depressing.
Variables to change:
enddate:
The end date of the bond, assuming a full (4/6/8-year) bond.
enddate_discount:
The end date of the bond assuming it's completed. Applies only
to those who serve full-time NS and have half of that counted
towards the bond (usually 10 months), or teachers whose NIE term
isn't counted unless they complete the bond.
startdate:
First day of work.
bond:
Bond value with interest and LD. Assumes a linear depreciation
of an already-compounded bond value with liquidated damages.
The amount signed on the contract can be used as a rough estimate.
OPTIONAL -- nowdate:
Change to a date in the future e.g.
nowdate = new Date("June 20, 2009");
to see how much to pay at that point of time.
*/
var enddate = new Date("June 20, 2011");
var enddate_discount = new Date("August 20, 2010");
// Uncomment this following line if end date is fixed:
// enddate_discount = enddate;
var startdate = new Date("June 20, 2005");
var bond = 500000;
var nowdate = new Date();
ms1 = enddate_discount - nowdate;
days = Math.floor(ms1 / 86400000); // from millisecs to days
document.write(days);
document.write(" days and ");
total = enddate - startdate;
ms2 = enddate - nowdate;
rem = formatAsMoney(ms2 / total * bond);
document.write("$");
document.write(rem);
document.write(" left to go");
</script>
To use, copy and paste the entire section into anywhere you want the words "x days and $y left to go" to show up, making sure to customise the variables for your own situation — bond value and the start and end dates. If there’s an error, let me know by email or on the comments.
Enjoy ![]()
July 10th, 2005 at 11:18 pm
[…] But the economic angle is far from the only important aspect of the scholarship system. Zuco touches upon the disparity between the social engineering benefits of the scholarship system, and the needs of the scholarship agency itself. Arguably the staffing requirements of said agencies is the only (economically) rational driving factor for instituting a scholarship system, but in the past it had the additional benefit of greasing the paths of upward social mobility for a select few. Which in recent years appear to have become a very select few, indeed, as mentioned by Sze Meng: This year’s President’s Scholars all live in private housing, and quite arguably belong solidly to the upper-middle classes. Mr. Wang Zhen of Commentary Singapore also notes the classist disparity. Mr. Wang Examines Scholarship Issues and Why it worked then, & why it fails now are incisive pieces on how modern society challenges the validity of the fundamental principles upon which the scholarship system was first founded: the confluence of increased affluence and an accelerated pace of life make scholarships suddenly look like the slow train to wealth and success, rather than the iron rice bowl that gleamed so gloriously in yesteryear. And the bit about scholars biding their time is so true. Perhaps without meaning it, YJ is proving the point with his bond countdown timer script. […]
May 19th, 2006 at 7:13 pm
Hi,
Could you possibly do one that just counts down to a spesific date in the future - i want to post in on my site -how many days, minutes and sec. before i get married in nov 06 - thanks!