0
   

Need a explanation on what are these code for.

 
 
bgurung
 
Reply Tue 17 May, 2011 02:37 am
function getScore(form) {
var score = 0;
var currElt;
var currSelection;
for (i=0; i<numQues; i++) {
currElt = i*numChoi;
for (j=0; j<numChoi; j++) {
currSelection = form.elements[currElt + j];
if (currSelection.checked) {
if (currSelection.value == answers) {
score++;
break;
}
}
}
}

score = Math.round(score/numQues*100); // math.round function will return the whole number to the nearest specified value for example 1.9 will show as 2
form.percentage.value = score + "%"; // The score will be displayed in percentage

var correctAnswers = "";
for (i=1; i<=numQues; i++) {
correctAnswers += i + ". " + answers[i-1] + "\r\n";
}
form.solutions.value = correctAnswers;
}
  • Topic Stats
  • Top Replies
  • Link to this Topic
Type: Question • Score: 0 • Views: 863 • Replies: 4
No top replies

 
Ragman
 
  1  
Reply Tue 17 May, 2011 06:15 pm
@bgurung,
Reading it casually, it seems to be a score keeper of perhaps some sort of quiz that gives score in percentages.
0 Replies
 
talk72000
 
  1  
Reply Tue 17 May, 2011 06:29 pm
@bgurung,
This is in C Programming Language. It is program to keep the score for quiz or tests.
maxdancona
 
  1  
Reply Tue 17 May, 2011 07:16 pm
@talk72000,
That is not C. It is JavaScript. You can tell because the function parameters aren't typed, and there are DOM calls.
talk72000
 
  1  
Reply Wed 18 May, 2011 12:04 pm
@maxdancona,
They are so similar anyways.
0 Replies
 
 

Related Topics

 
  1. Forums
  2. » Need a explanation on what are these code for.
Copyright © 2024 MadLab, LLC :: Terms of Service :: Privacy Policy :: Page generated in 0.06 seconds on 12/23/2024 at 12:12:39