randomize order of answers

Co-authored-by: haraldnilsen <harald_998@hotmail.com>
Signed-off-by: Sindre Kjelsrud <kjelsrudsindre@gmail.com>
This commit is contained in:
Sindre Kjelsrud 2024-01-14 13:20:00 +01:00
parent bda57ee28e
commit 75e9598db2
Signed by untrusted user who does not match committer: sidski
GPG key ID: D2BBDF3EDE6BA9A6

View file

@ -13,6 +13,8 @@
let questionAnswer2Text: string = "" let questionAnswer2Text: string = ""
let questionAnswer2ID: number = 0 let questionAnswer2ID: number = 0
let questionNumber: number = 0 let questionNumber: number = 0
let shouldSwitch = false;
let question1Answered: boolean = false let question1Answered: boolean = false
let question2Answered: boolean = false let question2Answered: boolean = false
@ -60,16 +62,24 @@
// On mount, call the update function // On mount, call the update function
onMount(() => { onMount(() => {
updateQuestionData(); updateQuestionData();
shouldSwitch = Math.random() >= 0.5;
}); });
</script> </script>
<div class="flex flex-col h-full md:h-screen gap-4"> <div class="flex flex-col h-full md:h-screen gap-10">
<FormHeader questionNum={questionNumber} formQuestion={formQuestion}/> <FormHeader questionNum={questionNumber} formQuestion={formQuestion}/>
<div class="flex flex-col md:flex-row h-full justify-between gap-12"> <div class="flex flex-col md:flex-row h-full justify-between gap-12">
{#key questionNumber} {#if shouldSwitch}
<AnswerBox on:update={(e) => question1Answered = e.detail} answerNum={1} answerText={questionAnswer1Text} answerID={questionAnswer1ID}/> {#key questionNumber}
<AnswerBox on:update={(e) => question2Answered = e.detail} answerNum={2} answerText={questionAnswer2Text} answerID={questionAnswer2ID}/> <AnswerBox on:update={(e) => question2Answered = e.detail} answerNum={2} answerText={questionAnswer2Text} answerID={questionAnswer2ID}/>
{/key} <AnswerBox on:update={(e) => question1Answered = e.detail} answerNum={1} answerText={questionAnswer1Text} answerID={questionAnswer1ID}/>
{/key}
{:else}
{#key questionNumber}
<AnswerBox on:update={(e) => question1Answered = e.detail} answerNum={1} answerText={questionAnswer1Text} answerID={questionAnswer1ID}/>
<AnswerBox on:update={(e) => question2Answered = e.detail} answerNum={2} answerText={questionAnswer2Text} answerID={questionAnswer2ID}/>
{/key}
{/if}
</div> </div>
{#key questionNumber} {#key questionNumber}
<Footer answeredAll={question1Answered && question2Answered} questionNum={Number(questionNumber)}/> <Footer answeredAll={question1Answered && question2Answered} questionNum={Number(questionNumber)}/>