0

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();
MikeM
  • 13,156
  • 2
  • 34
  • 47
  • 1
    Please show some **code**: example input (array?), desired output, and your attempt to solve the problem. – MikeM Apr 16 '22 at 22:49
  • ´here's the latest code: var player = GetPlayer(); var Analytical_Score = player.GetVar("Analytical_Score"); var Collaborative_Score = player.GetVar("Collaborative_Score"); var Adaptable_Score = player.GetVar("Adaptable_Score"); var data = [Analytical_Score, Collaborative_Score, Adaptable_Score]; var count = 0; var values = [] ; for (var i = 0; i < data.length; i++) { count = count+1 } var data1 = new Array(); // $.each( data, function( key, value ) { for (var i = 0; i < data.length; i++) { data1[i] = data[i].value; } – Euvouria Apr 17 '22 at 00:26
  • // these code are important for reading the score. need to call these variables after sorting is done // var RankOne = data[0]; // var RankTwo = data[1]; // var RankThree = data[2]; document.write(data[i] + "
    " ) ; // for descending order data1.reverse(data1.sort()); // for ascending order data1.sort(); player.SetVar("OrderScore",data);
    – Euvouria Apr 17 '22 at 00:26
  • Here is the Storyline file: https: // we.tl/t-EypDuJCHXn – Euvouria Apr 17 '22 at 00:29

1 Answers1

0

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();
MikeM
  • 13,156
  • 2
  • 34
  • 47
  • This is a good start but it needs to work with Articulate Storyline. Are you familiar with this software? – Euvouria Apr 17 '22 at 12:58
  • @Euvouria No, I am not. Please edit your question, add your code, and explain how it needs to work with AS. – MikeM Apr 17 '22 at 13:12
  • Do you have Articulate Storyline? The code needs to work within this software. – Euvouria Apr 17 '22 at 13:20
  • I have 13 Variables XX_score. Their scores are determined through an assessment that the user takes. Then, the scores need to be ranked and matched to the variables RankOne, RankTwo, etc. – Euvouria Apr 17 '22 at 13:21
  • How do I post the code? I use ``but it shows up as text. – Euvouria Apr 17 '22 at 13:23
  • @Euvouria I added a bit of code to your question as an example. Please add the rest and further explanation, and then delete any comments you have made which belong in the question. – MikeM Apr 17 '22 at 13:45