# Fooling around with Code: Jean Luc Picard’s birthday countdown

Just fooling around to flex my scripting muscles (which are badly atrophied by now) and honor one of Star Fleet’s most illustrious captains.

This is how long we have to wait until Jean Luc Picard is born:

This is the code I used. It is not really exact as it does not account for leap years but this is going to be the task for version 1.2. So the code without leap years is this:

``````<!DOCTYPE HTML>
<div class="picard">

<p id="demo" style="font-size:25px";>

<script>
// Set the date we're counting down to
var countDownDate = new Date("Jul 13, 2305 00:00:00").getTime();

// Update the count down every 1 second
var x = setInterval(function() {

// Get today's date and time
var now = new Date().getTime();

// Find the distance between now and the count down date
var distance = countDownDate - now;

// Time calculations for years, days, hours, minutes and seconds
var years = Math.floor(distance / (1000 * 60 * 60 * 24 * 365));
var days = Math.floor((distance % (1000 * 60 * 60 * 24 * 365))/(1000 * 60 * 60 * 24));
var hours = Math.floor((distance % (1000 * 60 * 60 * 24)) / (1000 * 60 * 60));
var minutes = Math.floor((distance % (1000 * 60 * 60)) / (1000 * 60));
var seconds = Math.floor((distance % (1000 * 60)) / 1000);

// Output the result in an element with id="demo"
document.getElementById("demo").innerHTML = years+ "y " + days + "d " + hours + "h "
+ minutes + "m " + seconds + "s ";

// If the count down is over, write some text
if (distance < 0) {
clearInterval(x);
document.getElementById("demo").innerHTML = "EXPIRED";
}
}, 1000);
</script>
</div>

</body>
``````

This site uses Akismet to reduce spam. Learn how your comment data is processed.