Click here to Skip to main content
15,903,175 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
i want to code the test series in html and javascript in which the random question should appear from database and one by one and then after the test link is closed then all the answers should be display acc to the way question appeared with the solutions. and if the user enter wrong then show correct answer.

What I have tried:

HTML
<meta http-equiv="Content-Language" content="en-us">
<title>Online Quiz

var rightAnswer=new Array();
var questPerPage=2;
var quests=Array("Quest0","Quest1","Quest2","Quest3","Quest4","Quest5","Quest6","Quest7");
var answers=Array();
answers[0]=Array(1,"answer1","answer2","answer3","answer4")
answers[1]=Array(2,"answer5","answer6","answer7","answer8")
answers[2]=Array(3,"answer9","answer10","answer11","answer12")
answers[3]=Array(4,"answer13","answer14","answer15","answer16")
answers[4]=Array(4,"answer17","answer18","answer19","answer20")
answers[5]=Array(3,"answer21","answer22","answer23","answer24")
answers[6]=Array(2,"answer25","answer26","answer27","answer28")
answers[7]=Array(1,"answer29","answer30","answer31","answer32")

function showQuestion(){
htmlStr="";
for(qpp=0;qpp&lt;questPerPage;qpp++){

q=Math.floor(Math.random()*quests.length)
htmlStr+="Q#"+qpp+": "+quests[q]+"<br>A: ";

rightAnswer[qpp]=answers[q][0]-1;

for(a=1;a&lt;answers[q].length;a++){
htmlStr+="<input name='ansr"+qpp+"' type='radio' value=''><label>"+answers[q][a]+"</label>  "
}
htmlStr+="<p>";
}
document.getElementById("myQuiz").innerHTML=htmlStr
}

function check(){
for (ra=0;ra&lt;rightAnswer.length;ra++){
radios=document.getElementsByName("ansr"+ra)
if (radios[rightAnswer[ra]].checked){
alert("The Answer#"+ra+" is correct");
}else{
alert("The Answer#"+ra+" is incorrect");
}
}
showQuestion()
}





<h1>Quiz:</h1>





	

showQuestion()
Posted
Updated 11-Mar-18 5:01am
v2
Comments
OriginalGriff 11-Mar-18 9:26am    
And?
What have you tried?
Where are you stuck?
What help do you need?
Member 13720058 11-Mar-18 10:39am    
i have tried this array method.

i don't know how to put the questions and respective options in one table and answer key in another table and then display questions.

i want that questions and their 4 options should come from database in random but non repeated order.
and once test is over then the user can get the correct option and the explanation for the same way the questions came.

so please can you give the code for the same.

1 solution

Quote:
so please can you give the code for the same.

No, because that's not how it works: We do not do your homework: it is set for a reason. It is there so that you think about what you have been told, and try to understand it. It is also there so that your tutor can identify areas where you are weak, and focus more attention on remedial action.

Have a think about it, and about what you need to do to ensure a non-repeating sequence. Hint: random numbers are just that: random. So you need to generate a list of questions in advance, store it somewhere, and fetch a question at a time from it. Is there anywhere you can store information in Javascript across page boundaries?

If you meet a specific problem, then please ask about that and we will do our best to help. But we aren't going to do it all for you!
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900