Savard
07-30-2010, 06:10 AM
Hi
PLZ HELP ME :(
this code is for randomly showing questions of a quize, but it's not working??!!!
<html> <head> <script>
function DisplayQuestions() {
var MCQ = new Array(5);
MCQ[0] =document.getElementById("Q1");
MCQ[1] =document.getElementById( "Q2");
MCQ[2] =document.getElementById( "Q3");
MCQ[3] =document.getElementById( "Q4");
MCQ[4] = document.getElementById("Q5");
var i = 0;
for(i=0;i<5;i++) {
var Q = Math.floor(1+Math.random()*5);
if (MCQ[Q] !=null ) {
document.writeln("Question number " + Q + " is " + MCQ[Q]);
i++;}
MCQ[Q] = null; // Dump this question - it's been displayed
}
}
function CheckAns(){
var myQuiz = document.getElementById( "Quiz" );
var g=0;
// determine whether the answer is correct
if ( Quiz.elements[ 2 ].checked )
g++;
}
</script>
</head>
<body>
<form id = "Quiz" onsubmit = "CheckAns()" action = "">
<p id="Q1"> What is the only function all C++ programs must contain? <br/>
<input type="radio" name="c" value="A"/> <label>A.start()</label> <br/>
<input type="radio" name="c" value="B"/><label>B.system()</label> <br/>
<input type="radio" name="c" value="C"/> <label>C.main()</label><br/>
<input type="radio" name="c" value="D"/> <label>D.program()</label><br/>
<input type = "submit" name = "submit" value = "Submit" />
<input type = "reset" name = "reset" value = "Reset" />
</p>
<p id="Q2"> What punctuation is used to signal the beginning and end of code blocks? <br/>
<input type="radio" name="c" value="A"/> <label>A.{ }</label> <br/>
<input type="radio" name="c" value="B"/><label>B.-> and <-</label> <br/>
<input type="radio" name="c" value="C"/> <label>C.BEGIN and END</label><br/>
<input type="radio" name="c" value="D"/> <label>D.(and)</label><br/>
<input type = "submit" name = "submit" value = "Submit" />
<input type = "reset" name = "reset" value = "Reset" />
</p>
<p id="Q3"> Which of the following is a correct comment? <br/>
<input type="radio" name="c" value="A"/> <label>A.*/ Comments */</label> <br/>
<input type="radio" name="c" value="B"/><label>B.** Comment **</label> <br/>
<input type="radio" name="c" value="C"/> <label>C./* Comment */</label><br/>
<input type="radio" name="c" value="D"/> <label>D.{ Comment }</label><br/>
<input type = "submit" name = "submit" value = "Submit" />
<input type = "reset" name = "reset" value = "Reset" />
</p>
</form>
</body></html>
PLZ HELP ME :(
this code is for randomly showing questions of a quize, but it's not working??!!!
<html> <head> <script>
function DisplayQuestions() {
var MCQ = new Array(5);
MCQ[0] =document.getElementById("Q1");
MCQ[1] =document.getElementById( "Q2");
MCQ[2] =document.getElementById( "Q3");
MCQ[3] =document.getElementById( "Q4");
MCQ[4] = document.getElementById("Q5");
var i = 0;
for(i=0;i<5;i++) {
var Q = Math.floor(1+Math.random()*5);
if (MCQ[Q] !=null ) {
document.writeln("Question number " + Q + " is " + MCQ[Q]);
i++;}
MCQ[Q] = null; // Dump this question - it's been displayed
}
}
function CheckAns(){
var myQuiz = document.getElementById( "Quiz" );
var g=0;
// determine whether the answer is correct
if ( Quiz.elements[ 2 ].checked )
g++;
}
</script>
</head>
<body>
<form id = "Quiz" onsubmit = "CheckAns()" action = "">
<p id="Q1"> What is the only function all C++ programs must contain? <br/>
<input type="radio" name="c" value="A"/> <label>A.start()</label> <br/>
<input type="radio" name="c" value="B"/><label>B.system()</label> <br/>
<input type="radio" name="c" value="C"/> <label>C.main()</label><br/>
<input type="radio" name="c" value="D"/> <label>D.program()</label><br/>
<input type = "submit" name = "submit" value = "Submit" />
<input type = "reset" name = "reset" value = "Reset" />
</p>
<p id="Q2"> What punctuation is used to signal the beginning and end of code blocks? <br/>
<input type="radio" name="c" value="A"/> <label>A.{ }</label> <br/>
<input type="radio" name="c" value="B"/><label>B.-> and <-</label> <br/>
<input type="radio" name="c" value="C"/> <label>C.BEGIN and END</label><br/>
<input type="radio" name="c" value="D"/> <label>D.(and)</label><br/>
<input type = "submit" name = "submit" value = "Submit" />
<input type = "reset" name = "reset" value = "Reset" />
</p>
<p id="Q3"> Which of the following is a correct comment? <br/>
<input type="radio" name="c" value="A"/> <label>A.*/ Comments */</label> <br/>
<input type="radio" name="c" value="B"/><label>B.** Comment **</label> <br/>
<input type="radio" name="c" value="C"/> <label>C./* Comment */</label><br/>
<input type="radio" name="c" value="D"/> <label>D.{ Comment }</label><br/>
<input type = "submit" name = "submit" value = "Submit" />
<input type = "reset" name = "reset" value = "Reset" />
</p>
</form>
</body></html>