Can anyone tell me what is going wrong here? The if statements are not executing, the code is part of a quiz where each question and answer looks like the included html, the function is supposed to create a summary of what percentage of points was attained.
function CreateSummary() {
var possiblePoints = 0;
var claimedPoints=0;
var intManual=0;
for (var i=0;i < intTotalQuestions;i++) {
var objQuestion = document.getElementById('divQuestion' + i);
if (objQuestion == null) {
alert('Null! ' + i); }
console.log(objQuestion)
for (var j=0;j<objQuestion.getElementsByTagName('input').length;j++) {
var objCurrentAnswer = objQuestion.getElementsByTagName('input')[j];
console.log(objCurrentAnswer)
if (objCurrentAnswer.correct == "1" && objCurrentAnswer.checked) {
console.log("add")
claimedPoints += 1; }
if (objCurrentAnswer.correct == "1") {
console.log("add")
possiblePoints += 1; }
if (objQuestion.getElementsByTagName('textarea').length > 0) {
intManual +=1;
}
}
}
console.log(possiblePoints)
console.log(claimedPoints)
document.getElementById('lblPercentage').innerHTML = 'Percentage: <strong>' + ((possiblePoints/claimedPoints)*100) + '</strong>';
}
<div id="divQuestion0" style="width:100%;height::auto;align:center;background-color:lightyellow;display:block">
<div ><span>You should use the phrase"calm down" when dealing with an angry or upset individual. </span></div>
<div id="divAnswer0" style="text-align:left;width:100%;padding:20px;"
<span><input value="1" correct=0 id="Q0A0" name="rb0" type="radio" ></input> True</span><br />
<span><input value="2" correct=1 id="Q0A1" name="rb0" type="radio" ></input> False</span><br />
</div>
</div>