Skip to content

Commit

Permalink
Merge pull request #4067 from bhumika-1127/mathQuiz
Browse files Browse the repository at this point in the history
math quiz wrt #4063
  • Loading branch information
kunjgit authored Jun 3, 2024
2 parents 84bea91 + 85f93ca commit 08d7901
Show file tree
Hide file tree
Showing 8 changed files with 204 additions and 3 deletions.
38 changes: 38 additions & 0 deletions Games/MathQuiz/Readme.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
# **MathQuiz**


## **Description 📃**
It is a basic mathematical quiz.


<br>

## **Functionalities 🎮**

Player need to find the correct answer to the maximum number of questions within 30 seconds.

<br>

## **How to play? 🕹️**

1. Start the quiz on your preferred platform.
2. Click on the start button to start the quiz.
3. Your goal is to answer maximum number of questions within 30 seconds.


<br>

## **Installation**
1. Clone or download the repository.
2. Navigate to the downloaded repository.
3. Open index.html with live server.




<br>

## **Screenshots 📸**

<br>
<img src="assets\images\MathQuiz.png" alt="Game Screenshot">
26 changes: 26 additions & 0 deletions Games/MathQuiz/index.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
<!DOCTYPE html>
<html>
<head>
<title>Math Quiz Game</title>
<link rel="stylesheet" type="text/css" href="styles.css">
</head>
<body>
<div id="game-container">
<h1>Math Quiz Game</h1>
<div id="instructions">
<p>Welcome to the Math Quiz Game! You have 30 seconds to answer as many questions as you can. Good luck!</p>
<button onclick="startGame()">Start Game</button>
</div>
<div id="game" style="display: none;">
<div id="question"></div>
<input type="number" id="answer" />
<button onclick="submitAnswer()">Submit Answer</button>
<div id="timer"></div>
<div id="result"></div>
<div id="score"></div>
</div>
</div>

<script src="script.js"></script>
</body>
</html>
78 changes: 78 additions & 0 deletions Games/MathQuiz/script.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,78 @@
let correctAnswers = 0;
let wrongAnswers = 0;
let currentQuestion;
let gameStarted = false;
let timer;
let timeLeft = 30;

function startGame() {
document.getElementById('instructions').style.display = 'none';
document.getElementById('game').style.display = 'block';
if (!gameStarted) {
gameStarted = true;
generateQuestion();
updateTimer();
timer = setInterval(updateTimer, 1000);
setTimeout(endGame, 20000);
}
}

function generateQuestion() {
const num1 = Math.floor(Math.random() * 10) + 1;
const num2 = Math.floor(Math.random() * 10) + 1;
const operations = ['+', '-', '*', '/'];
const operation = operations[Math.floor(Math.random() * operations.length)];

if (operation === '/' && num1 % num2 !== 0) {
generateQuestion(); // Avoid division questions with remainders
return;
}

currentQuestion = { num1, num2, operation };
document.getElementById('question').innerText = `What is ${num1} ${operation} ${num2}?`;
}

function submitAnswer() {
const answer = parseFloat(document.getElementById('answer').value);
let correctAnswer;

switch (currentQuestion.operation) {
case '+':
correctAnswer = currentQuestion.num1 + currentQuestion.num2;
break;
case '-':
correctAnswer = currentQuestion.num1 - currentQuestion.num2;
break;
case '*':
correctAnswer = currentQuestion.num1 * currentQuestion.num2;
break;
case '/':
correctAnswer = currentQuestion.num1 / currentQuestion.num2;
break;
}

if (answer === correctAnswer) {
correctAnswers++;
} else {
wrongAnswers++;
}

document.getElementById('answer').value = '';
generateQuestion();
}

function updateTimer() {
if (timeLeft > 0) {
document.getElementById('timer').innerText = `Time left: ${timeLeft} seconds`;
timeLeft--;
} else {
clearInterval(timer);
}
}

function endGame() {
clearInterval(timer);
gameStarted = false;
document.getElementById('result').innerText = 'Time is up!';
document.getElementById('score').innerText = `Correct Answers: ${correctAnswers}, Wrong Answers: ${wrongAnswers}`;
}
60 changes: 60 additions & 0 deletions Games/MathQuiz/styles.css
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
body {
font-family: Arial, sans-serif;
text-align: center;
background-color: #f0f0f0;
margin: 0;
padding: 20px;
background-image: url("https://png.pngtree.com/thumb_back/fh260/background/20200530/pngtree-cute-hand-drawn-style-mathematics-education-pink-plaid-background-image_337364.jpg");
background-repeat: no-repeat;
background-size: cover;
background-attachment: fixed;
}

#game-container {
background-color: rgba(255, 255, 255, 0.8);
border: 1px solid #ccc;
border-radius: 10px;
padding: 40px;
width: 500px;
margin: 50px auto;
box-shadow: 0 0 20px rgba(0, 0, 0, 0.2);
}

