viperfx07 is here to blog about hacking, cracking, website, application, android, and many more.

Tuesday, September 21, 2010

Week 8 Challenge: Javascript

5:42 PM Posted by viperfx07 No comments
This week's challenge is about JavaScript. Specifically, it's about a Date() function to how many days old you are and pop up this value in an alert box on an html page as it opens. Find out the codes below...

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "">
<html xmlns="" xml:lang="en" lang="en">
 <title>My Blog</title>
 <meta http-equiv="content-type" content="text/html; charset=iso-8859-1" />
 <script type="text/javascript">
  function calcDate()
  var today = new Date();
  var mybirthday = new Date(2010, 9, 5); //month is 0-11 in Javascript

  //Set 1 day in milliseconds
  var one_day=1000*60*60*24;

  //Calculate difference btw the two dates, and convert to days 
  alert("You are "+Math.ceil((today.getTime()-mybirthday.getTime())/(one_day))+" days old!");
<body onload="calcDate()">


Post a Comment