clock project in JS

22/32

Make two files(html-for html code;script-for JS)

html file code-->

<!DOCTYPE html>

<html lang="en">

<head>

<meta charset="UTF-8">

<meta name="viewport" content="width=device-width, initial-scale=1.0">

<title>Timer</title>

</head>

<body>

<div>

<h1 id="time"></h1>

<button id="stop-btn">Stop Timer</button>

<br>

<button id="start-btn">Start Timer</button>

</div>

<script src="script.js"></script>

</body>

</html>


script code-->

const button = document.getElementById("stop-btn");

const button1 = document.getElementById("start-btn");

function showTime(){

const currentTime = new Date();

console.log(currentTime);

const time = `${currentTime.getHours()}:${currentTime.getMinutes()}:${currentTime.getSeconds()}`

console.log(time);

document.getElementById("time").innerText = time;

}

// showTime();

// setTimeout(() => console.log("hi"),1000);

// setInterval(() =>console.log("hi"),5000);

// setInterval(showTime,1000);

let interval = setInterval(showTime,1000);

button.addEventListener("click",() => {

clearInterval(interval);

});

button1.addEventListener("click",() =>{

setInterval(showTime,1000);

})





























Comments

Popular posts from this blog

Blockchain Technology: Redefining Trust in the Digital Era

Essential - A clothing BRAND!!

FIRST PROJECT IN CPP(VECHILE PARKING MANAGEMENT SYSTEM!!)