From a94be56583ac7481497a87623c9043c95ac81b67 Mon Sep 17 00:00:00 2001 From: Kilokem Date: Thu, 10 Oct 2024 19:02:07 +0200 Subject: [PATCH] StopwatchMiniProject --- MiniProjects/StopWatch/watch.html | 63 ++++++++++++++++++++++++++++++ MiniProjects/StopWatch/watch.js | 41 +++++++++++++++++++ Practice/AdvancedThings/index.html | 12 ++++++ Practice/AdvancedThings/script.js | 4 ++ 4 files changed, 120 insertions(+) create mode 100644 MiniProjects/StopWatch/watch.html create mode 100644 MiniProjects/StopWatch/watch.js create mode 100644 Practice/AdvancedThings/index.html create mode 100644 Practice/AdvancedThings/script.js diff --git a/MiniProjects/StopWatch/watch.html b/MiniProjects/StopWatch/watch.html new file mode 100644 index 0000000..a34f600 --- /dev/null +++ b/MiniProjects/StopWatch/watch.html @@ -0,0 +1,63 @@ + + + + + + StopWatch + + + +
+

StopWatch

+

00:00:00

+
+ + + +
+
+ + + \ No newline at end of file diff --git a/MiniProjects/StopWatch/watch.js b/MiniProjects/StopWatch/watch.js new file mode 100644 index 0000000..72fbcbd --- /dev/null +++ b/MiniProjects/StopWatch/watch.js @@ -0,0 +1,41 @@ +//The stopwatch is incremented using a closure function! +function stopwatch() { + var time = new Date(0, 0, 0, 0, 0, 0, 0); + var pause = false; + + function increment() { + if (!pause) { + time.setSeconds(time.getSeconds() + 1); + const hours = time.getHours().toString().padStart(2, "0"); + const minutes = time.getUTCMinutes().toString().padStart(2, "0"); + const seconds = time.getUTCSeconds().toString().padStart(2, "0"); + document.getElementById("time").innerHTML = `${hours}:${minutes}:${seconds}`; + } + } + + function pauseTimer() { + pause = true; + } + + return { increment, pauseTimer }; +} + +var timer = stopwatch(); +var intervalId; + +function start() { + if (!intervalId) { + intervalId = setInterval(timer.increment, 1000); + } +} + +function stop() { + timer.pauseTimer(); +} + +function reset() { + clearInterval(intervalId); + intervalId = null; + timer = stopwatch(); + document.getElementById("time").innerHTML = "00:00:00"; +} diff --git a/Practice/AdvancedThings/index.html b/Practice/AdvancedThings/index.html new file mode 100644 index 0000000..cd01ed3 --- /dev/null +++ b/Practice/AdvancedThings/index.html @@ -0,0 +1,12 @@ + + + + + + Tittle + + +

For every output check out the console!!!

+ + + \ No newline at end of file diff --git a/Practice/AdvancedThings/script.js b/Practice/AdvancedThings/script.js new file mode 100644 index 0000000..8e193bb --- /dev/null +++ b/Practice/AdvancedThings/script.js @@ -0,0 +1,4 @@ +console.log("Hello World"); + +//I shall continue from this poin: +//https://youtu.be/lfmg-EJ8gm4?feature=shared&t=27294 \ No newline at end of file