Hi dear welcome to Ascode Blog . In this post we are going to learn how to make counting mechine using javascript. First Creat A index.html file Copy This HTML CODE and pest it one your code editor. 2ndly creat style.css file Then Copy The CSS CODE . 3rdly creat ap.js file Then Copy The Javascript CODE and pest it then open the index.html file with your browser.
HTML
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Counter javascript</title>
<script src="ap.js"></script>
</head>
<body>
<div id="number"></div>
</body>
</html>
CSS
*{
margin: 0;
padding: 0;
font-family:'Lucida Sans', 'Lucida Sans Regular', 'Lucida Grande', 'Lucida Sans Unicode', Geneva, Verdana, sans-serif;
box-sizing: border-box;
}
body {
display: flex;
justify-content: center;
align-items: center ;
min-height: 100vh;
}
#number {
font-size: 7rem;
padding: 30px 50px;
background: #000;
color: #fff;
width: fit-content;
font-weight: 600;
border-radius:10px ;
margin: 10px;
}
Javascript
let number = document.getElementById('number');
let Counter = 0;
setInterval(() => {
Counter += 1;
number.innerHTML = Counter + '';
}, 10);
0 Comments