- Notifications
You must be signed in to change notification settings - Fork656
Scoring system#40
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to ourterms of service andprivacy statement. We’ll occasionally send you account related emails.
Already on GitHub?Sign in to your account
Open
JasperBoller wants to merge2 commits intojamesqquick:masterChoose a base branch fromJasperBoller:scoring-system
base:master
Could not load branches
Branch not found:{{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline, and old review comments may become outdated.
Uh oh!
There was an error while loading.Please reload this page.
Open
Changes fromall commits
Commits
Show all changes
2 commits Select commitHold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Uh oh!
There was an error while loading.Please reload this page.
Jump to
Jump to file
Failed to load files.
Loading
Uh oh!
There was an error while loading.Please reload this page.
Diff view
Diff view
There are no files selected for viewing
47 changes: 47 additions & 0 deletionsQuiz App Master/app.css
This file contains hidden or 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
125 changes: 103 additions & 22 deletionsQuiz App Master/end.html
This file contains hidden or 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
65 changes: 53 additions & 12 deletionsQuiz App Master/end.js
This file contains hidden or 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 |
---|---|---|
@@ -1,29 +1,70 @@ | ||
// DOM Elements | ||
const finalScore = document.getElementById('finalScore'); | ||
const correctAnswersEl = document.getElementById('correctAnswers'); | ||
const totalQuestionsEl = document.getElementById('totalQuestions'); | ||
const percentageScoreEl = document.getElementById('percentageScore'); | ||
const feedbackMessage = document.getElementById('feedbackMessage'); | ||
const usernameInput = document.getElementById('username'); | ||
const saveScoreBtn = document.getElementById('saveScoreBtn'); | ||
const saveScoreForm = document.getElementById('saveScoreForm'); | ||
// Get results from localStorage | ||
const mostRecentScore = localStorage.getItem('mostRecentScore'); | ||
const correctAnswers = localStorage.getItem('correctAnswers'); | ||
const totalQuestions = localStorage.getItem('totalQuestions'); | ||
const percentageScore = localStorage.getItem('percentageScore'); | ||
// High Scores | ||
const highScores = JSON.parse(localStorage.getItem('highScores')) || []; | ||
const MAX_HIGH_SCORES = 5; | ||
// Display results | ||
finalScore.innerText = mostRecentScore; | ||
correctAnswersEl.innerText = correctAnswers; | ||
totalQuestionsEl.innerText = totalQuestions; | ||
percentageScoreEl.innerText = percentageScore; | ||
// Add feedback based on percentage | ||
const percentage = parseInt(percentageScore); | ||
if (percentage >= 90) { | ||
feedbackMessage.innerText = "Excellent! 🎉"; | ||
} else if (percentage >= 70) { | ||
feedbackMessage.innerText = "Good job! 👍"; | ||
} else if (percentage >= 50) { | ||
feedbackMessage.innerText = "Not bad! 😊"; | ||
} else { | ||
feedbackMessage.innerText = "Keep practicing! 💪"; | ||
} | ||
// Enable save button when username is entered | ||
usernameInput.addEventListener('keyup', () => { | ||
saveScoreBtn.disabled = !usernameInput.value; | ||
}); | ||
// Save high score | ||
saveScoreForm.addEventListener('submit', (e) => { | ||
e.preventDefault(); | ||
const score = { | ||
score: mostRecentScore, | ||
correctAnswers: correctAnswers, | ||
totalQuestions: totalQuestions, | ||
percentage: percentageScore, | ||
name: usernameInput.value, | ||
date: new Date().toLocaleDateString() | ||
}; | ||
highScores.push(score); | ||
highScores.sort((a, b) => b.score - a.score); | ||
highScores.splice(MAX_HIGH_SCORES); | ||
localStorage.setItem('highScores', JSON.stringify(highScores)); | ||
// Disable form after submission | ||
usernameInput.disabled = true; | ||
saveScoreBtn.disabled = true; | ||
// Show confirmation | ||
feedbackMessage.textContent = `Score saved for ${usernameInput.value}!`; | ||
feedbackMessage.style.color = "#4CAF50"; | ||
}); |
1 change: 1 addition & 0 deletionsQuiz App Master/game.html
This file contains hidden or 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 |
---|---|---|
@@ -49,6 +49,7 @@ <h2 id="question"></h2> | ||
</div> | ||
</div> | ||
</div> | ||
<script src="game.js"></script> | ||
</body> | ||
</html> |
Oops, something went wrong.
Uh oh!
There was an error while loading.Please reload this page.
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.