Skip to content

Commit

Permalink
wip
Browse files Browse the repository at this point in the history
  • Loading branch information
acharneski committed May 16, 2024
1 parent bd5c810 commit b2741ec
Show file tree
Hide file tree
Showing 4 changed files with 48 additions and 3 deletions.
Binary file added math_practice_1/button.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
18 changes: 16 additions & 2 deletions math_practice_1/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ document.addEventListener('DOMContentLoaded', (event) => {

let currentQuestion = {};
let score = 0;
let difficulty = 'easy'; // Default difficulty level
let difficulty = loadSettings().difficulty; // Load difficulty from settings

// Initialize the game
function initGame() {
Expand Down Expand Up @@ -94,7 +94,7 @@ function createQuestion(difficulty) {
// Check the user's answer
function checkAnswer(selectedAnswer) {
const feedbackElement = document.getElementById('feedback-message');
if (selectedAnswer === currentQuestion.correctAnswer) {
if (selectedAnswer == currentQuestion.correctAnswer) { // Use == for type coercion
score++;
feedbackElement.innerText = 'Correct!';
} else {
Expand All @@ -110,4 +110,18 @@ function checkAnswer(selectedAnswer) {
// Get a random integer between min (inclusive) and max (inclusive)
function getRandomInt(min, max) {
return Math.floor(Math.random() * (max - min + 1)) + min;
}

// Load settings from local storage
function loadSettings() {
const settings = localStorage.getItem('gameSettings');
if (settings) {
return JSON.parse(settings);
} else {
// Default settings
return {
difficulty: 'easy',
sound: true
};
}
}
14 changes: 13 additions & 1 deletion math_practice_1/settings.html
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,15 @@
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Game Settings</title>
<title>Settings</title>
<link rel="stylesheet" href="styles.css">
<script src="settings.js" defer></script>
</head>
<body>
<h1>Settings</h1>
<form id="settings-form" class="settings">
<label for="difficulty">Difficulty:</label>
<select id="difficulty" name="difficulty">
<div class="settings-container">
<h1>Game Settings</h1>

Expand All @@ -17,6 +22,13 @@ <h1>Game Settings</h1>
<option value="medium">Medium</option>
<option value="hard">Hard</option>
</select>
<br>
<label for="sound">Sound:</label>
<input type="checkbox" id="sound" name="sound">
<br>
<button type="submit">Save Settings</button>
</form>
<button onclick="window.location.href='index.html'">Back to Game</button>
</div>

<div class="setting-option">
Expand Down
19 changes: 19 additions & 0 deletions math_practice_1/styles.css
Original file line number Diff line number Diff line change
Expand Up @@ -105,4 +105,23 @@ body {

.instructions button, .settings button {
margin-top: 20px;
}

/* Settings Form */
#settings-form {
display: flex;
flex-direction: column;
align-items: flex-start;
}

#settings-form label {
margin-bottom: 10px;
}

#settings-form select, #settings-form input {
margin-bottom: 20px;
}

#settings-form button {
align-self: center;
}

0 comments on commit b2741ec

Please sign in to comment.