-
Notifications
You must be signed in to change notification settings - Fork 839
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #4067 from bhumika-1127/mathQuiz
math quiz wrt #4063
- Loading branch information
Showing
8 changed files
with
204 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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"> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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}`; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters