Saturday, January 4, 2014

Code for a baby...

I like to email myself stuff back that I've done. (As a result, I have a super cluttered inbox).

Here's an email that I found from 4/4/12 when I just started js.




var today=new Date ();

var longago= new Date(1996,1,4);

alert("I was born on " + longago);

var yeardiff= today.getFullYear() - longago.getFullYear();
var monthdiff= today.getMonth() - longago.getMonth();
var daydiff= today.getDate()- longago.getDate();

alert("Thus, I have been alive for " + yeardiff + " years and " + monthdiff + " months" + " and " + daydiff + " days.");

var exactage = (365*yeardiff+30*monthdiff+daydiff)/365;
alert("In other words, I am about " +exactage+ "years old.");

if (10*exactage % 10 < 5) {

    alert("I am not halfways through " + yeardiff + " yet. Need to wait until the next birthday!");

} else {alert("Yay! I am more than halfways through " + yeardiff + " already! a birthday coming soon!");}

lol

No comments:

Post a Comment