Ejemplos en Javascript

Recordatorio

<HTML>
<HEAD>

<TITLE>Ejemplos Javascript: ejemplo pr???¡ctico </TITLE>

<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(78,1,8,"Mattias")
  blist[1]= new birthday(82,8,14,"Janneke")
  blist[2]= new birthday(80,8,31,"Toon")
  blist[3]= new birthday(79,3,1,"Sander")
  blist[4]= new birthday(54,7,31,"Marjan")
  blist[5]= new birthday(51,5,16,"Anton")
 
  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>

</HEAD>

<BODY bgcolor="white">

<H1>Birthday calendar</H1>
<P>
Six birthdays are written on the calendar:
<P>
<PRE>
February 8th    Mattias ('78)
April 1st       Sander ('79)
June 16th       Anton ('51)
August 31st     Marjan ('54)
September 14th  Janneke ('82)
October 30th    Toon ('80)
</PRE>
<P>
<SCRIPT LANGUAGE="JavaScript">
<!--  
  writeNextBirthday(blist)
// -->
</SCRIPT>



</body>
</html>

Fechas y horarios