Skip to content

Instantly share code, notes, and snippets.

@Qwizi
Last active January 22, 2025 19:59
Show Gist options
  • Save Qwizi/3899b27511250565121d94d41fe8ccbf to your computer and use it in GitHub Desktop.
Save Qwizi/3899b27511250565121d94d41fe8ccbf to your computer and use it in GitHub Desktop.
ang
(() => {
try {
// Mark all objectives as completed
const objectiveCount = Number(SCORM2004_CallGetValue('cmi.objectives._count'));
if (objectiveCount > 0) console.log(`Completing ${objectiveCount} objectives`);
for (var i = 0; i < objectiveCount; i++) {
const objectiveId = SCORM2004_CallGetValue('cmi.objectives.' + i + '.id');
SCORM2004_SetObjectiveStatus(objectiveId, LESSON_STATUS_PASSED);
}
// Mark all interactions as correct
const interactionCount = Number(SCORM2004_CallGetValue('cmi.interactions._count'));
if (interactionCount > 0) console.log(`Completing ${interactionCount} interactions`);
for (var i = 0; i < interactionCount; i++) {
const interactionId = SCORM2004_CallGetValue('cmi.interactions.' + i + '.id');
const correctResponse = SCORM2004_GetInteractionCorrectResponse(interactionId);
const interactionType = SCORM2004_GetInteractionType(interactionId);
SCORM2004_RecordInteraction(
interactionId,
correctResponse,
true,
correctResponse,
'',
0,
0,
'',
new Date(),
interactionType
);
}
// Set the score above the passing score
const passingScore = SCORM2004_GetPassingScore() + 1;
const minScore = SCORM2004_CallGetValue('cmi.score.min');
const maxScore = SCORM2004_CallGetValue('cmi.score.max');
// Not all courses/modules have a score, so we need to check if it exists
if (minScore !== '' && maxScore !== '') {
const score = Math.min(Math.max(passingScore, minScore), maxScore);
console.log(`Setting score to ${score} out of ${maxScore} possible points`);
SCORM2004_SetScore(score, minScore, maxScore);
}
// Mark the module as completed and passed
console.log('Setting module as completed and passed');
SCORM2004_SetPassed();
// Fake the time it took to complete the module
const milisecondsInMinute = 60 * 1000;
const randomTime =
Math.floor(Math.random() * 15 * milisecondsInMinute) + 5 * milisecondsInMinute;
console.log(`Setting time to ${randomTime / milisecondsInMinute} minutes`);
SCORM2004_SaveTime(randomTime);
// Finish the module
SCORM2004_Finish(SCORM2004_NORMAL_EXIT, false);
console.log('Module completed successfuly, you can close the window');
} catch (error) {
console.error('An error occurred while trying to complete the module', error);
}
})();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment