Programming Challenge 4/99 Age in seconds


Code:

<script>
function conv() {
    yearSeconds = 31536000;
    leapYearSeconds = 31622400;
    currentYear = 2019;
    seconds = 0;
    text = document.getElementById("txt").value;
    year = parseInt(text);
    while (year < currentYear){
        if (year % 4 === 0){
            seconds += leapYearSeconds;
        }
        else {
            seconds += yearSeconds;
        }
        year++;
    }
    document.getElementById("res").innerText = "From "+ text + " to 2019 elapsed:" + seconds + "seconds";
}
</script>
<input type="text" id="txt" value="2000"/>
<input type="button" onclick="conv()" value="Enter"/>
<br><p id="res"></p>

Leave a Comment