From 9fcd1fc34950f587d6106cb9c84259364fcda05f Mon Sep 17 00:00:00 2001 From: JINAL RAVAL Date: Mon, 27 Jul 2026 16:43:46 +0100 Subject: [PATCH] Day 1- Solved --- src/question.js | 20 +++++++++++++++++--- src/quiz.js | 40 ++++++++++++++++++++++++++++++++-------- 2 files changed, 49 insertions(+), 11 deletions(-) diff --git a/src/question.js b/src/question.js index 68f6631a..a27445a2 100644 --- a/src/question.js +++ b/src/question.js @@ -1,7 +1,21 @@ 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() { + + for (let i = this.choices.length - 1; i > 0; i--){ + const j = Math.floor(Math.random() * (i + 1)); + [this.choices[i], this.choices[j] = [this.choices[j], this.choices[i]]]; + } + return this.choices; + + } - // 2. shuffleChoices() } \ No newline at end of file diff --git a/src/quiz.js b/src/quiz.js index d94cfd14..9c37fc62 100644 --- a/src/quiz.js +++ b/src/quiz.js @@ -1,15 +1,39 @@ class Quiz { - // YOUR CODE HERE: - // - // 1. constructor (questions, timeLimit, timeRemaining) + + constructor (questions, timeLimit, timeRemaining) { + this.questions = questions; + this.timeLimit = timeLimit; + this.timeRemaining = timeRemaining; + this.correctAnswers = 0; + this.currentQuestionIndex = 0; + } - // 2. getQuestion() + getQuestion() { + return this.questions[this.currentQuestionIndex]; + } - // 3. moveToNextQuestion() + moveToNextQuestion() { + return this.currentQuestionIndex++; + } + + shuffleQuestions() { + for (let i = this.questions.length - 1; i > 0; i--) { + const j = Math.floor(Math.random() * (i + 1)); + + [this.questions[i], this.questions[j]] = [this.questions[j], this.questions[i] ] + } + return this.questions; + } - // 4. shuffleQuestions() + checkAnswer(answer) { + if (answer === this.getQuestion().answer) { + this.correctAnswers++; - // 5. checkAnswer(answer) + } + + } - // 6. hasEnded() + hasEnded() { + return this.currentQuestionIndex >= this.questions.length; + } } \ No newline at end of file