07.10.2026 - QuizStart with Search
This commit is contained in:
@@ -0,0 +1,21 @@
|
||||
class Student{
|
||||
constructor(firstName, lastName, age)
|
||||
{
|
||||
this.firstName = firstName;
|
||||
this.lastName = lastName;
|
||||
this.age = age;
|
||||
}
|
||||
|
||||
greeting() {
|
||||
console.log(`Hi, my name is ${this.firstName} ${this.lastName}. I'm ${this.age} years old.`);
|
||||
|
||||
};
|
||||
};
|
||||
|
||||
const jonny = new Student("Jonny", "Hilbert", 22);
|
||||
const lisa = new Student("Lisa", "Lauser", 41);
|
||||
|
||||
|
||||
|
||||
jonny.greeting();
|
||||
lisa.greeting();
|
||||
@@ -29,18 +29,18 @@ function shuffleArray(questionArray)
|
||||
{
|
||||
rng = getRandomNumber(questionArray.length);
|
||||
}
|
||||
while(newArray.includes(rng));
|
||||
newArray[i] = rng;
|
||||
while(newArray.includes(questionArray[rng]));
|
||||
newArray[i] = questionArray[rng]
|
||||
}
|
||||
|
||||
newArray.forEach((value, index) => {
|
||||
newArray[index] = questionArray[value];
|
||||
});
|
||||
|
||||
|
||||
return newArray;
|
||||
}
|
||||
|
||||
function getRandomNumber(maxValue){
|
||||
let val = Math.floor(Math.random() * maxValue)
|
||||
if(val >= maxValue)
|
||||
getRandomNumber(maxValue);
|
||||
|
||||
return Math.floor(Math.random() * maxValue);
|
||||
}
|
||||
|
||||
@@ -57,11 +57,11 @@ function resetQuiz(){
|
||||
|
||||
function showQuestions() {
|
||||
|
||||
questions = shuffleArray(questions);
|
||||
shuffledQuestions = shuffleArray(questions);
|
||||
|
||||
|
||||
let btn = document.getElementById("resultBtn");
|
||||
if (currentQuestionIndex >= questions.length) {
|
||||
if (currentQuestionIndex >= shuffledQuestions.length) {
|
||||
document.getElementById("quiz-container").hidden = true;
|
||||
document.getElementById("result").hidden = false;
|
||||
document.getElementById("score").textContent = score;
|
||||
@@ -70,18 +70,18 @@ function showQuestions() {
|
||||
return;
|
||||
}
|
||||
|
||||
let question = questions[currentQuestionIndex];
|
||||
let currentQuestion = shuffledQuestions[currentQuestionIndex];
|
||||
|
||||
|
||||
document.getElementById("question").textContent = question.question;
|
||||
document.getElementById("question").textContent = currentQuestion.question;
|
||||
|
||||
let answersDiv = document.getElementById("answers");
|
||||
answersDiv.innerHTML = "";
|
||||
|
||||
question.answers.forEach((answer, index ) => {
|
||||
currentQuestion.answers.forEach((answer, index ) => {
|
||||
let answerBtn = document.createElement("button");
|
||||
answerBtn.textContent = answer;
|
||||
answerBtn.onclick = () => checkAnswer(index, question.correctAnswer);
|
||||
answerBtn.onclick = () => checkAnswer(index, currentQuestion.correctAnswer);
|
||||
answersDiv.appendChild(answerBtn);
|
||||
});
|
||||
|
||||
|
||||
Reference in New Issue
Block a user