0
퀴즈 질문이 포함 된 HTML 페이지가있는 SCORM 1.2 콘텐츠 패키지가 있습니다. 제출 버튼을 클릭하면 자바 스크립트가 점수를 계산하고 다시 돌아옵니다. 내 현재 자바 스크립트는 두 가지 질문에 잘 작동합니다. 그리고 한 페이지에 질문이 더 있으면 새 변수를 포함시켜 자바 스크립트를 수정해야합니다. 나는 'n'질문을 위해 동일한 자바 스크립트를 쓰는 일반적인 방법이 있는지 알고 싶다. 질문의 수의 변화에 관계없이 점수를 계산할 수있다. 고마워.SCORM1.2의 퀴즈 점수 계산을위한 자바 스크립트
내 자바 스크립트 : (calculate.js)
<script type="text/javascript">
<![CDATA[
var numQuestions = 2;
var rawScore = 0;
var actualScore = 0;
var question0;
var question1;
var key0 = 0;
var key1 = 1;
function getAnswer()
{
doLMSSetValue("cmi.interactions.0.id","key0b8");
doLMSSetValue("cmi.interactions.0.type","choice");
doLMSSetValue("cmi.interactions.0.correct_responses.0.pattern",
"0");
for (var i=0; i < 2; i++)
{
if (document.getElementById("quizForm8").key0b8[i].checked)
{
question0 = document.getElementById("quizForm8").key0b8[i].value;
doLMSSetValue("cmi.interactions.0.student_response",question0);
break;
}
}
doLMSSetValue("cmi.interactions.1.id","key1b8");
doLMSSetValue("cmi.interactions.1.type","choice");
doLMSSetValue("cmi.interactions.1.correct_responses.0.pattern",
"1");
for (var i=0; i < 2; i++)
{
if (document.getElementById("quizForm8").key1b8[i].checked)
{
question1 = document.getElementById("quizForm8").key1b8[i].value;
doLMSSetValue("cmi.interactions.1.student_response",question1);
break;
}
}
}
function calcRawScore(){
if (question0 == key0)
{
doLMSSetValue("cmi.interactions.0.result","correct");
rawScore++;
}
else
{
doLMSSetValue("cmi.interactions.0.result","wrong");
}
if (question1 == key1)
{
doLMSSetValue("cmi.interactions.1.result","correct");
rawScore++;
}
else
{
doLMSSetValue("cmi.interactions.1.result","wrong");
}
}
function calcScore2()
{
computeTime(); // the student has stopped here.
document.getElementById("quizForm8").submitB.disabled = true;
getAnswer();
calcRawScore();
actualScore = Math.round(rawScore/numQuestions * 100);
alert("Your score is " + actualScore + "%")
doLMSSetValue("cmi.core.score.raw", actualScore+"");
var mode = doLMSGetValue("cmi.core.lesson_mode");
if (mode != "review" && mode != "browse"){
if (actualScore < 50)
{
doLMSSetValue("cmi.core.lesson_status", "failed");
}
else
{
doLMSSetValue("cmi.core.lesson_status", "passed");
}
doLMSSetValue("cmi.core.exit", "");
}
exitPageStatus = true;
doLMSCommit();
doLMSFinish();
}
]]>
</script>
(X) HTML 페이지 : 당신이 다음 불변 당신의 HTML을 귀하의 자바 스크립트를 유지하려면
<?xml version="1.0" encoding="utf-8"?>
<html xmlns="http://www.w3.org/1999/xhtml">
<!-- Other Code -->
<body>
<div id="outer">
<div class="QuizTestIdevice" id="id8">
<script src="calculate.js" type="text/javascript"></script>
<form name="quizForm8" id="quizForm8" action="javascript:calcScore2();">
<div class="iDevice_inner">
<div class="passrate" value="50"></div>
<div class="question">
<div id="taquestion0b8">
1> TEXT FOR QUESTION 1.
</div><br />
True<input type="radio" name="key0b8" value="0" id="taoptionAnswer0q0b8" />
False<input type="radio" name="key0b8" value="1" id="taoptionAnswer1q0b8" />
</div><br />
<div class="question">
<div id="taquestion1b8">
2> TEXT FOR QUESTION 2.
</div><br />
True<input type="radio" name="key1b8" value="0" id="taoptionAnswer0q1b8" />
False<input type="radio" name="key1b8" value="1" id="taoptionAnswer1q1b8" />
</div><br />
<input type="submit" name="submitB" value="SUBMIT ANSWERS" />
</div>
</form>
</div>
</div>
</body>
</html>