Skip to content
Permalink
Browse files
handles custom max score
  • Loading branch information
aa7401 committed Jun 4, 2020
1 parent 6e2294d commit deab2fb9813538c249426748d436b54156cb1b87
Show file tree
Hide file tree
Showing 10 changed files with 131 additions and 96 deletions.
BIN +0 Bytes (100%) .DS_Store
Binary file not shown.
@@ -0,0 +1,3 @@

.DS_Store
*.zip
@@ -1,7 +1,6 @@

# TODO

- Make sure we warn if score not in bounds.
- Display current score on page.
- display pass/fail onscreen.
- calculate total time spent `session_time`.
@@ -1,5 +1,16 @@

h1 {
h1, h2, h3, p {
font-family: Arial, Helvetica, sans-serif;
color: darkgray;
}

.fullscreen {
position: fixed;
left: 0;
top: 0;
height: 100%;
width: 0;
z-index: 1;
overflow-x: hidden; /* Disable horizontal scroll */
transition: 0.5s;
}
@@ -37,6 +37,7 @@ intra-SCO navigation.
<file href="js/scormfunctions.js"/>
<file href="js/script.js"/>
<file href="css/style.css"/>
<file href="scormData.json"/>
</resource>
</resources>
</manifest>
@@ -14,10 +14,18 @@
</head>

<body>
<h1>Simple SCORM Template</h1>
<p>your name here...</p>
<input type="text" value="42" />
<button id="update">Update score</button>
<button id="end">End game</button>
<header>
<h1>Simple SCORM Template</h1>
</header>
<main>
<p>your name here...</p>
<h2></h2>
<h3></h3>
<section>
<input type="text" />
<button id="update">Update score</button>
<button id="end">End game</button>
</section>
</main>
</body>
</html>
@@ -16,89 +16,6 @@ some basic SCORM error handling.

//Include the standard ADL-supplied API discovery algorithm

// list of writable SCORM data values:

const scormData = {
cmi: {
core: {
student_id: {
readable: true,
description: 'student username',
datatype: 'string'
},
student_name: {
readable: true,
description: 'student name',
datatype: 'string'
},
lesson_location: {
readable: true,
writable: true,
description: 'bookmark',
datatype: 'string'
},
credit: {
readable: true,
description: 'bookmark',
datatype: 'string',
options: [
'credit',
'no-credit'
]
},
lesson_status: {
readable: true,
writable: true,
description: 'bookmark',
datatype: 'string',
options: [
'passed',
'completed',
'failed',
'incomplete',
'browsed',
'not attempted'
]
},
entry: {
readable: true,
description: 'Asserts whether the learner has previously accessed the SCO',
datatype: 'string',
options: [
'ab-initio',
'resume',
''
]
},
score: {
raw: {
readable: true,
writable: true,
description: 'the performance of the learner',
datatype: 'number'
},
max: {
readable: true,
writable: true,
description: 'Maximum value in the range for the raw score',
datatype: 'number'
},
min: {
readable: true,
writable: true,
description: 'Minimum value in the range for the raw score',
datatype: 'number'
}
},
total_time: {
readable: true,
description: 'Sum of all of the learner’s session times accumulated in the current learner attempt',
datatype: 'CMITimespan'
}
}
}
}

///////////////////////////////////////////
//Begin ADL-provided API discovery algorithm
///////////////////////////////////////////
@@ -129,7 +46,7 @@ function findAPI(win) {
}

/**
* open the API and return it.
* open the API and return
*/
function getAPI() {
// start by looking for the API in the current window
@@ -1,4 +1,7 @@

const MIN_SCORE = 0
let MAX_SCORE = 100

document.addEventListener('DOMContentLoaded', event => {
console.log('DOM CONTENT LOADED')
document.querySelector('button#update').addEventListener('click', event => {
@@ -8,6 +11,7 @@ document.addEventListener('DOMContentLoaded', event => {
})
document.querySelector('button#end').addEventListener('click', event => {
console.log('END BUTTON CLICKED')
document.querySelector('section').hidden = true
endGame(parseInt(document.querySelector('input').value))
ScormProcessFinish()
})
@@ -16,18 +20,26 @@ document.addEventListener('DOMContentLoaded', event => {
function updateScore(score) {
score = parseInt(score)
console.log(`score: ${score}`)
ScormProcessSetValue('cmi.core.score.raw', parseInt(score))
const percent = (score / MAX_SCORE) * 100
if(!isNaN(score) && score >= MIN_SCORE && score <= MAX_SCORE) { // is the score a number in a valid range
ScormProcessSetValue('cmi.core.score.raw', percent)
} else {
console.warn(`invalid score (${score}): needs to be a number between ${MIN_SCORE} and ${MAX_SCORE}`)
}
return percent
}

function endGame(score) {
updateScore(score)
const percent = updateScore(score)
document.querySelector('h2').innerText = `${percent}%`
// set the status
const mastery = parseInt(ScormProcessGetValue('cmi.student_data.mastery_score'))
console.log(`mastery: (${mastery})`)
if(!isNaN(mastery)) { // NaN if mastery score not provided by the API
const status = parseInt(score) >= mastery ? 'passed' : 'failed' // if mastery score then pass/fail
const status = percent >= mastery ? 'passed' : 'failed' // if mastery score then pass/fail
console.log(`status: (${status})`)
ScormProcessSetValue('cmi.core.lesson_status', status)
document.querySelector('h3').innerText = `status: ${status.toUpperCase()}`
} else {
console.log('status is: (completed)')
ScormProcessSetValue('cmi.core.lesson_status', 'completed') // if no mastery then completed
@@ -47,8 +59,11 @@ window.addEventListener('load', event => {
document.querySelector('p').innerText = name
const username = ScormProcessGetValue('cmi.core.student_id')
console.log(`student ID: ${username}`)
ScormProcessSetValue('cmi.core.score.min', 0)
ScormProcessSetValue('cmi.core.score.max', 100)
const maxScore = parseInt(ScormProcessGetValue('cmi.core.score.max')) // does the LMS provide a max score?
console.log(`moodle max score: (${maxScore})`)
ScormProcessSetValue('cmi.core.score.min', MIN_SCORE)
MAX_SCORE = !isNaN(maxScore) ? maxScore : MAX_SCORE
ScormProcessSetValue('cmi.core.score.max', MAX_SCORE)
})

window.addEventListener('beforeunload', event => {
@@ -0,0 +1,81 @@

{
"cmi": {
"core": {
"student_id": {
"readable": true,
"description": "student username",
"datatype": "string"
},
"student_name": {
"readable": true,
"description": "student name",
"datatype": "string"
},
"lesson_location": {
"readable": true,
"writable": true,
"description": "bookmark",
"datatype": "string"
},
"credit": {
"readable": true,
"description": "bookmark",
"datatype": "string",
"options": [
"credit",
"no-credit"
]
},
"lesson_status": {
"readable": true,
"writable": true,
"description": "bookmark",
"datatype": "string",
"options": [
"passed",
"completed",
"failed",
"incomplete",
"browsed",
"not attempted"
]
},
"entry": {
"readable": true,
"description": "Asserts whether the learner has previously accessed the SCO",
"datatype": "string",
"options": [
"ab-initio",
"resume",
""
]
},
"score": {
"raw": {
"readable": true,
"writable": true,
"description": "the performance of the learner",
"datatype": "number"
},
"max": {
"readable": true,
"writable": true,
"description": "Maximum value in the range for the raw score",
"datatype": "number"
},
"min": {
"readable": true,
"writable": true,
"description": "Minimum value in the range for the raw score",
"datatype": "number"
}
},
"total_time": {
"readable": true,
"description": "Sum of all of the learner’s session times accumulated in the current learner attempt",
"datatype": "CMITimespan"
}
}
}
}
BIN -15.7 KB template 1.9.zip
Binary file not shown.

0 comments on commit deab2fb

Please sign in to comment.