Hi, I wanted to randomise my quiz questions and to allow all questions to appear but [COLOR=red][COLOR=darkorange][COLOR=red]no[/COLOR] [/COLOR][COLOR=darkorchid]similar questions should appear twice[/COLOR][/COLOR][COLOR=darkorchid].[/COLOR] I tried to use arrays to do it but I kept having errors. So anyone can help me? I’m using xml to store the questions and answers. I’ve attached the fla and the xml file below…so pls take a look and help me with the randomising of the questions. Any help is greatly appreciated, Thanks!
:jail: Anyone can help? Pretty please?! I’m stuck with this question for a very long time! Pls help me?
function onQuizData(success)
{
var quizNode=this.firstChild;
var quizTitleNode=quizNode.firstChild;
title=quizTitleNode.firstChild.nodeValue;
var i=0;
// <items> follows <title>
/*for(a=1; a<=11; a++)
{
//var arr = ["0","1","2","3","4","5","6","7","8","9","10"];
//arr.sort(function(){return Math.floor(Math.random()*3)-1});
}*/var itemsNode=quizNode.childNodes[1];
//var quizNode=itemNode.childNodes[arr];
while (itemsNode.childNodes*)
{
var itemNode=itemsNode.childNodes*;
// <item> consists of <question> and one or more <answer>
// <question> always comes before <answer>s (node 0 of <item>)
var questionNode=itemNode.childNodes[0];
quizItems*=new QuizItem(questionNode.firstChild.nodeValue);
var a=1;
// <answer> follows <question>
var answerNode=itemNode.childNodes[a++];
while (answerNode)
{
var isCorrectAnswer=false;
if (answerNode.attributes.correct=="y")
isCorrectAnswer=true;
quizItems*.addAnswer(answerNode.firstChild.nodeValue, isCorrectAnswer);
// goto the next <answer>
answerNode=itemNode.childNodes[a++];
}
i++;
}
quizItems.sort(shuffle)
gotoAndPlay(_currentFrame+1);
}
function shuffle(){
return Math.floor(Math.random()*3)-1
}
but you will have to take the question number out of the string and have it as a variable
eg
count = 0;
function QuizItem(question) {
this.question = count+" "+question;
this.answers = new Array(i);
this.numOfAnswers = 0;
this.correctAnswer = 0;
this.getQuestion = function() {
count++
this.rq = count+". "+this.question;
return this.rq;
};
//...........etc
Thanks for the helpful reply…I’ll go and try it out!