3 //JMATCH-SPECIFIC SCORM-RELATED JAVASCRIPT CODE
5 function SetScormScore(){
6 //Reports the current score and any other information back to the LMS
8 API.LMSSetValue('cmi.core.score.raw', Score);
10 //Now send a detailed reports on the item
11 var ItemLabel = 'Matching';
12 API.LMSSetValue('cmi.objectives.0.id', 'obj'+ItemLabel);
13 API.LMSSetValue('cmi.interactions.0.id', 'int'+ItemLabel);
14 API.LMSSetValue('cmi.objectives.0.status', API.LMSGetValue('cmi.core.lesson_status'));
15 API.LMSSetValue('cmi.objectives.0.score.min', '0');
16 API.LMSSetValue('cmi.objectives.0.score.max', '100');
17 API.LMSSetValue('cmi.objectives.0.score.raw', Score);
18 //We can only use the performance type, because we're storing multiple responses of various types.
19 API.LMSSetValue('cmi.interactions.0.type', 'performance');
21 var AnswersTried = '';
22 for (var i=0; i<Status[0][3].length; i++){
23 if (i>0){AnswersTried += ' | ';}
24 for (var j=0; j<Status.length; j++){
25 if (j>0){AnswersTried += ',';}
26 AnswersTried += j + '.' + Status[j][3][i];
29 API.LMSSetValue('cmi.interactions.0.student_response', AnswersTried);
35 //JMATCH CORE JAVASCRIPT CODE
37 var CorrectIndicator = '[strCorrectIndicator]';
38 var IncorrectIndicator = '[strIncorrectIndicator]';
39 var YourScoreIs = '[strYourScoreIs]';
40 var CorrectResponse = '[strGuessCorrect]';
41 var IncorrectResponse = '[strGuessIncorrect]';
42 var TotalUnfixedLeftItems = 0;
43 var TotCorrectChoices = 0;
50 var ShuffleQs = [boolShuffleQs];
51 var QsToShow = [QsToShow];
55 RemoveBottomNavBarForIE();
66 PreloadImages([PreloadImageList]);
69 SetUpItems(ShuffleQs,QsToShow);
71 TotalUnfixedLeftItems = document.getElementById('MatchDiv').getElementsByTagName('select').length;
84 function CreateStatusArrays(){
85 var Selects = document.getElementById('Questions').getElementsByTagName('select');
86 for (var x=0; x<Selects.length; x++){
87 Status[x] = new Array();
88 Status[x][0] = 0; // Item not matched correctly yet
89 Status[x][1] = 0; //Tries at this item so far
90 Status[x][2] = Selects[x].id; //Store a ref to the original drop-down
91 Status[x][3] = new Array(); //Sequence of guesses for this item
95 function GetKeyFromSelectContainer(Container){
97 if (Container.getElementsByTagName('select').length > 0){
98 var Select = Container.getElementsByTagName('select')[0];
100 Result = parseInt(Select.id.substring(1, Select.id.length));
106 function GetKeyFromSelect(Select){
109 Result = parseInt(Select.id.substring(1, Select.id.length));
114 var OriginalKeys = new Array();
115 var ReducedKeys = new Array();
117 function GetUniqueKeys(Container, TargetArray){
118 TargetArray.length = 0;
120 var SList = Container.getElementsByTagName('select');
121 if (SList.length > 0){
122 for (var i=0; i<SList.length; i++){
123 x = GetKeyFromSelect(SList[i]);
124 if (TargetArray.indexOf(x) < 0){
131 function SetUpItems(ShuffleQs, ReduceTo){
132 var QList = new Array();
133 var i, j, k, Selects, Options;
135 //Remove all the table rows and put them in an array for processing
136 var Qs = document.getElementById('Questions');
138 //First, get a list of keys
139 GetUniqueKeys(Qs, OriginalKeys);
141 //Remove the table rows to an array
142 while (Qs.getElementsByTagName('tr').length > 0){
143 QList.push(Qs.removeChild(Qs.getElementsByTagName('tr')[0]));
146 var Reducing = (QList.length > ReduceTo);
148 //If required, select random rows to delete
149 if (Reducing == true){
151 while (ReduceTo < QList.length){
153 //Get a number to delete from the array
154 DumpItem = Math.floor(QList.length*Math.random());
155 for (i=DumpItem; i<(QList.length-1); i++){
156 QList[i] = QList[i+1];
158 QList.length = QList.length-1;
161 //Shuffle the rows if necessary
162 if (ShuffleQs == true){
163 QList = Shuffle(QList);
166 TotalUnfixedLeftItems = QList.length;
168 //Write the rows back to the table body
169 for (i=0; i<QList.length; i++){
170 Qs.appendChild(QList[i]);
173 //Now we need to remove any drop-down options that no longer have associated select items
174 if (Reducing == true){
175 GetUniqueKeys(Qs, ReducedKeys);
177 Selects = Qs.getElementsByTagName('select');
178 for (i=0; i<Selects.length; i++){
179 Options = Selects[i].getElementsByTagName('option');
180 for (j=Options.length-1; j>=0; j--){
181 if (OptionRequired(Options[j].value) == false){
182 Selects[i].removeChild(Options[j]);
189 function OptionRequired(Key){
190 if (ReducedKeys.indexOf(Key) > -1){
194 if (OriginalKeys.indexOf(Key) > -1){
203 function CheckAnswers(){
204 if (Locked == true){return;}
211 TotCorrectChoices = 0;
213 //for each item not fixed or a distractor
214 for (var i=0; i<Status.length; i++){
216 //if it hasn't been answered correctly yet
217 if (Status[i][0] < 1){
219 //Add one to the number of tries for this item
222 //Get a pointer to the drop-down
223 Select = document.getElementById(Status[i][2]);
224 Key = GetKeyFromSelect(Select);
225 //Save the answer given
226 Status[i][3].push(Select.options[Select.selectedIndex].value);
229 if (Select.options[Select.selectedIndex].value == Key){
231 AnsText = Select.options[Select.selectedIndex].innerHTML;
232 Parent = Select.parentNode;
233 Parent.removeChild(Select);
234 Parent.innerHTML = AnsText;
235 Parent.nextSibling.innerHTML = CorrectIndicator;
239 Parent = Select.parentNode;
240 Parent.nextSibling.innerHTML = IncorrectIndicator;
244 //Add a copy of the last (correct) answer.
245 Status[i][3].push(Status[i][3][Status[i][3].length-1]);
247 //If it's correct, count it
248 if (Status[i][0] == 1){
252 //Calculate the score
253 Score = Math.floor(((TotCorrectChoices-Penalties)/TotalUnfixedLeftItems)*100);
254 if (Score<0){Score = 0;}
258 if (AllDone == true){
259 Feedback = CorrectResponse + '<br />' + YourScoreIs + Score + '%.';
262 Feedback = IncorrectResponse + '<br />' + YourScoreIs + Score + '%.';
263 //Penalty for incorrect check
267 //If the exercise is over, deal with that
268 if ((AllDone == true)||(TimeOver == true)){
270 setTimeout('SendResults(' + Score + ')', 50);
273 window.clearInterval(Interval);
278 setTimeout('Finish()', SubmissionTimeout);
279 WriteToInstructions(Feedback);
283 ShowMessage(Feedback);
286 if (AllDone == true){
290 SetScormIncomplete();
297 document.getElementById('Timer').innerHTML = '[strTimesUp]';