2 //JMIX-SPECIFIC SCORM-RELATED JAVASCRIPT CODE
4 function SetScormScore(){
5 //Reports the current score and any other information back to the LMS
7 API.LMSSetValue('cmi.core.score.raw', Score);
9 //Now send a detailed reports on the item
10 var ItemLabel = 'Item_1';
11 API.LMSSetValue('cmi.objectives.0.id', 'obj'+ItemLabel);
12 API.LMSSetValue('cmi.interactions.0.id', 'int'+ItemLabel);
13 if (Finished == true){
14 API.LMSSetValue('cmi.objectives.0.status', 'completed');
17 API.LMSSetValue('cmi.objectives.0.status', 'incomplete');
20 API.LMSSetValue('cmi.objectives.0.score.min', '0');
21 API.LMSSetValue('cmi.objectives.0.score.max', '100');
22 API.LMSSetValue('cmi.objectives.0.score.raw', Score);
23 //We can only use the performance type, because we're storing multiple responses of various types.
24 API.LMSSetValue('cmi.interactions.0.type', 'performance');
25 API.LMSSetValue('cmi.interactions.0.student_response', AnswersTried);
32 //JMIX STANDARD OUTPUT FORMAT CODE
34 var CorrectResponse = '[strGuessCorrect]';
35 var IncorrectResponse = '[strGuessIncorrect]';
36 var TheseAnswersToo = '[strTheseAnswersToo]';
37 var ThisMuchCorrect = '[strThisMuch]';
38 var NextCorrect = '[strNextCorrect]';
39 var YourScoreIs = '[strYourScoreIs]';
40 var CapitalizeFirst = [boolCapitalizeFirst];
45 var strInstructions = '';
46 var AnswersTried = '';
49 var SegmentTemplate = ' <a class="ExSegment" href="javascript:void(0)" onclick="AddSegment([SegmentNumber])" title="[strClickToAdd]">[CurrentSegment]</a> ';
53 var Punctuation = '[strPunctuation]';
55 var Openers = '[strOpenPunctuation]';
57 var Guesses = new Array();
58 var Remaining = new Array();
59 var CorrectParts = new Array();
68 var Segments = new Array();
71 var GuessSequence = new Array();
73 var Answers = new Array();
76 function WriteToGuess(Feedback) {
77 document.getElementById('GuessDiv').innerHTML = Feedback;
84 if (GuessSequence.length < 1){
87 GuessSequence.length = GuessSequence.length - 1;
90 DisplayExercise(Exercise);
91 //Following line modified for 6.0.4.44 -- "remaining words" message removed, no longer needed
92 WriteToGuess('<span class="Answer">' + Output + '</span>');
95 function AddSegment(SegNum){
97 if (TimeOver == true){return;}
99 GuessSequence[GuessSequence.length] = SegNum;
101 WriteToGuess('<span class="Answer">' + Output + '</span>');
103 DisplayExercise(Exercise);
106 function BuildCurrGuess(){
112 //first, create arrays of all the segments guessed so far and those not yet used
113 GuessSegs = new Array();
114 GuessSegs.length = 0;
116 //set the "used" markers all to 0
117 for (i=0; i<Segments.length; i++){
121 for (i=0; i<GuessSequence.length; i++){
122 for (j=0; j<Segments.length; j++){
123 if ((Segments[j][1] == GuessSequence[i])&&(Segments[j][2] == 0)){
124 GuessSegs[GuessSegs.length] = Segments[j][0];
131 //Create the list of unused segments
133 for (i=0; i<Segments.length; i++){
134 if (Segments[i][2] == 0){
135 RemainingList += Segments[i][0] + ' ';
139 //now concatenate the segments, adding spaces where appropriate;
140 Output = CompileString(GuessSequence);
143 function CompileString(InArray){
146 OutArray = new Array();
148 for (i=0; i<InArray.length; i++){
149 OutArray[OutArray.length] = FindSegment(InArray[i]);
152 if (OutArray.length > 0){
153 OutString = OutArray[0];
160 for (i=1; i<OutArray.length; i++){
162 if ((Openers.indexOf(OutString.charAt(OutString.length-1)) > -1)||(Punctuation.indexOf(OutArray[i].charAt(0)) > -1)){
165 OutString = OutString + Spacer + OutArray[i];
168 //Capitalize the first letter if necessary
169 if (CapitalizeFirst == true){
171 if ((Openers.indexOf(OutString.charAt(i))>-1)||(OutString.charAt(i) == ' ')){
174 if ((Openers.indexOf(OutString.charAt(i))>-1)||(OutString.charAt(i) == ' ')){
177 var Temp = OutString.charAt(i);
178 Temp = Temp.toUpperCase();
179 OutString = OutString.substring(0, i) + Temp + OutString.substring(i+1, OutString.length);
183 function CheckAnswer(CheckType){
185 if (GuessSequence.length < 1){
187 ShowMessage(NextCorrect + '<br /><span class="Answer">' + FindSegment(Answers[0][0]) + '</span>');
197 var WhichCorrect = -1;
199 var LongestCorrectBit = '';
200 TempCorrect = new Array();
201 LongestCorrect = new Array();
203 var HintToReturn = 1;
204 var OtherAnswers = '';
207 for (i=0; i<Answers.length; i++){
208 TempCorrect.length = 0;
209 for (j=0; j<Answers[i].length; j++){
210 if (Answers[i][j] == GuessSequence[j]){
211 TempCorrect[j] = GuessSequence[j];
214 TempHint = Answers[i][j];
218 if ((TempCorrect.length == GuessSequence.length)&&(TempCorrect.length == Answers[i].length)){
224 if (TempCorrect.length > LongestCorrect.length){
225 LongestCorrect.length = 0;
226 for (k=0; k<TempCorrect.length; k++){
227 LongestCorrect[k] = TempCorrect[k];
229 HintToReturn = TempHint;
233 if (WhichCorrect > -1){
235 for (i=0; i<Answers.length; i++){
236 if (i!=WhichCorrect){
237 OtherAnswers += '<br />' + CompileString(Answers[i]);
241 WellDone = '<span class="Answer">' + Output + '</span><br /><br />' + CorrectResponse + '<br />';
243 if (AnswersTried.length > 0){AnswersTried += ' | ';}
244 AnswersTried += Output;
246 //Do score calculation here
247 Score = Math.floor(((Segments.length-Penalties) * 100)/Segments.length);
248 WellDone += YourScoreIs + ' ' + Score + '%.<br />';
251 if (OtherAnswers.length > 0){
252 WellDone += TheseAnswersToo + '<span class="Answer">' + OtherAnswers + '</span>';
256 WriteToGuess(WellDone);
257 ShowMessage(WellDone);
261 var WrongGuess = CompileString(GuessSequence);
262 if (AnswersTried.length > 0){AnswersTried += ' | ';}
263 AnswersTried += WrongGuess;
264 TryAgain = '<span class="Answer">' + WrongGuess + '</span><br /><br />';
266 TryAgain += IncorrectResponse + '<br />';
269 if (LongestCorrect.length > 0){
271 LongestCorrectBit = CompileString(LongestCorrect);
272 GuessSequence.length = LongestCorrect.length;
273 TryAgain += ThisMuchCorrect + '<br /><span class="Answer">' + LongestCorrectBit + '</span><br />';
275 //These lines added for 6.0.3.44
276 WriteToGuess('<span class="Answer">' + LongestCorrectBit + '</span>');
279 GuessSequence.length = 0;
284 TryAgain += NextCorrect + '<br /><span class="Answer">' + FindSegment(HintToReturn) + '</span>';
289 DisplayExercise(Exercise);
290 ShowMessage(TryAgain);
291 Penalties++; //Penalty for inaccurate check
294 if (TimeOver == true){
295 Score = Math.floor(((LongestCorrect.length-Penalties) * 100)/Segments.length);
296 if (Score < 0){Score = 0;}
297 ShowMessage(YourScoreIs + ' ' + Score + '%.<br />');
302 //If the exercise is over, deal with that
303 if ((AllDone == true)||(TimeOver == true)){
305 setTimeout('SendResults(' + Score + ')', 50);
308 window.clearInterval(Interval);
313 setTimeout('Finish()', SubmissionTimeout);
314 WriteToInstructions(YourScoreIs + ' ' + Score + '%.');
317 if (AllDone == true){
321 SetScormIncomplete();
326 function FindSegment(SegID){
328 for (var i=0; i<Segments.length; i++){
329 if (Segments[i][1] == SegID){
330 Seg = Segments[i][0];
338 RemoveBottomNavBarForIE();
340 //Stash the instructions so they can be redisplayed
341 strInstructions = document.getElementById('InstructionsDiv').innerHTML;
352 PreloadImages([PreloadImageList]);
355 Segments = Shuffle(Segments);
357 //Build and show the exercise
359 DisplayExercise(Exercise);
367 function BuildExercise(){
373 for (var i=0; i<Segments.length; i++){
374 //if the segment hasn't been used yet
375 if (Segments[i][2] == 0){
376 TempRow = SegmentTemplate;
377 TempRow = TempRow.replace(/\[SegmentNumber\]/g, Segments[i][1]);
378 TempRow = TempRow.replace(/\[CurrentSegment\]/g, Segments[i][0]);
383 //Make it into a table
387 function DisplayExercise(StuffToDisplay){
388 document.getElementById('SegmentDiv').innerHTML = StuffToDisplay;
397 document.getElementById('Timer').innerHTML = '[strTimesUp]';