Skip to content

Commit 5305f4b

Browse files
authoredOct 11, 2024··
Merge pull request #42 from alien-andrew/41_pass_fail
Ability to configure pass / fail and provide a custom message based o…
2 parents 2926691 + 95b7849 commit 5305f4b

File tree

4 files changed

+33
-6
lines changed

4 files changed

+33
-6
lines changed
 

‎public/build/quizdown.js

+5-5
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

‎public/index.html

+4-1
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,9 @@ <h1>Quizdown Demo Page</h1>
3737
shuffleAnswers: true
3838
shuffleQuestions: true
3939
nQuestions: 3
40+
passingGrade: 80
41+
customPassMsg: You have Passed!
42+
customFailMsg: You have not passed
4043
---
4144

4245
#### What's the value of $x$?
@@ -193,4 +196,4 @@ <h1>Quizdown Demo Page</h1>
193196
</div>
194197
</body>
195198

196-
</html>
199+
</html>

‎src/components/ResultsView.svelte

+18
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,16 @@
2323
minimumIntegerDigits: 2,
2424
});
2525
}
26+
27+
let gradedPoints = quiz.evaluate();
28+
let passed = false;
29+
if (quiz.config.passingGrade != undefined) {
30+
if( (Number(gradedPoints)/Number(quiz.questions.length) * 100)
31+
>= Number(quiz.config.passingGrade) ) {
32+
passed = true;
33+
}
34+
}
35+
2636
</script>
2737

2838
<h3>{$_('resultsTitle')}</h3>
@@ -61,6 +71,14 @@
6171
</ol>
6272
</li>
6373
{/each}
74+
<h2>
75+
{#if passed == true}
76+
{quiz.config.customPassMsg}
77+
{/if}
78+
{#if passed == false && quiz.config.passingGrade != undefined}
79+
{quiz.config.customFailMsg}
80+
{/if}
81+
</h2>
6482
</ol>
6583
</div>
6684
</Loading>

‎src/config.ts

+6
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,9 @@ export class Config {
2626
primaryColor: string;
2727
secondaryColor: string;
2828
textColor: string;
29+
passingGrade: number | undefined;
30+
customPassMsg: string;
31+
customFailMsg: string;
2932
locale: 'de' | 'en' | 'es' | 'fr' | null;
3033
enableRetry: boolean;
3134

@@ -41,6 +44,9 @@ export class Config {
4144
this.primaryColor = get(options['primaryColor'], 'steelblue');
4245
this.secondaryColor = get(options['secondaryColor'], '#f2f2f2');
4346
this.textColor = get(options['textColor'], 'black');
47+
this.passingGrade = get(options['passingGrade'], undefined);
48+
this.customPassMsg = get(options['customPassMsg'], 'You have passed!');
49+
this.customFailMsg = get(options['customFailMsg'], 'You have not passed');
4450
this.locale = get(options['locale'], null);
4551
this.enableRetry = get(options['enableRetry'],true);
4652
}

0 commit comments

Comments
 (0)
Please sign in to comment.