h1 {
color: #333;
}

#question {
font-size: 24px;
margin-bottom: 20px;
}

#answer {
width: 100px;
padding: 5px;
font-size: 16px;
}

button {
padding: 10px 20px;
font-size: 16px;
margin-top: 10px;
}

#result, #score, #timer {
margin-top: 20px;
font-size: 18px;
}

#instructions {
font-size: 18px;
background-color: rgba(255, 255, 255, 0.8);
border-radius: 10px;
padding: 20px;
}

#game {
background-color: rgba(255, 255, 255, 0.8);
border-radius: 10px;
padding: 20px;
}
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -187,7 +187,7 @@ This repository also provides one such platforms where contributers come over an
| [CSS Select](https://github.com/kunjgit/GameZone/tree/main/Games/CSS_Select) | [Squid](https://github.com/kunjgit/GameZone/tree/main/Games/Squid_Game) | [Flip Coin](https://github.com/kunjgit/GameZone/tree/main/Games/Flip_Coin) | [Witty Word Quest](https://github.com/kunjgit/GameZone/tree/main/Games/witty_word_quest) | [Typing Game](https://github.com/Ishan-77/GameZone/tree/main/Games/Typing_Game) |
| [numeral-whiz](https://github.com/Ishan-77/GameZone/tree/main/Games/numeral-whiz) | [candy_match](https://github.com/kunjgit/GameZone/tree/main/Games/Candy_Match_Saga) | [Crossy_Road](https://github.com/tanujbordikar/GameZone/tree/Crossy_Road) | [HueHero](https://github.com/kunjgit/GameZone/tree/main/Games/HueHero) | [Puzzel_Winner](https://github.com/kunjgit/GameZone/tree/main/Games/Puzzel_Winner) |
| [Emoji_Intruder](https://github.com/kunjgit/GameZone/tree/main/Games/Emoji_Intruder) | [Guess The Weapon](https://github.com/kunjgit/GameZone/tree/main/Games/Guess_The_Weapon) | [Guess Who](https://github.com/kunjgit/GameZone/tree/main/Games/Guess_Who) | [Pop My Balloon](https://github.com/kunjgit/GameZone/tree/main/Games/Pop_My_Balloon) | [Color_Blast](https://github.com/kunjgit/GameZone/tree/main/Games/Color_Blast) |
| [Maze_Game](https://github.com/kunjgit/GameZone/tree/main/Games/Maze_Game) | [Coloron](https://github.com/kunjgit/GameZone/tree/main/Games/Coloron) | [PenPointerFight](https://github.com/kunjgit/GameZone/tree/main/Games/PenPointerFight) |
| [Maze_Game](https://github.com/kunjgit/GameZone/tree/main/Games/Maze_Game) | [Coloron](https://github.com/kunjgit/GameZone/tree/main/Games/Coloron) | [PenPointerFight](https://github.com/kunjgit/GameZone/tree/main/Games/PenPointerFight) | [MathQuiz](https://github.com/kunjgit/GameZone/tree/main/Games/MathQuiz) |

| [Emoji_Intruder](https://github.com/kunjgit/GameZone/tree/main/Games/Emoji_Intruder) | [Guess The Weapon](https://github.com/kunjgit/GameZone/tree/main/Games/Guess_The_Weapon) | [Guess Who](https://github.com/kunjgit/GameZone/tree/main/Games/Guess_Who) | | |
| [Emoji_Intruder](https://github.com/kunjgit/GameZone/tree/main/Games/Emoji_Intruder) | [Guess The Weapon](https://github.com/kunjgit/GameZone/tree/main/Games/Guess_The_Weapon) | [Guess Who](https://github.com/kunjgit/GameZone/tree/main/Games/Guess_Who) | [Pop My Balloon](https://github.com/kunjgit/GameZone/tree/main/Games/Pop_My_Balloon) | |
Expand Down
Binary file added assets/images/MathQuiz.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
1 change: 0 additions & 1 deletion assets/js/gamesData.json
Original file line number Diff line number Diff line change
Expand Up @@ -2088,7 +2088,6 @@
"gameTitle": "Guess_The_Song",
"gameUrl": "Guess_The_Song",
"thumbnailUrl": "Guess_The_Song.png"

}

}
Expand Down
2 changes: 1 addition & 1 deletion assets/js/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ const generateLiTags = (gamesData, searchText = "") => {
const liTags = [];
searchText = searchText.trim().toLowerCase(); // Trim whitespace and convert to lowercase

for (let tagNumber = 1; tagNumber <= 416; tagNumber++) {
for (let tagNumber = 1; tagNumber <= 417; tagNumber++) {
const gameData = gamesData[tagNumber.toString()];

if (gameData) {
Expand Down

0 comments on commit 08d7901

Please sign in to comment.