+1 vote
by (98.9k points)
Write a JavaScript code for displaying a digital clock on a web page.

1 Answer

0 votes
by (98.9k points)
Best answer
<!DOCTYPE html>
<html lang="en">
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Digital Clock</title>
        body {
            font-family: 'Arial', sans-serif;
            text-align: center;
            margin: 100px;
            font-size: 2em;

<div id="digitalClock"></div>

    function updateClock() {
        const now = new Date();
        const timeString = now.toTimeString().slice(0, 8);
        document.getElementById("digitalClock").innerHTML = timeString;

    setInterval(updateClock, 1000);
    updateClock(); // Display the clock immediately


Related questions

+1 vote
1 answer 180 views
+1 vote
1 answer 62 views

Doubtly is an online community for engineering students, offering:

  • Free viva questions PDFs
  • Previous year question papers (PYQs)
  • Academic doubt solutions
  • Expert-guided solutions

Get the pro version for free by logging in!

5.7k questions

5.1k answers


506 users