<script type="text/javascript">
var score = 0;
var questions = [
['What do Piggy Banks hold?', 'money'],
['What sign represents pounds?', '£'],
['What sign represents dollars', '$']
];
function askQuestion(question) {
var anwser = prompt(question[0],'');
if (anwser == question[1]) {
alert('Yes! That’s right');
score++;
} else {
alert('Sorry :( That seems to be wrong, the answer was ' + question[1]);
}
}
for (var i=0; i<questions.length; i++) {
askQuestion(questions[i]);
}
</script>
Then in one of my div's i exercuted the following code...
<script type="text/javascript"> var message = 'You got ' + score; message += ' out of ' + questions.length; message += ' questions correct.'; document.write(message); </script>
My problem is the page doesnt display as the quiz exercutes, because its in the head tag, so how could i format my code so the page loads then the javascript loads, i tried putting the code in the head moved to the footer but then the scoring display is already exercuted.


Sign In
Create Account

Back to top









