hi all im trying to make a quiz on this..here is my code but cant seem to get it to work Grrrrrrrrr
it gives the user a mark on how he/she performed. This should be time limited and when finished should also display whether the given answers were wrong or correct. The user will get 2 marks for each correct answer, and -1 for each wrong answer. The quiz should consist of 10 questions. The background colour of the page should change according to the awarded mark.

 <title>Sports Quiz</title>
 //highlight color of answer - can change this color to a hex code or recognized color name
var highlightColor = "#00ff00";
//this should not be changed
function checkQuestionDropDown(selectGroup) {
  if (selectGroup[selectGroup.selectedIndex].value == "correct") {
     return 1;
   else {
     return 0;
//this should not be changed
function checkQuestionRadio(radioGroup) {
//go through the radio group sent in and determine if radio button
//checked is "correct". 
//return 1 for correct value, 0 for incorrect
   for (i=0; i<radioGroup.length; i++) {
     if (radioGroup[i].checked) {
       if (radioGroup[i].value == "correct") {
         return 1;
       else {
         return 0;
return 0;
//this should not be changed
function highlightCorrectButton(radioButton) {
   document.getElementById(radioButton).style.backgroundColor = highlightColor;
function checkQuiz() {
   //check each question to see if it's right.
   //The orange highlighted code may need to be changed
   //you will need to match these question types(Radio/DropDown)
   //and names (q1, q2, ...) to the ones in your quiz 
   numCorrect = 0;
   numCorrect += checkQuestionRadio( document.quiz.q1); 
   numCorrect += checkQuestionRadio( document.quiz.q2); 
   numCorrect += checkQuestionRadio( document.quiz.q3); 
   numCorrect += checkQuestionDropDown( document.quiz.q4);
  //highlight correct answers from radio button groups...use span id name
   //produce output in textarea.
   document.quiz.output.value += 
    	"You got " + numCorrect + " out of 4 questions correct.\n" +
    	"Your grade is " + Math.round(100*numCorrect/4) + "%\n" +
    "The answer to question 1 is HyperText Markup Language\n" +
    "The answer to question 2 is Jefferson City\n" +
    "The answer to question 3 is talking\n" +
    "The answer to question 4 is mass\n";
setTimeout('submitForm()', 1*60*1000);
function submitForm() {
<form name="counter"><input type="text" size="8" 
 var milisec=0 
 var seconds=30 
function display(){ 
 if (milisec<=0){ 
 if (seconds<=-1){ 
<form name="quiz">
<li><b>HTML stands for</b>:<br>
  	<input type="radio" name="q1" value="wrong">How To Make Lines
  	<br><input type="radio" name="q1" value="wrong">Hungry Men Talk Lots
   <span id="correct1"><br><input type="radio" name="q1" value="correct">HyperText Markup Language</span>
  	<br><input type="radio" name="q1" value="wrong">Hyper Talk Machine Language
<li><b>The capital of Missourri is</b>:
  	<br><input type="radio" name="q2" value="wrong">St. Louis
  	<span id="correct2"><br><input type="radio" name="q2" value="correct">Jefferson City</span>
  	<br><input type="radio" name="q2" value="wrong">Missourri City
  	<br><input type="radio" name="q2" value="wrong">Omaha
<li><b> What is capital of wales:</b>
  	<span id="correct3"><br><input type="radio" name="q3" value="correct">Cardiff</span>
  	<br><input type="radio" name="q3" value="wrong">hankuva
  	<br><input type="radio" name="q3" value="wrong">hong kong
		<br><input type="radio" name="q3" value="wrong">egypt
</li><br><li><b> What is capital of spain:</b>
  	<span id="correct3"><br><input type="radio" name="q3" value="correct">Ahuhu</span>
  	<br><input type="radio" name="q3" value="wrong">Bchec
  	<br><input type="radio" name="q3" value="wrong">Cdoddoe
		<br><input type="radio" name="q3" value="wrong">quebec
<center><input type="button" onClick="checkQuiz()" value="check quiz">
<textarea cols="80" rows="10" name="output"></textarea></center>

Edited by thepanther: changed code

5 Years
Discussion Span
Last Post by thepanther

the button at the bottom to generate the questions and answers is not working and the time at the top should have message when time runs out....and cant get the background colour to work

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.