Register    Login    Forum    Search    FAQ

Board index » Programming » JavaScript




 Page 1 of 1 [ 1 post ] 



Author Message
 Post subject: Hii
 Post Posted: Sat Jul 31, 2010 10:08 am 
Offline
n00b
n00b

Joined: Sat Jul 31, 2010 10:03 am
Posts: 1
I need help

how can i make a quize that its MCQ questions and answers would show up randomly each time i reload the page ??

i did a code but i can't figure out how to calculate the score

Code:
<html> <head> <script>

var score=0;

var MCQ =new Array ("What is the only function all C++ programs must contain?<br/>",
"What punctuation is used to signal the beginning and end of code blocks?<br/>",
"What punctuation ends most lines of C++ code?<br/>",
"Which of the following is the correct operator to compare two variables?<br/>",
"Which of the following is not a correct variable type?<br/>");


var Q1=new Array("<form id=\"q1\"><input type=\"radio\" name=\"A\" value=\"A\"/> <label>start()</label><br/>",
"<input  type=\"radio\" name=\"B\" value=\"B\"/><label>system()</label>  <br/>",
"<input  type=\"radio\" name=\"C\" value=\"C\" onClick=\"score()\"  />    <label>main()</label><br/>",
"<input  type=\"radio\" name=\"D\" value=\"D\"/> <label>program()</label></form><br/> <br/>");

var Q2=new Array("<input  type=\"radio\" name=\"c\" value=\"A\" onClick=\"score()\"  /> <label>{ }</label><br/>",
"<input  type=\"radio\" name=\"c\" value=\"B\"/><label>-> and <-</label>",
"<br/><input  type=\"radio\" name=\"c\" value=\"C\"/> <label>BEGIN and END</label><br/>",
"<input  type=\"radio\" name=\"c\" value=\"D\"/> <label>(and)</label> <br/> <br/>");



var Q3=new Array("<input  type=\"radio\" name=\"c\" value=\"A\"/> <label>(dot)</label><br/>",
"<input  type=\"radio\" name=\"c\" value=\"B\" onClick=\"score()\" /><label>;(Semi colon)</label>",
"<br/><input  type=\"radio\" name=\"c\" value=\"C\"/> <label>:(Colon)</label><br/>",
"<input  type=\"radio\" name=\"c\" value=\"D\"/> <label>'(Single quote)</label> <br/> <br/>");



var Q4=new Array("<input  type=\"radio\" name=\"c\" value=\"A\"/> <label>:=</label><br/>",
"<input  type=\"radio\" name=\"c\" value=\"B\"/><label>=</label>",
"<br/><input  type=\"radio\" name=\"c\" value=\"C\"/> <label>Equal</label><br/>",
"<input  type=\"radio\" name=\"c\" value=\"D\" onClick=\"score()\" /> <label>==</label> <br/> <br/>");



 
var Q5=new Array("<input  type=\"radio\" name=\"c\" value=\"A\"/> <label>float</label><br/>",
"<input  type=\"radio\" name=\"c\" value=\"B\" onClick=\"score()\" /><label>real</label>",
"<br/><input  type=\"radio\" name=\"c\" value=\"C\"/> <label>int</label><br/>",
"<input  type=\"radio\" name=\"c\" value=\"D\"/> <label>double</label> <br/> <br/>");








function DisplayQuestions() {
   

   dis: for(var i=0;i<100;i++) {
            var Q = Math.floor(Math.random()*5);
               
                if(MCQ[Q]==null)
                continue dis;
            else {
                 
                  document.writeln( MCQ[Q]);
                 
                  if(Q==0){
           
           ans1:  for(var j=0;j<=100;j++){
                  var r = Math.floor(Math.random()*4);
                  if(Q1[r]==null)
                  continue ans1;
                  else  {document.writeln(Q1[r]);
                  Q1[r]=null;} document.write("<br/>") }
                  }
       
         else     if(Q==1){
                 ans2: for(var a=0;a<=100;a++){
                  r = Math.floor(Math.random()*4);
                  if(Q2[r]==null)
                  continue ans2;
                  else {document.writeln(Q2[r]);
                  Q2[r]=null;} document.write("<br/>");}
                  }//end if



                 if(Q==2){
                 ans3: for(var a=0;a<=100;a++){
                  r = Math.floor(Math.random()*4);
                  if(Q3[r]==null)
                  continue ans3;
                  else {document.writeln(Q3[r]);
                  Q3[r]=null;} document.write("<br/>");}
                  }//end if



if(Q==3){
                 ans4: for(var a=0;a<=100;a++){
                  r = Math.floor(Math.random()*4);
                  if(Q4[r]==null)
                  continue ans4;
                  else {document.writeln(Q4[r]);
                  Q4[r]=null;} document.write("<br/>");}
                  }//end if




if(Q==4){
                 ans5: for(var a=0;a<=100;a++){
                  r = Math.floor(Math.random()*4);
                  if(Q5[r]==null)
                  continue ans5;
                  else {document.writeln(Q5[r]);
                  Q5[r]=null;} document.write("<br/>");}
                  }//end if

                  } MCQ[Q]=null; 

     document.write("<br/>"); }}

DisplayQuestions()

function score(){
score++;}

function CheckAns(){
document.write(score);

}     

</script>
</head>
<body>






<input type = "submit" name = "submit" value = "Submit" onClick="CheckAns()" /> <input type = "reset" name = "reset" value = "Reset"
</body></html>


Top 
Display posts from previous:  Sort by  
 
 Page 1 of 1 [ 1 post ] 




Board index » Programming » JavaScript


Who is online

Users browsing this forum: No registered users and 1 guest

 
 

 
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Jump to: