Click here to Skip to main content
15,905,875 members
Home / Discussions / Web Development
   

Web Development

 
QuestionUsing Paypal Pin
Mohammad A Gdeisat25-Apr-09 4:30
Mohammad A Gdeisat25-Apr-09 4:30 
AnswerRe: Using Paypal Pin
Yusuf25-Apr-09 9:44
Yusuf25-Apr-09 9:44 
AnswerRe: Using Paypal Pin
SayreCC26-Apr-09 18:00
SayreCC26-Apr-09 18:00 
AnswerRe: Using Paypal Pin
Marc Firth26-Apr-09 22:26
Marc Firth26-Apr-09 22:26 
QuestionHtml-iFrame-Javascript Pin
LordLothar25-Apr-09 4:06
LordLothar25-Apr-09 4:06 
AnswerRe: Html-iFrame-Javascript Pin
Yusuf25-Apr-09 9:47
Yusuf25-Apr-09 9:47 
GeneralRe: Html-iFrame-Javascript Pin
LordLothar25-Apr-09 22:23
LordLothar25-Apr-09 22:23 
QuestionFading news Pin
Ahmad Hamid24-Apr-09 21:33
Ahmad Hamid24-Apr-09 21:33 
AnswerRe: Fading news Pin
Yusuf25-Apr-09 9:48
Yusuf25-Apr-09 9:48 
GeneralRe: Fading news Pin
Ahmad Hamid25-Apr-09 17:39
Ahmad Hamid25-Apr-09 17:39 
GeneralRe: Fading news Pin
Marc Firth26-Apr-09 22:32
Marc Firth26-Apr-09 22:32 
QuestionInstall ActiveX Pin
p_196024-Apr-09 21:28
p_196024-Apr-09 21:28 
AnswerCross Posted Pin
led mike27-Apr-09 4:38
led mike27-Apr-09 4:38 
QuestionUDDI Pin
daniel kuperberg24-Apr-09 21:11
daniel kuperberg24-Apr-09 21:11 
AnswerRe: UDDI Pin
Yusuf25-Apr-09 9:51
Yusuf25-Apr-09 9:51 
QuestionJavaScript: Need help understanding what's happening in this loop. Pin
durango7724-Apr-09 13:38
durango7724-Apr-09 13:38 
I want to use a script on my website that scores a multiple choice test, and what I have works pretty well. Before I use this script I want to make sure I understand everything it's doing. I understand most of what is happening, but I don't understand this particular loop:
for (i = 0; i < numberOfQuestions; i++) {
    currentElt = i * numberOfChoices;
    for (j = 0; j < numberOfChoices; j++) {
        currentSelection = form.elements[currentElt + j];
        if (currentSelection.checked) {
            if (currentSelection.value == correctAnswers[i]) {
                numberCorrect++;
                break;
            }
        }
    }
}


I understand that the first for loop is running through each question, but what is currentElt and why is it equal to the question times the number of answers? What is the second for loop doing with the numberOfChoices variable. The full script is below:
<script type="text/javascript">
        /*<![CDATA[*/
        var numberOfQuestions = 10;
        var numberOfChoices = 4;
        var correctAnswers = new Array(10);
        correctAnswers = ["a", "b", "b", "a", "d", "a", "b", "b", "a", "c"];
        function scoreQuiz(form) {
            if (outOfTime == true) {
                window.alert("You have exceeded the time limit of the test." + "\n" + "Please try again.");
                return true;
            }
            var numberCorrect = 0;
            var currentElt;
            var currentSelection;
            for (i = 0; i < numberOfQuestions; i++) {
                currentElt = i * numberOfChoices;
                for (j = 0; j < numberOfChoices; j++) {
                    currentSelection = form.elements[currentElt + j];
                    if (currentSelection.checked) {
                        if (currentSelection.value == correctAnswers[i]) {
                            numberCorrect++;
                            break;
                        }
                    }
                }
            }
            form.correct.value = numberCorrect;
            form.percentage.value = ((numberCorrect / numberOfQuestions) * 100) + "%";
        }
        var remainingTime = 600000;
        var outOfTime = false;
        function timeLeft() {
            if (remainingTime <= 0) {
                outOfTime = true;
            }
            else {
                setTimeout("timeLeft()", (remainingTime));
                remainingTime -= 1;
            }
        }
        /*]]>*/
    </script>

If anyone can help me understand this, or show me a better (simpler?) method of achieving the same thing I would greatly appreciate it.
AnswerRe: JavaScript: Need help understanding what's happening in this loop. Pin
Parinay Bansal24-Apr-09 18:41
Parinay Bansal24-Apr-09 18:41 
GeneralRe: JavaScript: Need help understanding what's happening in this loop. Pin
durango7725-Apr-09 3:40
durango7725-Apr-09 3:40 
Questionjavscipt: hex to string conversion problem: Pin
Parinay Bansal24-Apr-09 10:35
Parinay Bansal24-Apr-09 10:35 
Questionhelp me Pin
tidelgl24-Apr-09 7:08
tidelgl24-Apr-09 7:08 
AnswerRe: help me Pin
Rolando CC24-Apr-09 7:50
professionalRolando CC24-Apr-09 7:50 
AnswerRe: help me Pin
Yusuf24-Apr-09 10:18
Yusuf24-Apr-09 10:18 
QuestionAuthorization Required Pin
p_196023-Apr-09 20:56
p_196023-Apr-09 20:56 
AnswerRe: Authorization Required Pin
Paddy Boyd24-Apr-09 1:54
Paddy Boyd24-Apr-09 1:54 
AnswerRe: Authorization Required Pin
Yusuf24-Apr-09 6:10
Yusuf24-Apr-09 6:10 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.