i have used an array and i need to make sure that 3 questions out of 6 in the array are outputted in the quiz and that the questions are different each time. how do i go about doing this? here is my code so far:
<script langauge="JavaScript">
// number of quiz questions
var totalQuestions = 6;
// storing answers and user answers
var answers = new Array;
var userAnswers = new Array;
// quiz answers
answers[1] = "B";
answers[2] = "C";
answers[3] = "C";
answers[4] = "D";
answers[5] = "B";
answers[6] = "A";
function SetAnswer(questionNumber, answerSelection) {
userAnswers[questionNumber] = answerSelection;
}
// incorrect answers to questions.
function MarkWrongQuestions() {
for(i = 1; i <= totalQuestions; i++) {
if(answers[i] != userAnswers[i]) {
document.getElementById(i).className += " wrong";
}
}
}
// counts and returns number of right answers
function GetScore() {
var score = 0;
for(i = 1; i <= totalQuestions; i++) {
if(userAnswers[i] == answers[i])
score++;
}
return score;
}
// sets classes for each question div to its default styling.
function ApplyDefaultQuestionStyles() {
for(i = 1; i <= totalQuestions; i++) {
if(i % 2 == 0) {
document.getElementById(i).className = "question";
}
else {
document.getElementById(i).className = "question odd";
}
}
}
// calls all appropriate functions in order to check answers and mark
// incorrect questions.
function CheckQuiz() {
ApplyDefaultQuestionStyles();
var totalQuestions = '6';
var score = GetScore();
MarkWrongQuestions();
alert("Your Total Score Is: " + score + " out of " + totalQuestions + ".");
}
function result(score,totalQuestions){
document.write("Score" +score);
}
thanks in advance