Skip to content

Commit 305b80c

Browse files
committed
THE-MATH-GAME
1 parent 3218411 commit 305b80c

3 files changed

Lines changed: 37 additions & 0 deletions

File tree

Source Code/css/style.css

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,11 @@
1616
box-sizing: border-box;
1717
}
1818

19+
/*
20+
Body Background:
21+
Uses a radial-gradient() for a dynamic, visually appealing background.
22+
The gradient creates a spotlight effect, transitioning from white (#fff) at the center to grey (#ccc) at the edges.
23+
*/
1924
body {
2025
width: 100%;
2126
height: 100vh;
@@ -102,6 +107,12 @@ h1 {
102107
justify-content: space-between;
103108
}
104109

110+
/*
111+
Answer Box Styling:
112+
Flexbox column layout with centered content.
113+
CSS transition provides smooth hover/active state animations.
114+
The 'cursor: pointer' and ':hover'/':active' pseudo-classes enhance user interaction feedback.
115+
*/
105116
.box {
106117
width: 85px;
107118
height: 85px;

Source Code/index.html

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,11 @@
2121

2222
<body>
2323
<h1>The Math Game</h1>
24+
<!--
25+
Main Game Container:
26+
Houses all game UI elements including score, question display,
27+
answer choices, start/reset button, and timer.
28+
-->
2429
<div id="container">
2530
<div id="score">
2631
Score : <span id="scorevalue">0</span>
@@ -37,6 +42,11 @@ <h1>The Math Game</h1>
3742
<div id="instruction">
3843
Click on the Correct Answer
3944
</div>
45+
<!--
46+
Answer Choices:
47+
Four answer boxes displayed using Flexbox layout.
48+
Only one contains the correct answer; the rest are random distractors.
49+
-->
4050
<div id="choices">
4151
<div id="box1" class="box"></div>
4252
<div id="box2" class="box"></div>

Source Code/js/script.js

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,9 @@
88
* Repository: https://github.com/Amey-Thakur/THE-MATH-GAME
99
* License: MIT
1010
*/
11+
// Game State Variables
12+
// Tracks whether the game is active, the current score, the timer interval reference,
13+
// the remaining time, and the correct answer for the current question.
1114
var playing = false;
1215
var score = 0;
1316
var action;
@@ -79,6 +82,12 @@ for (let i = 1; i < 5; i++) {
7982
}
8083
}
8184

85+
/**
86+
* Countdown Timer Implementation
87+
* Uses setInterval() to decrement the time every 1000ms (1 second).
88+
* When time reaches zero, the game ends: score is displayed, UI is reset,
89+
* and the game state is set to 'not playing'.
90+
*/
8291
function startCountdown() {
8392
action = setInterval(() => {
8493
//reduce time by 1sec in loops
@@ -120,6 +129,13 @@ function showElement(Id) {
120129
document.querySelector("#" + Id).style.display = "block";
121130
}
122131

132+
/**
133+
* Question & Answer Generation Algorithm
134+
* Generates two random single-digit numbers (1-9) and calculates their product.
135+
* Places the correct answer in a randomly selected box (1-4).
136+
* Fills remaining boxes with unique wrong answers using a do-while loop
137+
* to avoid duplicates (preventing identical distractor values).
138+
*/
123139
function generateQA() {
124140
//generating random number between 1-9
125141
var x = 1 + Math.round(9 * Math.random());

0 commit comments

Comments
 (0)