JSFiddle - React, Tailwind, and code Playground

by Mariya_Korotkova

HTML

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <meta http-equiv="X-UA-Compatible" content="ie=edge">
    <title>Document</title>
</head>
<body>

    <script src='script.js'></script>
</body>
</html>

JavaScript

let time = document.createElement('div');

let timerId = setTimeout(function timer() {

    let now = new Date(),
        seconds = now.getSeconds(),
        minutes = now.getMinutes(),
        hours = now.getHours();

    function addZero() {
        if (hours / 10 < 1) {
            hours = '0' + hours;
        }
        if (minutes / 10 < 1) {
            minutes = '0' + minutes;
        }
        if (seconds / 10 < 1) {
            seconds = '0' + seconds;
        }
    }
    addZero();
    timeNow = hours + ':' + minutes + ':' + seconds;
    document.body.appendChild(time);
    time.textContent = timeNow;

    setTimeout(timer, 1000);
});