mirror of
https://github.com/FranP-code/Vanilla-Javascript-Counter.git
synced 2025-10-12 23:52:56 +00:00
main script done
This commit is contained in:
17
index.html
17
index.html
@@ -0,0 +1,17 @@
|
||||
<!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>JavaScript counter</title>
|
||||
<script src="./script.js"></script>
|
||||
</head>
|
||||
<body>
|
||||
<div class="container">
|
||||
<div id="counter-element">
|
||||
|
||||
</div>
|
||||
</div>
|
||||
</body>
|
||||
</html>
|
||||
27
script.js
27
script.js
@@ -0,0 +1,27 @@
|
||||
function counter(number, seconds) {
|
||||
|
||||
seconds = seconds * 1000
|
||||
|
||||
const counterElement = document.getElementById('counter-element')
|
||||
let counterNumber = 0
|
||||
counterElement.innerText = counterNumber
|
||||
|
||||
function setTimeOutFunction() {
|
||||
|
||||
counterElement.innerText = counterNumber
|
||||
counterNumber++
|
||||
|
||||
if (counterNumber <= number) {
|
||||
|
||||
setTimeout(setTimeOutFunction, seconds)
|
||||
|
||||
} else {
|
||||
|
||||
clearTimeout(setTimeOutFunction)
|
||||
}
|
||||
}
|
||||
|
||||
setTimeout(setTimeOutFunction, seconds)
|
||||
}
|
||||
|
||||
window.onload = () => counter(45, 0.1)
|
||||
3
styles.css
Normal file
3
styles.css
Normal file
@@ -0,0 +1,3 @@
|
||||
|
||||
|
||||
/*# sourceMappingURL=styles.css.map */
|
||||
1
styles.css.map
Normal file
1
styles.css.map
Normal file
@@ -0,0 +1 @@
|
||||
{"version":3,"sourceRoot":"","sources":[],"names":[],"mappings":"","file":"styles.css"}
|
||||
Reference in New Issue
Block a user