From 75e9598db2c87c6e256163d755a67eb7a0d5657f Mon Sep 17 00:00:00 2001 From: Sindre Kjelsrud Date: Sun, 14 Jan 2024 13:20:00 +0100 Subject: [PATCH] :sparkles: randomize order of answers Co-authored-by: haraldnilsen Signed-off-by: Sindre Kjelsrud --- frontend/src/routes/form/[slug]/+page.svelte | 22 ++++++++++++++------ 1 file changed, 16 insertions(+), 6 deletions(-) diff --git a/frontend/src/routes/form/[slug]/+page.svelte b/frontend/src/routes/form/[slug]/+page.svelte index 7b4fb1d..9dc3184 100644 --- a/frontend/src/routes/form/[slug]/+page.svelte +++ b/frontend/src/routes/form/[slug]/+page.svelte @@ -13,6 +13,8 @@ let questionAnswer2Text: string = "" let questionAnswer2ID: number = 0 let questionNumber: number = 0 + + let shouldSwitch = false; let question1Answered: boolean = false let question2Answered: boolean = false @@ -60,16 +62,24 @@ // On mount, call the update function onMount(() => { updateQuestionData(); + shouldSwitch = Math.random() >= 0.5; }); -
+
-
- {#key questionNumber} - question1Answered = e.detail} answerNum={1} answerText={questionAnswer1Text} answerID={questionAnswer1ID}/> - question2Answered = e.detail} answerNum={2} answerText={questionAnswer2Text} answerID={questionAnswer2ID}/> - {/key} +
+ {#if shouldSwitch} + {#key questionNumber} + question2Answered = e.detail} answerNum={2} answerText={questionAnswer2Text} answerID={questionAnswer2ID}/> + question1Answered = e.detail} answerNum={1} answerText={questionAnswer1Text} answerID={questionAnswer1ID}/> + {/key} + {:else} + {#key questionNumber} + question1Answered = e.detail} answerNum={1} answerText={questionAnswer1Text} answerID={questionAnswer1ID}/> + question2Answered = e.detail} answerNum={2} answerText={questionAnswer2Text} answerID={questionAnswer2ID}/> + {/key} + {/if}
{#key questionNumber}