4 Replies Latest reply on Mar 22, 2010 10:48 AM by kglad

# comparing 10 variables and listing top 3

I am making a scoreboard.  On this scoreboard I will have 10 different scores.  I want to compare the 10 scores and list the top 3 scores in another location.

I am unsure howto write this.

I was thinking at first

if(score1>score2&&score1>score3&&score1>score4 etc.....){

some function

}

but this will only give me the top score in the group.  I would like to find the top 3 scores, and then list them.

Any suggestions?

Thanks!

D

• ###### 1. Re: comparing 10 variables and listing top 3

push your scores into an array and sort the array.

• ###### 2. Re: comparing 10 variables and listing top 3

I have heard that before, but I am not sure how to do that...

any suggested links or posts that I can reference?

• ###### 3. Re: comparing 10 variables and listing top 3

figured it out.

(sxTotal is a variable of a dynamic text box).

var totalScoreArray = new Array();
totalScoreArray[0] = s1Total
totalScoreArray[1] = s2Total
totalScoreArray[2] = s3Total
totalScoreArray[3] = s4Total
totalScoreArray[4] = s5Total
totalScoreArray[5] = s6Total
totalScoreArray[6] = s7Total
totalScoreArray[7] = s8Total
totalScoreArray[8] = s9Total
totalScoreArray[9] = s10Total
totalScoreArray[10] = s11Total
totalScoreArray.sort(Array.DESCENDING | Array.NUMERIC);
if (totalScoreArray[0]==s3Total){
trace("team 3 is in First Place!")
}

• ###### 4. Re: comparing 10 variables and listing top 3

you might consider using a for-loop:

var totalScoreArray:Array=[];

for(var i:Number=0;i<10;i++){

totalScoreArray.push(this["s"+(i+1)+"Total"]);

}