Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added stopwatch #5

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions scripts/script.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
//script.js

function sep(sep) {
const separators = document.querySelectorAll(".sep");
for (let i = 0; i < separators.length; i++)
Expand Down
37 changes: 37 additions & 0 deletions scripts/stopwatch.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
const STOPWATCH_CLOCK = [
document.querySelector("#stopwatch-hour"),
document.querySelector("#stopwatch-minute"),
document.querySelector("#stopwatch-second")
];

let stopwatchSeconds = 0;
let stopwatchInterval;

function startStopwatch() {
stopwatchInterval = setInterval(() => {
stopwatchSeconds++;

const h = Math.floor(stopwatchSeconds / 3600);
let s = stopwatchSeconds % 3600;
const m = Math.floor(s / 60);
s %= 60;

const t = [h, m, s];

for (let i = 0; i < STOPWATCH_CLOCK.length; i++) {
STOPWATCH_CLOCK[i].innerText = t[i] < 10 ? `0${t[i]}` : `${t[i]}`;
}
}, 1000);
}

function stopStopwatch() {
clearInterval(stopwatchInterval);
}

function resetStopwatch() {
stopwatchSeconds = 0;
stopStopwatch();
for (let i = 0; i < STOPWATCH_CLOCK.length; i++) {
STOPWATCH_CLOCK[i].innerText = '00';
}
}
2 changes: 2 additions & 0 deletions scripts/timer.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
timer.js

const CLOCK = [
document.querySelector("#hour"),
document.querySelector("#minute"),
Expand Down
1 change: 1 addition & 0 deletions styles/styles.css
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@

:root {
--light-bg: #fff;
--light-txt: #000;
Expand Down
2 changes: 2 additions & 0 deletions views/clock.ejs
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@


<!DOCTYPE html>
<html lang="en">

Expand Down
71 changes: 71 additions & 0 deletions views/stopwatch.ejs
Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@


<!DOCTYPE html>
<html lang="en">

<head>
<meta charset="UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<title>Big-Clock</title>
</head>

<link rel="stylesheet" href="./css/styles.css">

<!-- CDN -->
<link href="https://fonts.googleapis.com/css?family=Chivo+Mono:100,200,300,regular,500,600,700,800,900,100italic,200italic,300italic,italic,500italic,600italic,700italic,800italic,900italic" rel="stylesheet" />
<script src="https://kit.fontawesome.com/8070ea12a9.js" crossorigin="anonymous"></script>
<link href="https://fonts.googleapis.com/css?family=Roboto+Slab:100,200,300,regular,500,600,700,800,900" rel="stylesheet" />
<!-- CDN -->

<!-- <script src="https://code.jquery.com/jquery-3.6.3.min.js"
integrity="sha256-pvPw+upLPUjgMXY0G+8O0xUf+/Im1MZjXxxgOcBQBXU=" crossorigin="anonymous"></script> -->

<body class="back-light">
<!-- heading area -->
<header>
<span id="heading" class="sec-text sec-light">Big Clock</span>
<span class="header-menu">
<i class="fa-solid fa-moon text sec-light sec-text theme-toggle"></i>
<i class="fa-solid fa-ellipsis-vertical text sec-light sec-text menu"></i>
</span>
</header>
<!-- heading ends -->

<!-- clock area -->
<div id="main-area" class="main">
<span class="main-text main-light" id="stopwatch-hour">HH</span>
<span class="sep sec-light sec-text"></span>
<span class="main-text main-light" id="stopwatch-minute">MM</span>
<span class="sep sec-text sec-light"></span>
<span class="main-light main-text" id="stopwatch-second">SS</span>
</div>
<!-- clock ends-->

<!-- the footer area -->
<footer>
<!-- mode -->
<div class="mode">
</div>
</footer>
<!-- the footer area -->

<div class="menu-list hidden text sec-light">
<div class="menu-items">
<div class="menu-label">Theme</div>
<div class="menu-value"><%= THEME %></div>
</div>
<div class="menu-items">
<div class="menu-label">Show Date</div>
<div class="menu-value"><%= DATE %></div>
</div>
<div class="menu-items">
<div class="menu-label">Time Zone</div>
<div class="menu-value"><%= TZ %></div>
</div>
</div>

</body>

<script type="module" src="./js/stopwatch.js"></script>
<script type="module" src="./js/script.js"></script>
</html>