Added Check Choice question type

This commit is contained in:
Mawoka
2023-05-24 21:40:53 +02:00
parent d713f76d0a
commit c6dc71b941
13 changed files with 164 additions and 68 deletions
@@ -6,10 +6,11 @@
<script lang="ts">
import { QuizQuestionType } from '$lib/quiz_types';
import { getLocalization } from '$lib/i18n';
import type { Question } from '$lib/quiz_types';
const { t } = getLocalization();
export let question;
export let question: Question;
interface Answer {
username: string;
@@ -24,8 +25,23 @@
const get_answer_count_for_answer = (answer: string): number => {
let count = 0;
for (const a of answers) {
if (a.answer === answer) {
let answer_id = 0;
if (question.type === QuizQuestionType.CHECK) {
for (let i = 0; i < question.answers.length; i++) {
if (answer === question.answers[i].answer) {
answer_id = i;
break;
}
}
}
for (let i = 0; i < answers.length; i++) {
const a = answers[i];
if (question.type === QuizQuestionType.CHECK) {
console.log(a.answer.includes('2'), answer_id);
if (a.answer.includes(String(answer_id))) {
count++;
}
} else if (a.answer === answer) {
count++;
}
}
@@ -79,8 +95,8 @@
<th class="p-1 mx-auto">{$t('words.answer')} </th>
{#if question.type !== QuizQuestionType.VOTING}
<th class="border-l dark:border-gray-500 p-1 mx-auto border-gray-300"
>{$t('words.correct')}?</th
>
>{$t('words.correct')}?
</th>
{/if}
</tr>
{#each answers as answer}
@@ -211,7 +211,7 @@
</svg>
<span class="text-lg">{question.time}s</span>
</p>
{#if question.type === QuizQuestionType.ABCD || question.type === undefined}
{#if question.type === QuizQuestionType.ABCD || question.type === undefined || question.type === QuizQuestionType.CHECK}
<div class="grid grid-cols-2 gap-4 m-4 p-6">
{#each question.answers as answer, index_answer}
<div