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.
----------------------------------------------------------

<html>
<head>
 <title>Sports Quiz</title>
<script> 
 
 //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
   highlightCorrectButton('correct1');
   highlightCorrectButton('correct2');
   highlightCorrectButton('correct3');
 
   //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() {
   document.getElementById('form_id').submit();
}
 
 
</script>
</head>
<body>
 
<form name="counter"><input type="text" size="8" 
name="d2"></form> 
 
<script> 
<!-- 
// 
 var milisec=0 
 var seconds=30 
 document.counter.d2.value='60' 
 
function display(){ 
 if (milisec<=0){ 
    milisec=9 
    seconds-=1 
 } 
 if (seconds<=-1){ 
    milisec=0 
    seconds+=1 
 } 
 else 
    milisec-=1 
    document.counter.d2.value=seconds+"."+milisec 
    setTimeout("display()",100) 
} 
display() 
--> 
</script> 
 
<form name="quiz">
<ol>
<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><br><br>
<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><br><br>
<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><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
</li><br>
</ol><br><br>
 
<center><input type="button" onClick="checkQuiz()" value="check quiz">
<hr>
<textarea cols="80" rows="10" name="output"></textarea></center>
</form>
</body>
</html>

Recommended Answers

All 3 Replies

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

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.