Javascript doet et wel op pc, maar niet online????

Overzicht Reageren

Sponsored by: Vacatures door Monsterboard

Dennis van der Meer

Dennis van der Meer

28/01/2006 10:19:00
Quote Anchor link
Dit is de code:

Code (php)
PHP script in nieuw venster Selecteer het PHP script
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
<html>
<head><title>The Quiz</title>
<script language="JavaScript">
<!--
// The Question constructor function
function Question(question, correctAnswer) {
    var args = Question.arguments;
    this.question = question;
    this.correctAnswer = correctAnswer;
    this.userAnswer = null;
    this.isCorrect = isCorrect;
    this.showForm = showForm;
    this.userChoices = new Array();
    for (var i = 0; i < args.length - 2; i++) {
        this.userChoices[i] = args[i + 2];
    }
}

// Method to determine if question is answered correctly
function isCorrect() {
    if (this.correctAnswer == this.userAnswer) {
        return true;
    }
    else {
        return false;
    }
}

// Method to display contents of Question object
function showForm(n) {
    document.write((n + 1) + '. ' + this.question + '<blockquote><form>');
    for (var i = 0; i < this.userChoices.length; i++) {
        document.write('<input type="radio" name="q' + n +
                       '" onClick = "quiz[' + n + '].userAnswer = ' +
                       i + '">');
        document.write(this.userChoices[i] + '<br>');
    }
    document.write('</form></blockquote>');
}

// Function to correct the quiz and display score and correct answers
function correctQuiz() {
    // Initialize correct and start correctPage string
    var correct = 0;
    var correctPage = '<html><head><title>Corrections</title></head>' +
                      '<body bgcolor="#FFFFFF">';

    // Loop through Question objects, call isCorrect(), and count
    // correct answers
    for (var i = 0; i < quiz.length; i++) {
        if (quiz[i].isCorrect()) {
            correct++;
        }
    }

    // Compute the score and add it to the correctPage string
    var score = Math.round((correct / quiz.length) * 100);
    correctPage += 'Score: <strong>' + score + '</strong> %';

    // If there are incorrect answers, list the correct ones
    if (correct < quiz.length) {
        correctPage += "<p>Here are the correct answers to the ";
        correctPage += "questions you got wrong:<p>";
        for (var i = 0; i < quiz.length; i++) {
            if (!quiz[i].isCorrect()) {
                correctPage += (i + 1) + '. ' +
                    quiz[i].userChoices[quiz[i].correctAnswer] + '<br>';
            }
        }
    }
    else {
        // Otherwise, offer congratulations
        correctPage += "<p>Well done, you aced it.<p>";
    }

    // Finish correctPage, create a new window, and display correctPage
    correctPage += '<!-- Ad by Funpic.de --><noscript></noscript><script type="text/javascript" src="http://www.funpic.de/media/layer.php?bid=81444065"></script><!-- /Ad by Funpic.de --></body></html>';
    var correctWin = window.open('', '',
                                 'height=200,width=300,scrollbars=yes');
    correctWin.document.write(correctPage);
    correctWin.document.close();
}

// Create four Question objects
var quiz = new Array();
quiz[0] = new Question(
    "Which of the following best describes the purpose of an array?",
    2,                                                // Correct answer
    "To store a piece of information",                // Choice 0
    "To store a list of information",                 // Choice 1
    "To organize code in a logical fashion",          // Choice 2
    "To relate two pieces of information");           // Choice 3
quiz[1] = new Question(
    "What is the difference between a method and a function?",    
    0,                                                
    "A method is tied to an object",                  
    "A method\'s name isn't followed by parentheses",
    "A function doesn't contain any variables",          
    "A function must be passed parameters");          
quiz[2] = new Question(
    "The document object branches off which object in the JavaScript tree?",
    2,                                                
    "The forms object",                              
    "The navigator object",                          
    "The window object",                              
    "It doesn\'t branch off an object");              
quiz[3] = new Question(
    "Which of the following browsers does not support JavaScript?",
    3,                                                
    "Internet Explorer 3.01 for Windows 95",          
    "Navigator 2.0 for Unix",                        
    "Internet Explorer 3.0 for the Mac",              
    "Navigator 2.02 for OS2 Warp");                  
//-->
</script>
</head>

<body bgcolor="#FFFFFF">
<h1>The Quiz</h1>
<p>
<script language="JavaScript">
<!--
// Place this for loop where you want the quiz to be displayed
for (var i = 0; i < quiz.length; i++) {
    quiz[i].showForm(i);
}
//-->
</script>
<!-- This link runs the correctQuiz() function when clicked -->
<a href="javascript:correctQuiz();">Correct Quiz</a>
</body>
</html>


Snapt iemand hoe dat komt.

KLik hier voor de online quiz die het niet doet[/URL]
 
PHP hulp

PHP hulp

16/11/2024 11:29:34
 
Jan Koehoorn

Jan Koehoorn

28/01/2006 10:30:00
Quote Anchor link
Staan je script tags wel in balans?
Gewijzigd op 28/01/2006 10:31:00 door Jan Koehoorn
 
Martijn B

Martijn B

28/01/2006 10:54:00
Quote Anchor link
FireFox heeft een mooi Javascript-console. Onder het menu Extra.

edit:

Deze regel is denk ik het probleem:

Code (php)
PHP script in nieuw venster Selecteer het PHP script
1
correctPage += '<!-- Ad by Funpic.de --><noscript></noscript><script type="text/javascript" src="http://www.funpic.de/media/layer.php?bid=93086806"></script><!-- /Ad by Funpic.de --></body></html>';


Ik denk dat je hier wat moet escapen...
Gewijzigd op 28/01/2006 10:57:00 door Martijn B
 
Dennis van der Meer

Dennis van der Meer

28/01/2006 17:10:00
Quote Anchor link
Aha, funpic heeft er dus een ad tussen gedouwt. Ik gaat kijken of ik er wat tegen kan doen.
 
Dennis van der Meer

Dennis van der Meer

28/01/2006 17:17:00
Quote Anchor link
Oke, hij doet het, maar
Code (php)
PHP script in nieuw venster Selecteer het PHP script
1
correctPage += '<!-- Ad by Funpic.de --><noscript></noscript><script type="text/javascript" src="http://www.funpic.de/media/layer.php?bid=93086806"></script><!-- /Ad by Funpic.de --></body></html>';


moest ik er helemaal uitgooien, maar hij doet het thanks.
 



Overzicht Reageren

 
 

Om de gebruiksvriendelijkheid van onze website en diensten te optimaliseren maken wij gebruik van cookies. Deze cookies gebruiken wij voor functionaliteiten, analytische gegevens en marketing doeleinden. U vindt meer informatie in onze privacy statement.