Sort Variables and Match to Variables in Articulate Storyline w/ Javascript
Apr 17, 2022
Hello,
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.
This is how far I got:
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;
}
// 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] + "<br >" ) ;
// for descending order
data1.reverse(data1.sort());
// for ascending order
data1.sort();
player.SetVar("OrderScore",data);
4 Replies
Hi,
I hope anybody can help me ascending descending sorting using javascript in storyline, if please share some refences file its helps to lots, Thanks in Advance
Do you only need numbers in Rank 1,2, etc or do you need to know the variable name?
Hi Phil mayor,
Thanks for your reply, I needed only rank numbers in highest to lowest "Example 5, 9, 1, o, To o, 1,5, 9" please refer attached references, if variable name also fine, Thanks
sort numbers in lowest to highest or highest to lowest if any for your reference i have attached snapshot and story file, i have used storyline triggers but i need to use sort a JavaScript array method, if it's possible please can you share the same in my story file i have attached, Any help would be greatly appreciated, Thanks