Rank and Match Variables in Articulate Storyline / JavaScript

235 views Asked by At

I hope anybody can help. I want to rank (13) scores (variables) that are determined through an assessment. The scores then need to be ranked (descending order) and then match to variables RankOne, RankTwo, etc.

var player = GetPlayer();
1

There are 1 answers

6
MikeM On

Which part are you struggling with?

const scores = [17, 98, 45, 41, 67, 12, 39, 90, 11, 25, 83, 77, 53];

scores.sort().reverse();

const rankOne = scores[0]; 
const rankTwo = scores[1]; 
const rankThree = scores[2];

console.log(rankOne, rankTwo, rankThree);
// 98 90 83

If you don't want to alter scores then copy it instead using [...scores] or slice() before sorting:

const scoresDescending = scores.slice().sort().reverse();