WT Practical 7


Practical : 7
Subject : Web Technology

Aim : Write a JavaScript that uses function to calculate how many days are left in your birthday?


Source Code :
<!DOCTYPE html>

<html>
<head>
            <title>pratik008 DOB</title>
</head>
<body>
<input class="btn" type="button" value="Calculate Age" onclick="mybirthday()">
<div id="age"></div>                       
<script type="text/javascript">
function mybirthday()
{
    var month = parseInt(prompt("Enter Month (1-12)","") - 1);
    var day = parseInt(prompt("Enter Date (1-31)", ""));
    var birthday = new Date();
    birthday.setDate(day);
    birthday.setMonth(month);
    var today= new Date();
    var time_dif = birthday.getTime()-today.getTime();
    var day_diff=time_dif/(1000 * 3600 * 24);
    if(day_diff<0)
    {
        day_diff=(365+day_diff)
    }
document.getElementById("age").innerHTML = "Your Birthday : "+birthday+"<br/>Today : "+today+"<br/>Remaining days :"+day_diff;
}
</script>
</body>
</html>

Output :


Pratik Boghani

Author & Editor

Life is all about the next step.

0 comments:

Post a Comment