Setting/Getting Attempt Status
The Content Player now supports an event called “sowiso-attempt-status-changed” that enables users to track the attempt status of exercises within the player.
This event provides information about whether an input is unanswered, answered, or invalid.
It provides this information in the status
field of the Event’s detail
object. The status
field will contain a value of either unanswered
, answered
, or incorrectInput
. This documentation will guide you on how to use this new feature.
Usage
-
Select the Player in the DOM
Locate and select the Content Player within the Document Object Model (DOM) using JavaScript.
-
Event Listener Setup
Add an event listener for the “sowiso-attempt-status-changed” event to listen for changes in the attempt status of exercises.
player.addEventListener("sowiso-attempt-status-changed", (event) => { console.log("Attempt Status:", event.detail.status); });
-
Trigger the Event
Trigger the “sowiso-set-attempt-status” event to update the attempt status of the exercises within the player.
player.dispatchEvent(new Event("sowiso-set-attempt-status"));
This event will trigger the update of the attempt status for the exercises.
-
Testing and Examples
Test the functionality by interacting with the player, such as entering answers, submitting, and navigating to the next set of exercises. The “sowiso-attempt-status-changed” event will log the attempt status to the console.
Example Use Case
Here’s a simple example demonstrating the usage of the attempt status event for a multiple-choice exercise:
player.addEventListener("sowiso-attempt-status-changed", (event) => {
const exerciseStatus = event.detail.status;
switch (exerciseStatus) {
case "unanswered":
console.log("Exercise is unanswered.");
break;
case "answered":
console.log("Exercise has been answered.");
break;
case "incorrectInput":
console.log("Exercise has an incorrect input.");
break;
default:
console.log("Unknown attempt status.");
break;
}
});
// Simulate setting attempt status
player.dispatchEvent(new Event("sowiso-set-attempt-status"));