In modern education, online quizzes have become a common method of learning. Multiple-choice questions, as one of the question types, are an effective way to assess students' knowledge. This article will use code examples to demonstrate how to implement multiple-choice questions in online quizzes.
First, we need to create a simple webpage interface for students to answer questions. Here’s a simple HTML code example:
for (var i = 0; i < checkboxes.length; i++) {
if (checkboxes[i].checked) {
userAnswer.push(checkboxes[i].value);
}
}
// Compare user answers with correct answers
var isCorrect = userAnswer.length === correctAnswer.length && userAnswer.every((value, index) => value === correctAnswer[index]);
if (isCorrect) {
alert("Correct Answer!");
} else {
alert("Incorrect Answer!");
}
// Additional operations, such as score calculation, can be added here
}
</script>