JavaScript Program Display Time After User Clicks Button

Write a JavaScript program display time after user clicks button.



Source Code
<html>
<head>
    <title>Display time on button click using function</title>
</head>
<body>

<p>Click the button to display the date.</p>

<button onclick="displayDate()">The time is?</button>

<script>
    function displayDate() {
        document.getElementById("demo").innerHTML = Date();
    }
</script>

<p id="demo"></p>

</body>
</html> 
Output





"Coding Hub - Learn to code" app now available on Google Play Store