Exam Application Programming Tutorial Quiz Online Test

Published :
Author :
Adam Khoury
Learn to create a Quiz, Test or Exam software using JavaScript and HTML. The main objective is to give the user multiple choice questions one at a time in sequence and grade them at the end of the exam. Perfect for school classrooms or educational entities online. The multidimensional array tutorial from yesterday is going to come into play within this application build. You can easily add a timer with setInterval(), and apply all the bells and whistles you need using JavaScript. Storing the questions/answers/options in a secure database that PHP can access, is the most practical way to make sure people do not cheat when you need the test to be secure and cheat proof. Ajax requests would be a big part of that interaction with the server. I discuss securing and externalizing the test data more in the video. <!DOCTYPE html> <html> <head> <meta charset="UTF-8"> <style> div#test{ border:#000 1px solid; padding:10px 40px 40px 40px; } </style> <script> var pos = 0, test, test_status, question, choice, choices, chA, chB, chC, correct = 0; var questions = [ [ "What is 10 + 4?", "12", "14", "16", "B" ], [ "What is 20 - 9?", "7", "13", "11", "C" ], [ "What is 7 x 3?", "21", "24", "25", "A" ], [ "What is 8 / 2?", "10", "2", "4", "C" ] ]; function _(x){ return document.getElementById(x); } function renderQuestion(){ test = _("test"); if(pos >= questions.length){ test.innerHTML = "<h2>You got "+correct+" of "+questions.length+" questions correct</h2>"; _("test_status").innerHTML = "Test Completed"; pos = 0; correct = 0; return false; } _("test_status").innerHTML = "Question "+(pos+1)+" of "+questions.length; question = questions[pos][0]; chA = questions[pos][1]; chB = questions[pos][2]; chC = questions[pos][3]; test.innerHTML = "<h3>"+question+"</h3>"; test.innerHTML += "<input type='radio' name='choices' value='A'> "+chA+"<br>"; test.innerHTML += "<input type='radio' name='choices' value='B'> "+chB+"<br>"; test.innerHTML += "<input type='radio' name='choices' value='C'> "+chC+"<br><br>"; test.innerHTML += "<button onclick='checkAnswer()'>Submit Answer</button>"; } function checkAnswer(){ choices = document.getElementsByName("choices"); for(var i=0; i<choices.length; i++){ if(choices[i].checked){ choice = choices[i].value; } } if(choice == questions[pos][4]){ correct++; } pos++; renderQuestion(); } window.addEventListener("load", renderQuestion, false); </script> </head> <body> <h2 id="test_status"></h2> <div id="test"></div> </body> </html>