Forum Discussion
Rank numeric values and show the top 3
I like to rank numeric values with a Javascript. I have a result page with 4 different variables. I like to rank the values and show the top 3 values. I used Javascript, but it doesn´t work. Can anybody help me? I attached my code. The problem is that the 3 textboxes I created do not show the ranked values. I appreciate any help ;-).
// Get the variables value out of Storyline project
var varValueName1 = player.GetVar("Name1");
var varValueName2 = player.GetVar("Name2");
var varValueName3 = player.GetVar("Name3");
var varValueName4 = player.GetVar("Name4");
// Create an array of your variables
var varArray = [varValueName1, varValueNam2, varValueName3, varValueName4];
// Use the sort() method with a custom comparison function varArray.sort(function(a, b) { return b - a; // Sort in descending order });
// Update the content of textboxes with the sorted values document.getElementById("Text-feld1").textContent = varArray[0]; document.getElementById("Text-feld2").textContent = varArray[1]; document.getElementById("Text-feld3").textContent = varArray[2];
- WaltHamiltonSuper Hero
I think it would be easier to use SetVar to return the values to SL variables, and use references to display them.
- shivapalaniCommunity Member
HI Kristina Barthel,
You have get this javascript references how to explore "Rank numeric values and show the top 3" could you please share me story file or javascript references, it's helpful for me. Thanks
Hi Shiva!
Just wanted to pop in and share that since this discussion is a bit older, Kristina may no longer be subscribed. You're welcome to reach out to her directly if you'd like by clicking on her name and selecting 'Contact Me'.