# Randomizing the quiz questions

**URL:** <https://forum.kirupa.com/t/randomizing-the-quiz-questions/204238>\
**Category:** flash\
**Created:** [October 18, 2006, 9:09am UTC](https://forum.kirupa.com/t/randomizing-the-quiz-questions/204238 "2006-10-18T09:09:44Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![cabomba](https://avatars.discourse-cdn.com/v4/letter/c/6f9a4e/32.png) [@cabomba](https://forum.kirupa.com/u/cabomba)\
**Post date:** [October 18, 2006, 9:09am UTC](https://forum.kirupa.com/t/randomizing-the-quiz-questions/204238/1 "2006-10-18T09:09:44Z")

</div>

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!

---

<div class="post-metadata">

**Author:** ![cabomba](https://avatars.discourse-cdn.com/v4/letter/c/6f9a4e/32.png) [@cabomba](https://forum.kirupa.com/u/cabomba)\
**Post date:** [October 25, 2006, 2:06am UTC](https://forum.kirupa.com/t/randomizing-the-quiz-questions/204238/2 "2006-10-25T02:06:57Z")

</div>

:jail: Anyone can help? Pretty please?! I’m stuck with this question for a very long time! Pls help me?

---

<div class="post-metadata">

**Author:** ![stringy](https://avatars.discourse-cdn.com/v4/letter/s/919ad9/32.png) [@stringy](https://forum.kirupa.com/u/stringy)\
**Post date:** [October 25, 2006, 6:13am UTC](https://forum.kirupa.com/t/randomizing-the-quiz-questions/204238/3 "2006-10-25T06:13:40Z")

</div>

> [@cabomba;1984864](#):
>
> :jail: Anyone can help? Pretty please?! I’m stuck with this question for a very long time! Pls help me?

```auto
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

```auto
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

```

---

<div class="post-metadata">

**Author:** ![cabomba](https://avatars.discourse-cdn.com/v4/letter/c/6f9a4e/32.png) [@cabomba](https://forum.kirupa.com/u/cabomba)\
**Post date:** [October 26, 2006, 1:31am UTC](https://forum.kirupa.com/t/randomizing-the-quiz-questions/204238/4 "2006-10-26T01:31:33Z")

</div>

Thanks for the helpful reply…I’ll go and try it out!
