From 7e59c99a3e59439b100f61e0aadf5d78b577d8d4 Mon Sep 17 00:00:00 2001 From: AndreRibeiro24 Date: Thu, 26 Mar 2026 20:45:13 +0000 Subject: [PATCH 1/8] Day 1 --- src/question.js | 18 ++++++++++++++++-- src/quiz.js | 42 +++++++++++++++++++++++++++++++++++------- 2 files changed, 51 insertions(+), 9 deletions(-) diff --git a/src/question.js b/src/question.js index 68f6631a..46993718 100644 --- a/src/question.js +++ b/src/question.js @@ -2,6 +2,20 @@ class Question { // YOUR CODE HERE: // // 1. constructor (text, choices, answer, difficulty) + constructor(text,choices,answer,difficulty){ + this.text = text + this.choices = choices + this.answer = answer + this.difficulty = difficulty + } + shuffleChoices(){ + let randomChoice = []; + for(let i = this.choices.length - 1; i > 0; i-- ){ + const randomizer = Math.floor(Math.random()* (i+1)); + randomChoice.push([this.choices[i], this.choices[randomizer]] = [this.choices[randomizer], this.choices[i]]) + } + return randomChoice; + } +} - // 2. shuffleChoices() -} \ No newline at end of file +// Done for now \ No newline at end of file diff --git a/src/quiz.js b/src/quiz.js index d94cfd14..d950f5f0 100644 --- a/src/quiz.js +++ b/src/quiz.js @@ -1,15 +1,43 @@ class Quiz { // YOUR CODE HERE: // - // 1. constructor (questions, timeLimit, timeRemaining) - - // 2. getQuestion() + constructor (questions, timeLimit, timeRemaining){ + this.questions = questions + this.timeLimit = timeLimit + this.timeRemaining = timeRemaining + this.correctAnswers = 0 + this.currentQuestionIndex = 0 + } + + getQuestion(){ + return this.questions[this.currentQuestionIndex]; + } - // 3. moveToNextQuestion() + moveToNextQuestion(){ + return this.currentQuestionIndex += 1; + } + + shuffleQuestions(){ + let randomQuestion = []; + for(let i=this.questions.length - 1; i > 0; i--){ + const randomizer = Math.floor(Math.random()*(i+1)); + randomQuestion.push([this.questions[i],this.questions[randomizer]]=[this.questions[randomizer],this.questions[i]]) + } + return randomQuestion; + } - // 4. shuffleQuestions() + checkAnswer(answer){ + if(answer === this.getQuestion().answer){ + this.correctAnswers += 1; + } + } - // 5. checkAnswer(answer) + hasEnded(){ + if(this.currentQuestionIndex < this.questions.length){ + return false + }else if (this.currentQuestionIndex === this.questions.length){ + return true + } - // 6. hasEnded() + } } \ No newline at end of file From b8cb49055b1ececff952e5944fbba9cd7f5fd80a Mon Sep 17 00:00:00 2001 From: AndreRibeiro24 Date: Sat, 28 Mar 2026 15:48:23 +0000 Subject: [PATCH 2/8] Day2 --- src/quiz.js | 25 ++++++++++++++++++++++++- 1 file changed, 24 insertions(+), 1 deletion(-) diff --git a/src/quiz.js b/src/quiz.js index d950f5f0..dac55c10 100644 --- a/src/quiz.js +++ b/src/quiz.js @@ -40,4 +40,27 @@ class Quiz { } } -} \ No newline at end of file + + filterQuestionsByDifficulty(difficulty){ + + if (typeof difficulty !== "number" || difficulty < 1 || difficulty > 3) { + return; + } + + this.questions = this.questions.filter( + question => question.difficulty === difficulty + ); + } + + + averageDifficulty(){ + + const sum = this.questions.reduce((acc, question) =>{ + return acc + question.difficulty; + + },0); + return sum/ this.questions.length + + } + +} From ca1af5df54653769f7f1e076b57c06e7a9bf4d47 Mon Sep 17 00:00:00 2001 From: AndreRibeiro24 Date: Thu, 2 Apr 2026 20:32:31 +0100 Subject: [PATCH 3/8] day 3 --- index.html | 6 ++++-- src/index.js | 20 +++++++++++++++----- 2 files changed, 19 insertions(+), 7 deletions(-) diff --git a/index.html b/index.html index 534cd886..b36080ba 100644 --- a/index.html +++ b/index.html @@ -21,7 +21,9 @@

JavaScript Quiz

-
    +
      + +
    Remaining Time: 00:00
    @@ -33,7 +35,7 @@

    JavaScript Quiz

    - + answer

    Results

    diff --git a/src/index.js b/src/index.js index 03737ba3..b00371eb 100644 --- a/src/index.js +++ b/src/index.js @@ -98,23 +98,33 @@ document.addEventListener("DOMContentLoaded", () => { // // 1. Show the question // Update the inner text of the question container element and show the question text - + questionContainer.innerText = question.text // 2. Update the green progress bar // Update the green progress bar (div#progressBar) width so that it shows the percentage of questions answered - - progressBar.style.width = `65%`; // This value is hardcoded as a placeholder + const progressPercent = ((quiz.currentQuestionIndex + 1) / quiz.questions.length) * 100; + progressBar.style.width = progressPercent + "%"; // This value is hardcoded as a placeholder // 3. Update the question count text // Update the question count (div#questionCount) show the current question out of total questions - - questionCount.innerText = `Question 1 of 10`; // This value is hardcoded as a placeholder + const currentQuest = quiz.currentQuestionIndex + 1; + questionCount.innerText =`${currentQuest} out of ${quiz.questions.length}`; // This value is hardcoded as a placeholder // 4. Create and display new radio input element with a label for each choice. + const choicess = quiz.choices + choicess.forEach(element => { + newLi.innerHTML = ` +
  • ${element}
  • + + ` + CONTENT.appendChild(newLi) + + + }); // Loop through the current question `choices`. // For each choice create a new radio input with a label, and append it to the choice container. // Each choice should be displayed as a radio input element with a label: From 2beaa5796ce3c2c836422c3b9702b9ebc1d8072f Mon Sep 17 00:00:00 2001 From: AndreRibeiro24 Date: Mon, 6 Apr 2026 18:01:47 +0100 Subject: [PATCH 4/8] changes day 3 --- index.html | 6 +-- src/index.js | 102 +++++++++++++++++++++++++++++++-------------------- 2 files changed, 66 insertions(+), 42 deletions(-) diff --git a/index.html b/index.html index b36080ba..bb59dda3 100644 --- a/index.html +++ b/index.html @@ -35,13 +35,13 @@

    JavaScript Quiz

    - answer +

    Results

    - - + +
    diff --git a/src/index.js b/src/index.js index b00371eb..eedd4395 100644 --- a/src/index.js +++ b/src/index.js @@ -115,16 +115,18 @@ document.addEventListener("DOMContentLoaded", () => { // 4. Create and display new radio input element with a label for each choice. - const choicess = quiz.choices - choicess.forEach(element => { - newLi.innerHTML = ` -
  • ${element}
  • - - ` - CONTENT.appendChild(newLi) - - + question.choices.forEach((choice) => { + const li = document.createElement("li"); + li.innerHTML = ` + + +
    + ` + choiceContainer.appendChild(li); }); + } + + // 4. Create and display new radio input element with a label for each choice. // Loop through the current question `choices`. // For each choice create a new radio input with a label, and append it to the choice container. // Each choice should be displayed as a radio input element with a label: @@ -132,53 +134,75 @@ document.addEventListener("DOMContentLoaded", () => {
    - */ // Hint 1: You can use the `document.createElement()` method to create a new element. // Hint 2: You can use the `element.type`, `element.name`, and `element.value` properties to set the type, name, and value of an element. // Hint 3: You can use the `element.appendChild()` method to append an element to the choices container. // Hint 4: You can use the `element.innerText` property to set the inner text of an element. - } - - - + */ function nextButtonHandler () { let selectedAnswer; // A variable to store the selected answer value + let choices = document.querySelectorAll("input[name='choice']"); + choices.forEach((element) => { - - // YOUR CODE HERE: - // - // 1. Get all the choice elements. You can use the `document.querySelectorAll()` method. - - - // 2. Loop through all the choice elements and check which one is selected - // Hint: Radio input elements have a property `.checked` (e.g., `element.checked`). - // When a radio input gets selected the `.checked` property will be set to true. - // You can use check which choice was selected by checking if the `.checked` property is true. + if (element.checked === true){ + selectedAnswer = element.value; + } - // 3. If an answer is selected (`selectedAnswer`), check if it is correct and move to the next question - // Check if selected answer is correct by calling the quiz method `checkAnswer()` with the selected answer. - // Move to the next question by calling the quiz method `moveToNextQuestion()`. - // Show the next question by calling the function `showQuestion()`. - } - - - - + }); + if(selectedAnswer){ + quiz.checkAnswer(selectedAnswer); + quiz.moveToNextQuestion(); + showQuestion(); + } + } function showResults() { - - // YOUR CODE HERE: - // - // 1. Hide the quiz view (div#quizView) + + quizView.style.display = "none"; // 2. Show the end view (div#endView) endView.style.display = "flex"; // 3. Update the result container (div#result) inner text to show the number of correct answers out of total questions - resultContainer.innerText = `You scored 1 out of 1 correct answers!`; // This value is hardcoded as a placeholder + resultContainer.innerText = `You scored ${quiz.correctAnswers} out of ${quiz.questions.length} correct answers!`; // This value is hardcoded as a placeholder } -}); \ No newline at end of file +// Restart button +const RestarButtonElement = document.querySelector("#restartButton"); +RestarButtonElement.addEventListener('click', ()=>{ + endView.style.display = "none" + quizView.style.display = "flex"; + + quiz.currentQuestionIndex = 0; + quiz.correctAnswers = 0; + const progressPercent = ((quiz.currentQuestionIndex + 1) / quiz.questions.length) * 100; + progressBar.style.width = progressPercent + "%"; + const currentQuest = quiz.currentQuestionIndex + 1; + questionCount.innerText =`${currentQuest} out of ${quiz.questions.length}`; + quiz.shuffleQuestions(); + quiz.getQuestion(quiz.currentQuestionIndex); + + +}) +//add timer +// const interval = setInterval(() => { +// if (quiz.timeRemaining <= 0){ +// clearInterval(interval); +// showResults(); +// return; +// } +// quiz.timeRemaining--; + +// const minutes = Math.floor(quiz.timeRemaining / 60).toString().padStart(2, "0"); +// const seconds = (quiz.timeRemaining % 60).toString().padStart(2, "0"); +// timeRemainingContainer.innerText = `Remaining time: ${minutes}:${seconds}`; +// }, 1000); + + + +/*end of line*/}); + + From ed0a8555d98bd4c0d263c8fa8a1b0c0cd66e85d7 Mon Sep 17 00:00:00 2001 From: AndreRibeiro24 Date: Mon, 6 Apr 2026 19:24:21 +0100 Subject: [PATCH 5/8] day 4 uncompleted --- index.html | 2 +- src/index.js | 33 +++++++++++++++++---------------- 2 files changed, 18 insertions(+), 17 deletions(-) diff --git a/index.html b/index.html index bb59dda3..769da563 100644 --- a/index.html +++ b/index.html @@ -25,7 +25,7 @@

    JavaScript Quiz

    -
    Remaining Time: 00:00
    +
    Remaining Time: 00:00
    diff --git a/src/index.js b/src/index.js index eedd4395..09361f82 100644 --- a/src/index.js +++ b/src/index.js @@ -185,24 +185,25 @@ RestarButtonElement.addEventListener('click', ()=>{ quiz.shuffleQuestions(); quiz.getQuestion(quiz.currentQuestionIndex); - + quizDuration = 120; + const minutes = Math.floor(quiz.timeRemaining / 60).toString().padStart(2, "0"); + const seconds = (quiz.timeRemaining % 60).toString().padStart(2, "0"); + timeRemainingContainer.innerHTML = `${minutes}:${seconds}` }) -//add timer -// const interval = setInterval(() => { -// if (quiz.timeRemaining <= 0){ -// clearInterval(interval); -// showResults(); -// return; -// } -// quiz.timeRemaining--; - -// const minutes = Math.floor(quiz.timeRemaining / 60).toString().padStart(2, "0"); -// const seconds = (quiz.timeRemaining % 60).toString().padStart(2, "0"); -// timeRemainingContainer.innerText = `Remaining time: ${minutes}:${seconds}`; -// }, 1000); - - +//Timer building +const timerInterval = setInterval(() => { + if(quiz.timeRemaining <= 0){ + clearInterval(timerInterval); + showResults(); + return; + } + quiz.timeRemaining--; + const minutes = Math.floor(quiz.timeRemaining / 60).toString().padStart(2, "0"); + const seconds = (quiz.timeRemaining % 60).toString().padStart(2, "0"); + timeRemainingContainer.innerHTML = `${minutes}:${seconds}` + +}, 1000); /*end of line*/}); From 8893d33e6bf3162592cd5174888d9391e78e86e2 Mon Sep 17 00:00:00 2001 From: AndreRibeiro24 Date: Mon, 6 Apr 2026 19:39:47 +0100 Subject: [PATCH 6/8] updated day 4 --- src/index.js | 9 +++------ 1 file changed, 3 insertions(+), 6 deletions(-) diff --git a/src/index.js b/src/index.js index 09361f82..9f055d82 100644 --- a/src/index.js +++ b/src/index.js @@ -184,12 +184,9 @@ RestarButtonElement.addEventListener('click', ()=>{ questionCount.innerText =`${currentQuest} out of ${quiz.questions.length}`; quiz.shuffleQuestions(); quiz.getQuestion(quiz.currentQuestionIndex); - - quizDuration = 120; - const minutes = Math.floor(quiz.timeRemaining / 60).toString().padStart(2, "0"); - const seconds = (quiz.timeRemaining % 60).toString().padStart(2, "0"); - timeRemainingContainer.innerHTML = `${minutes}:${seconds}` -}) +// ONLY THING REMAINING, to RESTART TIMER WHEN QUIZ IS RESTARTED + //quiz.timeRemaining = timerInterval; + }) //Timer building const timerInterval = setInterval(() => { From e06d064dff3a8ae909ef8afb774a69d0f100320f Mon Sep 17 00:00:00 2001 From: AndreRibeiro24 Date: Mon, 6 Apr 2026 20:10:32 +0100 Subject: [PATCH 7/8] final change quiz project --- src/index.js | 23 ++++++++++++++++++++++- 1 file changed, 22 insertions(+), 1 deletion(-) diff --git a/src/index.js b/src/index.js index 9f055d82..6a96d779 100644 --- a/src/index.js +++ b/src/index.js @@ -186,10 +186,11 @@ RestarButtonElement.addEventListener('click', ()=>{ quiz.getQuestion(quiz.currentQuestionIndex); // ONLY THING REMAINING, to RESTART TIMER WHEN QUIZ IS RESTARTED //quiz.timeRemaining = timerInterval; + startTimer(); }) //Timer building -const timerInterval = setInterval(() => { +let timerInterval = setInterval(() => { if(quiz.timeRemaining <= 0){ clearInterval(timerInterval); showResults(); @@ -201,6 +202,26 @@ const timerInterval = setInterval(() => { timeRemainingContainer.innerHTML = `${minutes}:${seconds}` }, 1000); +//Reseting the timer +const INITIAL_TIME = quiz.timeRemaining; +let timerRestart = null; + +function startTimer() { + // clear any existing timer ----- Ask Daniel why is it dropping seconds quickly ---------------// + quiz.timeRemaining = quizDuration; // reset time + + timerRestart = setInterval(() => { + if (quiz.timeRemaining <= 0) { + clearInterval(timerRestart); + showResults(); + return; + } + quiz.timeRemaining--; + const minutes = Math.floor(quiz.timeRemaining / 60).toString().padStart(2, "0"); + const seconds = (quiz.timeRemaining % 60).toString().padStart(2, "0"); + timeRemainingContainer.innerHTML = `${minutes}:${seconds}`; + }, 1000); +} /*end of line*/}); From 207e3383343ed5da306339da2a30068f2c939e5c Mon Sep 17 00:00:00 2001 From: AndreRibeiro24 Date: Tue, 7 Apr 2026 19:28:47 +0100 Subject: [PATCH 8/8] final changes day 5 --- src/index.js | 21 +++------------------ 1 file changed, 3 insertions(+), 18 deletions(-) diff --git a/src/index.js b/src/index.js index 6a96d779..dcb19288 100644 --- a/src/index.js +++ b/src/index.js @@ -186,7 +186,7 @@ RestarButtonElement.addEventListener('click', ()=>{ quiz.getQuestion(quiz.currentQuestionIndex); // ONLY THING REMAINING, to RESTART TIMER WHEN QUIZ IS RESTARTED //quiz.timeRemaining = timerInterval; - startTimer(); + restartTimer(); }) //Timer building @@ -203,24 +203,9 @@ let timerInterval = setInterval(() => { }, 1000); //Reseting the timer -const INITIAL_TIME = quiz.timeRemaining; -let timerRestart = null; +function restartTimer(){ + quiz.timeRemaining = quizDuration; -function startTimer() { - // clear any existing timer ----- Ask Daniel why is it dropping seconds quickly ---------------// - quiz.timeRemaining = quizDuration; // reset time - - timerRestart = setInterval(() => { - if (quiz.timeRemaining <= 0) { - clearInterval(timerRestart); - showResults(); - return; - } - quiz.timeRemaining--; - const minutes = Math.floor(quiz.timeRemaining / 60).toString().padStart(2, "0"); - const seconds = (quiz.timeRemaining % 60).toString().padStart(2, "0"); - timeRemainingContainer.innerHTML = `${minutes}:${seconds}`; - }, 1000); } /*end of line*/});