Forum Discussion
Hi Steven
I agree with Katherine above. I have no Javascript knowledge and ironically, I have 18 groupings of data that I am trying to generate the top 3 of. This script couldn't be more perfect. I only wish I knew what I was doing wrong.
I have a feeling that I am missing something really simple. For that, I apologize. :)
As instructed, I changed all the "Slider1" and "SliderName_1" to the Variables I set in mine.
Mine are:
1. "A_Counter" (to "R_Counter"). These count every time that a particular group option is chosen throughout the course.
2. "A_name" (to "R_Name") which converts the letter to its complete name. (Example A_Name = Arts and Sciences, B_Name = Science and Technology, etc.)
I have created 3 more variables: "1st", "2nd", and "3rd" for the top 3 ranked letters (which when placed, show the complete name instead of the letter).
What other variables do I need to have for this Javascript to work?
In the attachment - for the sake of ease, I put a random number in each Counter variable to bypass the very long survey that is required to count up the totals.
Slide 1 - is the current manual effort that the Javascript would replace. Currently, the user has to look at the results and manually enter the top three highest scores into text entry boxes.
Slide 2 - Converts the 3 manually entered top letters to their full name. On this slide the learner can Learn more about each group they are most interested in.
In a perfect world we would let the javascript calculate the top three results that are revealed on the 2nd slide. so that we wouldn't need to show the first slide.
What am I missing? I may be missing variables or storyline triggers. I have no idea.
Here is the modified Javascript that Steven provided above with my variables in place. Below is my test story file.
var player = GetPlayer();
var A_Counter = player.GetVar("A_Counter");
var B_Counter = player.GetVar("B_Counter");
var C_Counter = player.GetVar("C_Counter");
var D_Counter = player.GetVar("D_Counter");
var E_Counter = player.GetVar("E_Counter");
var F_Counter = player.GetVar("F_Counter");
var G_Counter = player.GetVar("G_Counter");
var H_Counter = player.GetVar("H_Counter");
var I_Counter = player.GetVar("I_Counter");
var J_Counter = player.GetVar("J_Counter");
var K_Counter = player.GetVar("K_Counter");
var L_Counter = player.GetVar("L_Counter");
var M_Counter = player.GetVar("M_Counter");
var N_Counter = player.GetVar("N_Counter");
var O_Counter = player.GetVar("O_Counter");
var P_Counter = player.GetVar("P_Counter");
var Q_Counter = player.GetVar("Q_Counter");
var R_Counter = player.GetVar("R_Counter");
var A_name = player.GetVar("A_name");
var B_name = player.GetVar("B_name");
var C_name = player.GetVar("C_name");
var D_name = player.GetVar("D_name");
var E_name = player.GetVar("E_name");
var F_name = player.GetVar("F_name");
var G_name = player.GetVar("G_name");
var H_name = player.GetVar("H_name");
var I_name = player.GetVar("I_name");
var J_name = player.GetVar("J_name");
var K_name = player.GetVar("K_name");
var L_name = player.GetVar("L_name");
var M_name = player.GetVar("M_name");
var N_name = player.GetVar("N_name");
var O_name = player.GetVar("O_name");
var P_name = player.GetVar("P_name");
var Q_name = player.GetVar("Q_name");
var R_name = player.GetVar("R_name");
var myarray = [
{ key: A_name, val: A_Counter },
{ key: B_name, val: B_Counter },
{ key: C_name, val: C_Counter },
{ key: D_name, val: D_Counter },
{ key: E_name, val: E_Counter },
{ key: F_name, val: F_Counter },
{ key: G_name, val: G_Counter },
{ key: H_name, val: H_Counter },
{ key: I_name, val: I_Counter },
{ key: J_name, val: J_Counter },
{ key: K_name, val: K_Counter },
{ key: L_name, val: L_Counter },
{ key: N_name, val: M_Counter },
{ key: N_name, val: N_Counter },
{ key: O_name, val: O_Counter },
{ key: P_name, val: P_Counter },
{ key: Q_name, val: Q_Counter },
{ key: R_name, val: R_Counter }
]
myarray.sort(function(a, b){
return b.val - a.val;
});
var Top1Object = myarray[0];
var Top2Object = myarray[1];
var Top3Object = myarray[2];
var Top1DestructuredLabel = Top1Object.key
var Top2DestructuredLabel = Top2Object.key
var Top3DestructuredLabel = Top3Object.key
var Top1DestructuredValue = Top1Object.val
var Top2DestructuredValue = Top2Object.val
var Top3DestructuredValue = Top3Object.val
Top1LabelForStoryline = Top1DestructuredLabel.toString();
Top2LabelForStoryline = Top2DestructuredLabel.toString();
Top3LabelForStoryline = Top3DestructuredLabel.toString();
Top1ValueForStoryline = Top1DestructuredValue.toString();
Top2ValueForStoryline = Top2DestructuredValue.toString();
Top3ValueForStoryline = Top3DestructuredValue.toString();
player.SetVar ("Top3_1_Label",Top1LabelForStoryline);
player.SetVar ("Top3_2_Label",Top2LabelForStoryline);
player.SetVar ("Top3_3_Label",Top3LabelForStoryline);
player.SetVar ("Top3_1_Value",Top1ValueForStoryline);
player.SetVar ("Top3_2_Value",Top2ValueForStoryline);
player.SetVar ("Top3_3_Value",Top3ValueForStoryline);
Any help anyone can provide would be tremendous. Thank you in advance.
Cathy