Birthday Tracker

[Total: 0    Average: 0/5]

This shows how to have a birthday list that will show you when the next part should be.

Head Code:

<SCRIPT LANGUAGE="JavaScript">
<!--
  function birthday(year,month,date,person) {
    this.year=year
    this.month=month
    this.date=date
    this.person=person
  }

  function birthdaylist() {
  }

  blist=new birthdaylist()
  blist[0]= new birthday(82,6,29,"Benny")
  blist[1]= new birthday(79,3,4,"Sean")
  blist[2]= new birthday(81,4,7,"Mike")
  blist[3]= new birthday(82,5,23,"Chintan")
  blist[4]= new birthday(76,9,11,"Machin")
  blist[5]= new birthday(80,11,12,"Sara")
  
  var now=new Date()
  today=new Date(now.getYear(),now.getMonth(),now.getDate())   // today 0:00:00
  function daysFromToday(sdate) {
    return Math.round((sdate.getTime()-today.getTime())/(24*60*60*1000))
  }

  function writeNextBirthday(list) {
    var daysToClosest=888
    var closest
    for (var i in list) {
      thisDate=new Date(today.getYear(),list[i].month,list[i].date)
      if (daysFromToday(thisDate)<0)
        thisDate.setYear(today.getYear()+1)
      if (daysFromToday(thisDate)<daysToClosest) {
        daysToClosest=daysFromToday(thisDate)
        closest=i
      }
    }
    if (daysToClosest==0)
      document.write("<B>So today "+list[closest].person+" became "+(today.getYear()-list[closest].year)+" years old !! Hoorah!</B><P>")
    else if (daysToClosest==1)
      document.write("So tomorrow "+list[closest].person+" will become "+(today.getYear()-list[closest].year)+" !<P>")
    else
      document.write("So the next birthday will be "+list[closest].person+"'s, in "+daysToClosest+" days.<P>")
  }
        
// end hiding -->
</SCRIPT>

Body Code:

<H1>Birthday Calendar</H1>
<P>
Six birthdays are written on the calendar:
<P>
<PRE>
6/29 Benny 
3/4 Sean
4/7 Mike
5/23 Chintan
9/11 Machin
11/12 Sara
</PRE>
<P>
<SCRIPT LANGUAGE="JavaScript">
<!--  
  writeNextBirthday(blist)
// -->
</SCRIPT>

Times Viewed: 2

Leave a Reply

Your email address will not be published. Required fields are marked *