Skip to content

Commit

Permalink
Merge pull request #47 from dbeigi/display-score
Browse files Browse the repository at this point in the history
fixed #42 display score added
  • Loading branch information
Arcaster42 committed Nov 1, 2019
2 parents f875db5 + bb0887e commit 07377a7
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 1 deletion.
11 changes: 10 additions & 1 deletion src/js/game_logic.js
Expand Up @@ -22,12 +22,16 @@ let incorrectGuesses = 0
let timeRemaining = playTimeSeconds
let cardNumber = 1
let correctGuesses = 0
let totalCorrect = 0
let totalWrong = 0


//HTML elements
const cardBlock = document.getElementById('rhyme_card')
const countElement = document.getElementById('rhyme_count')
const rhymeElement = document.getElementById('rhyme')
const correctElement = document.getElementById('correct')
const incorrectElement = document.getElementById('wrong')
const guessElement = document.getElementById('rhyme_guess')
const wrongElement = document.getElementById('incorrect')
const hint = document.getElementById('hint')
Expand Down Expand Up @@ -86,10 +90,12 @@ const updateDisplay = () => {
const checkAnswer = () => {
if (guessElement.value === Game.currentCard.answer) {
correctAnswer()
totalCorrect++
} else if (guessElement.value === '' || undefined) {
alert('Please enter a guess!')
} else {
incorrectAnswer()
totalWrong++
}
}

Expand Down Expand Up @@ -142,6 +148,8 @@ const gameOver = () => {
timerDisplay.classList.remove('running')
timerDisplay.classList.add('gameover')
rhymeElement.textContent = 'Game Over!'
correctElement.textContent = 'Correct guesses: ' + totalCorrect
incorrectElement.textContent = 'Incorrect guesses: ' + totalWrong
timerDisplay.style.setProperty('background', 'var(--danger)')
cardBlock.style.setProperty('background', 'var(--danger)')
hint.style.display = 'none';
Expand All @@ -161,7 +169,8 @@ const restartGame = () => {
timerDisplay.classList.remove('gameover')
timerDisplay.style.setProperty('background', 'var(--primary-gradient)')
cardBlock.style.setProperty('background', 'var(--primary-gradient)')

correctElement.textContent = ''
incorrectElement.textContent = ''
guessElement.addEventListener('keydown', assignListeners)
shufflePuzzles(puzzles)
loadCard(puzzles[0])
Expand Down
2 changes: 2 additions & 0 deletions src/views/main.html
Expand Up @@ -22,6 +22,8 @@
<div class="rhyme_count" id="rhyme_count"><span></span></div>
</div>
<p class="rhyme" id="rhyme"></p>
<p class="rhyme" id="correct"></p>
<p class="rhyme" id="wrong"></p>
<div class="card_info_outer center">
<div id="hint" class="center"></div>
<div class="card_info center">
Expand Down

0 comments on commit 07377a7

Please sign in to comment.