Added Check Choices to practice mode

This commit is contained in:
Mawoka
2023-05-24 21:51:59 +02:00
parent c6dc71b941
commit 61f62c7780
+43
View File
@@ -10,6 +10,7 @@
import { getLocalization } from '$lib/i18n'; import { getLocalization } from '$lib/i18n';
import Spinner from '$lib/Spinner.svelte'; import Spinner from '$lib/Spinner.svelte';
import { flip } from 'svelte/animate'; import { flip } from 'svelte/animate';
import BrownButton from '$lib/components/buttons/brown.svelte';
export let question: Question; export let question: Question;
@@ -43,6 +44,8 @@
let text_input; let text_input;
timer(question.time); timer(question.time);
let check_choice_selected = [false, false, false, false];
function shuffleArray(a) { function shuffleArray(a) {
for (let i = a.length - 1; i > 0; i--) { for (let i = a.length - 1; i > 0; i--) {
const j = Math.floor(Math.random() * (i + 1)); const j = Math.floor(Math.random() * (i + 1));
@@ -303,5 +306,45 @@
{$t('words.submit')} {$t('words.submit')}
</button> </button>
</div> </div>
{:else if question.type === QuizQuestionType.CHECK}
{#if show_results}
<div>
{#each question.answers as answer, i}
<button
disabled
class:bg-green-500={question.answers[i].right}
class:bg-red-500={!question.answers[i].right}
class="p-2 rounded-lg flex justify-center w-full transition my-5 text-black"
>{answer.answer}</button
>
{/each}
</div>
{:else}
<div>
{#each question.answers as answer, i}
<button
disabled={selected_answer !== undefined || timer_res === '0'}
class="p-2 rounded-lg flex justify-center w-full transition bg-amber-300 my-5 disabled:grayscale text-black opacity-50"
class:opacity-100={check_choice_selected[i]}
on:click={() => {
check_choice_selected[i] = !check_choice_selected[i];
}}>{answer.answer}</button
>
{/each}
<BrownButton
on:click={() => {
timer_res = '0';
}}>{$t('words.submit')}</BrownButton
>
{#if timer_res === '0'}
<button
class="bg-orange-500 p-2 rounded-lg flex justify-center w-full transition my-5 text-black"
on:click={() => {
show_results = true;
}}>{$t('admin_page.get_results')}</button
>
{/if}
</div>
{/if}
{/if} {/if}
</div> </div>