Skip to content

Commit

Permalink
add default correct and default incorrect settings
Browse files Browse the repository at this point in the history
  • Loading branch information
parmsam committed Sep 5, 2024
1 parent 584cf70 commit 2f325d9
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 3 deletions.
4 changes: 4 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,8 @@ format:
allowNumberKeys: true
disableOnCheck: false
shuffleOptions: true
defaultCorrect: "Correct!"
defaultIncorrect: "Incorrect!"
revealjs-plugins:
- quiz
```
Expand All @@ -63,6 +65,8 @@ The `disableOnCheck` option will disable the quiz question after it has been che

The `shuffleOptions` option will shuffle the order of the options when the question is displayed. This is true by default. You can refresh your browser to reshuffle the options.

The `defaultCorrect` and `defaultIncorrect` options allow you to set the default text for the correct and incorrect explanations. By default, they are set to "Correct!" and "Incorrect!" if you don't define them.

### Custom explanations for each option

Within a slide, you can use the `data-explanation` attribute to provide an explanation for the each option including the correct answer. It is a [data attribute](https://developer.mozilla.org/en-US/docs/Learn/HTML/Howto/Use_data_attributes), in case you are wondering why it has a "data-*" prefix. This will be displayed when the user checks their answer. For example, here's what a math quiz question might look like:
Expand Down
4 changes: 3 additions & 1 deletion _extensions/quiz/_extension.yml
Original file line number Diff line number Diff line change
Expand Up @@ -16,4 +16,6 @@ contributes:
shuffleKey: "t"
allowNumberKeys: true
disableOnCheck: false
shuffleOptions: true
shuffleOptions: true
defaultCorrect: ""
defaultIncorrect: ""
7 changes: 5 additions & 2 deletions _extensions/quiz/quiz.js
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,9 @@ window.RevealQuiz = function () {

settings.shuffleOptions = options.shuffleOptions || false;

settings.defaultCorrect = options.defaultCorrect || "Correct!";
settings.defaultIncorrect = options.defaultIncorrect || "Incorrect!";

console.log(settings);

deck.getSlides().forEach((slide, index) => {
Expand Down Expand Up @@ -172,11 +175,11 @@ window.RevealQuiz = function () {
}
if (isCorrect) {
selectedOption.classList.add('correct');
cloneFeedbackElement.textContent = explanation || 'Correct!'; // Use explanation if available
cloneFeedbackElement.textContent = explanation || settings.defaultCorrect; // Use explanation if available
cloneFeedbackElement.style.color = '#27ae60';
} else {
selectedOption.classList.add('incorrect');
cloneFeedbackElement.textContent = explanation || 'Incorrect!'; // Use explanation if available
cloneFeedbackElement.textContent = explanation || settings.defaultIncorrect; // Use explanation if available
cloneFeedbackElement.style.color = '#c0392b';
}

Expand Down

0 comments on commit 2f325d9

Please sign in to comment.