From f579d509e50b127b54b8af8b0403b424538e3727 Mon Sep 17 00:00:00 2001
From: williamtitus295661
<160694407+williamtitus295661@users.noreply.github.com>
Date: Mon, 9 Dec 2024 22:11:43 -0500
Subject: [PATCH] added timer and dark mode
---
index.html | 1 +
js/main.js | 29 +++++++++++++++--
pages/main.html | 84 +++++++++++++++++++++++++++++++++++++++++++++++--
3 files changed, 109 insertions(+), 5 deletions(-)
diff --git a/index.html b/index.html
index 053194e..753249b 100644
--- a/index.html
+++ b/index.html
@@ -10,6 +10,7 @@
+
diff --git a/js/main.js b/js/main.js
index fd644e0..87207fa 100644
--- a/js/main.js
+++ b/js/main.js
@@ -224,8 +224,8 @@ function examiner(up_number, down_number, sign_of_question, answer_of_student) {
function resultGenerator() {
total_time = end_time - start_time;
time_taken_seconds = parseInt(total_time / 1000);
- time_taken_minutes = 00;
- time_taken_hours = 00;
+ time_taken_minutes = '00';
+ time_taken_hours = '00';
if (time_taken_seconds > 59) {
time_taken_minutes = parseInt(time_taken_seconds / 60);
@@ -471,6 +471,31 @@ function createStartornotpage() {
start_now_btn.addEventListener('click', createTestpage);
}
+
+function startTimer(duration, display) {
+ let timer = duration, minutes, seconds;
+ setInterval(function () {
+ minutes = parseInt(timer / 60, 10);
+ seconds = parseInt(timer % 60, 10);
+
+ minutes = minutes < 10 ? "0" + minutes : minutes;
+ seconds = seconds < 10 ? "0" + seconds : seconds;
+
+ display.textContent = minutes + ":" + seconds;
+
+ if (--timer < 0) {
+ timer = 0;
+ alert("Time's up!");
+ // You can add any additional actions here, like submitting the test automatically
+ }
+ }, 1000);
+}
+
+window.onload = function () {
+ const timeLimit = 60 * 10; // 10 minutes
+ const display = document.querySelector('#time');
+ startTimer(timeLimit, display);
+};
// document.querySelector('#difficulty').addEventListener('change', change_max_attr_val())
function change_max_attr_val() {
diff --git a/pages/main.html b/pages/main.html
index 7b38cb2..44330a7 100644
--- a/pages/main.html
+++ b/pages/main.html
@@ -9,6 +9,52 @@
+
@@ -16,6 +62,8 @@
@@ -87,8 +135,10 @@
Result 🧐
-
+
+
Time Left: 00:00
+
+
@@ -197,7 +247,35 @@
Fill them!