✨ Added new range-answer type
This commit is contained in:
@@ -5,7 +5,9 @@
|
||||
-->
|
||||
<script lang="ts">
|
||||
import type { Question } from '$lib/quiz_types';
|
||||
import { QuizQuestionType } from '$lib/quiz_types';
|
||||
import { socket } from '$lib/socket';
|
||||
import Spinner from '../Spinner.svelte';
|
||||
|
||||
export let question: Question;
|
||||
export let question_index: string | number;
|
||||
@@ -44,6 +46,21 @@
|
||||
answer: answer
|
||||
});
|
||||
};
|
||||
|
||||
let slider_value = [0];
|
||||
if (question.type === QuizQuestionType.RANGE) {
|
||||
slider_value[0] = (question.answers.max - question.answers.min) / 2 + question.answers.min;
|
||||
}
|
||||
const set_answer_if_not_set_range = (time) => {
|
||||
if (question.type !== QuizQuestionType.RANGE) {
|
||||
return;
|
||||
}
|
||||
if (selected_answer === undefined && time === '0') {
|
||||
selected_answer = `${slider_value[0]}`;
|
||||
selectAnswer(selected_answer);
|
||||
}
|
||||
};
|
||||
$: set_answer_if_not_set_range(timer_res);
|
||||
</script>
|
||||
|
||||
<div class="flex flex-col justify-center w-screen h-1/6">
|
||||
@@ -62,16 +79,40 @@
|
||||
</div>
|
||||
{/if}
|
||||
{#if timer_res !== '0'}
|
||||
<div class="flex flex-wrap">
|
||||
{#each question.answers as answer}
|
||||
<button
|
||||
class="w-1/2 text-3xl bg-amber-700 my-2 disabled:opacity-60 border border-white"
|
||||
disabled={selected_answer !== undefined}
|
||||
on:click={() => selectAnswer(answer.answer)}>{answer.answer}</button
|
||||
>
|
||||
{/each}
|
||||
</div>
|
||||
{:else}
|
||||
{#if question.type === QuizQuestionType.ABCD}
|
||||
<div class="flex flex-wrap">
|
||||
{#each question.answers as answer}
|
||||
<button
|
||||
class="w-1/2 text-3xl bg-amber-700 my-2 disabled:opacity-60 border border-white"
|
||||
disabled={selected_answer !== undefined}
|
||||
on:click={() => selectAnswer(answer.answer)}>{answer.answer}</button
|
||||
>
|
||||
{/each}
|
||||
</div>
|
||||
{:else if question.type === QuizQuestionType.RANGE}
|
||||
{#await import('svelte-range-slider-pips')}
|
||||
<Spinner />
|
||||
{:then c}
|
||||
<svelte:component
|
||||
this={c.default}
|
||||
bind:values={slider_value}
|
||||
bind:min={question.answers.min}
|
||||
bind:max={question.answers.max}
|
||||
pips
|
||||
float
|
||||
all="label"
|
||||
/>
|
||||
<div class="flex justify-center">
|
||||
<button
|
||||
class="w-1/2 text-3xl bg-amber-700 my-2 disabled:opacity-60 border border-white"
|
||||
disabled={selected_answer !== undefined}
|
||||
on:click={() => selectAnswer(slider_value[0])}
|
||||
>Submit
|
||||
</button>
|
||||
</div>
|
||||
{/await}
|
||||
{/if}
|
||||
{:else if question.type === QuizQuestionType.ABCD}
|
||||
<div class="flex flex-wrap">
|
||||
{#each question.answers as answer}
|
||||
{#if answer.right}
|
||||
@@ -89,4 +130,14 @@
|
||||
{/if}
|
||||
{/each}
|
||||
</div>
|
||||
{:else if question.type === QuizQuestionType.RANGE}
|
||||
<p class="text-center">
|
||||
Every number between {question.answers.min_correct} and {question.answers.max_correct} was correct.
|
||||
You got {selected_answer}, so you have been
|
||||
{#if question.answers.min_correct <= parseInt(selected_answer) && parseInt(selected_answer) <= question.answers.max_correct}
|
||||
correct
|
||||
{:else}
|
||||
wrong.
|
||||
{/if}
|
||||
</p>
|
||||
{/if}
|
||||
|
||||
@@ -6,6 +6,7 @@
|
||||
<script lang="ts">
|
||||
import type { Answer, QuizData } from '$lib/quiz_types';
|
||||
import { getLocalization } from '$lib/i18n';
|
||||
import { QuizQuestionType } from '../quiz_types.js';
|
||||
|
||||
const { t } = getLocalization();
|
||||
export let results: Array<Answer>;
|
||||
@@ -30,56 +31,64 @@
|
||||
<div>
|
||||
<h2 class="text-center text-3xl mb-8">{$t('words.result', { count: 2 })}</h2>
|
||||
<div class="w-screen flex justify-center">
|
||||
<div class="relative overflow-x-auto shadow-md rounded-lg">
|
||||
<table class="w-fit text-sm text-left text-gray-500 dark:text-gray-400">
|
||||
<thead class="bg-gray-50 dark:bg-gray-700">
|
||||
<tr>
|
||||
<th
|
||||
scope="col"
|
||||
class="py-3 px-6 text-xs font-medium tracking-wider text-left text-gray-700 uppercase dark:text-gray-400"
|
||||
>
|
||||
{$t('words.answer')}
|
||||
</th>
|
||||
<th
|
||||
scope="col"
|
||||
class="py-3 px-6 text-xs font-medium tracking-wider text-left text-gray-700 uppercase dark:text-gray-400"
|
||||
>
|
||||
{$t('words.count')}
|
||||
</th>
|
||||
<th
|
||||
scope="col"
|
||||
class="py-3 px-6 text-xs font-medium tracking-wider text-left text-gray-700 uppercase dark:text-gray-400"
|
||||
>
|
||||
{$t('words.correct')}
|
||||
</th>
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody>
|
||||
{#each game_data.questions[parseInt(question_index)].answers as answer}
|
||||
<tr class="bg-white border-b dark:bg-gray-800 dark:border-gray-700">
|
||||
<td
|
||||
class="py-4 px-6 text-sm font-medium text-gray-900 whitespace-nowrap dark:text-white"
|
||||
{#if game_data.questions[parseInt(question_index)].type === QuizQuestionType.ABCD}
|
||||
<div class="relative overflow-x-auto shadow-md rounded-lg">
|
||||
<table class="w-fit text-sm text-left text-gray-500 dark:text-gray-400">
|
||||
<thead class="bg-gray-50 dark:bg-gray-700">
|
||||
<tr>
|
||||
<th
|
||||
scope="col"
|
||||
class="py-3 px-6 text-xs font-medium tracking-wider text-left text-gray-700 uppercase dark:text-gray-400"
|
||||
>
|
||||
{answer.answer}
|
||||
</td>
|
||||
<td
|
||||
class="py-4 px-6 text-sm text-gray-500 whitespace-nowrap dark:text-gray-400"
|
||||
{$t('words.answer')}
|
||||
</th>
|
||||
<th
|
||||
scope="col"
|
||||
class="py-3 px-6 text-xs font-medium tracking-wider text-left text-gray-700 uppercase dark:text-gray-400"
|
||||
>
|
||||
{data_store[answer.answer]}
|
||||
</td>
|
||||
<td
|
||||
class="py-4 px-6 text-sm text-gray-500 whitespace-nowrap dark:text-gray-400"
|
||||
{$t('words.count')}
|
||||
</th>
|
||||
<th
|
||||
scope="col"
|
||||
class="py-3 px-6 text-xs font-medium tracking-wider text-left text-gray-700 uppercase dark:text-gray-400"
|
||||
>
|
||||
{#if answer.right}
|
||||
✅
|
||||
{:else}
|
||||
❌
|
||||
{/if}
|
||||
</td>
|
||||
{$t('words.correct')}
|
||||
</th>
|
||||
</tr>
|
||||
{/each}
|
||||
</tbody>
|
||||
</table>
|
||||
</div>
|
||||
</thead>
|
||||
<tbody>
|
||||
{#each game_data.questions[parseInt(question_index)].answers as answer}
|
||||
<tr class="bg-white border-b dark:bg-gray-800 dark:border-gray-700">
|
||||
<td
|
||||
class="py-4 px-6 text-sm font-medium text-gray-900 whitespace-nowrap dark:text-white"
|
||||
>
|
||||
{answer.answer}
|
||||
</td>
|
||||
<td
|
||||
class="py-4 px-6 text-sm text-gray-500 whitespace-nowrap dark:text-gray-400"
|
||||
>
|
||||
{data_store[answer.answer]}
|
||||
</td>
|
||||
<td
|
||||
class="py-4 px-6 text-sm text-gray-500 whitespace-nowrap dark:text-gray-400"
|
||||
>
|
||||
{#if answer.right}
|
||||
✅
|
||||
{:else}
|
||||
❌
|
||||
{/if}
|
||||
</td>
|
||||
</tr>
|
||||
{/each}
|
||||
</tbody>
|
||||
</table>
|
||||
</div>
|
||||
{:else if game_data.questions[parseInt(question_index)].type === QuizQuestionType.RANGE}
|
||||
<p class="text-center">
|
||||
Every number between {game_data.questions[parseInt(question_index)].answers
|
||||
.min_correct} and {game_data.questions[parseInt(question_index)].answers
|
||||
.max_correct} was correct.
|
||||
</p>
|
||||
{/if}
|
||||
</div>
|
||||
</div>
|
||||
|
||||
Reference in New Issue
Block a user