Skip to content

Commit

Permalink
fix additional timer issue, rename data file to fit convention
Browse files Browse the repository at this point in the history
rbozek committed Jan 4, 2024
1 parent 4e22f12 commit 03c06c8
Showing 4 changed files with 19 additions and 12 deletions.
2 changes: 1 addition & 1 deletion css/style.css
Original file line number Diff line number Diff line change
@@ -36,6 +36,6 @@ div#countdown {
}

div#player-score {
background-color: rgb(255, 160, 66);
background-color: rgb(66, 255, 211);
}

20 changes: 13 additions & 7 deletions js/app.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
// console.log('overall test!');

/*------------ Constants ------------*/
import { questionsImportCat1, questionsImportCat2, questionsImportCat3 } from "../js/questions.js"
import { questionsImportCat1, questionsImportCat2, questionsImportCat3 } from "../js/data.js"
const questionsCat1 = Object.values(questionsImportCat1);
const questionsCat2 = Object.values(questionsImportCat2);
const questionsCat3 = Object.values(questionsImportCat3);
@@ -12,7 +12,6 @@ let playerScore = 0 // can reset in init or render
let currentQuesIdx = 0
let currQuesCorrAnsIdx // for playerChooseAnswer
let currentCategory // to fix problem in renderQUestion & playerCHoice
let timeLeft = 80 // TIMER
let timerSeconds, timerInterval

/*---- Cached Element References ----*/
@@ -27,6 +26,7 @@ const playerScoreContainer = document.getElementById("player-score")
let initialScoreState = playerScoreContainer.innerHTML = `score`
const countdown = document.getElementById("countdown") // TIMER


/*--------- Event Listeners ---------*/
btnCategory1.addEventListener('click', renderQuestionCat1)
btnCategory1.addEventListener('click', startTimer) // TIMER
@@ -41,17 +41,23 @@ btnReset.addEventListener('click', resetGame)

function startTimer() {
// Reset the timer
timerSeconds = 80;
timerSeconds = 5
// Set up the interval to update the timer every second
timerInterval = setInterval(updateTimer, 1000);
timerInterval = setInterval(updateTimer, 1000)
}
function updateTimer() {
countdown.textContent = `Time: ${timerSeconds}s`;
timerSeconds -= 1;
countdown.textContent = `Time: ${timerSeconds}s`
timerSeconds -= 1
if (timerSeconds < 0) {
countdown.textContent = `Out of time!`
roundOver()
question.textContent = ''
answers.innerHTML = ''
}
}
function stopTimer() {
// Clear the interval to stop the timer
clearInterval(timerInterval);
clearInterval(timerInterval)
}

function renderQuestionCat1() {
File renamed without changes.
9 changes: 5 additions & 4 deletions js/pseudocode.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@


// //next:
// // move questions into app.js (big array of objects, each object k:v pairs)
// // CATEGORIES - separate question array for each (category1, category 2, etc)
@@ -16,7 +14,6 @@
// // move for loop to update global variable
// // get LI's clickable / - event listener for those


// // finish function for chooseAnswer - that's where we'll use conditional to see if it matches "true" from quesAs?
// // update playerScore - compare playerChoice with correctAnswer, if === then add points, else then nothing
// // & display playerScore
@@ -39,8 +36,12 @@
// color scheme: warm colors

// IF I HAVE TIME
// clearing Q's and A's - diditn mess with it for fear of breaking it - but see if i can display.none instead of innerHTML (but might make a mess with reest? idk)
// seaprate "rules" & "buttons" - when user starts, everything disappears, but after a reset, only buttons re-appear
// add conditional - if player got a perfect score, play hidden sound (or display hidden image)
// perfect score make more exciting - if player perfect score, hidden image or page






0 comments on commit 03c06c8

Please sign in to comment.