Forum Discussion
A Solution to rounding in Storyline – without using Javascript
See attahced a file that uses JS to round the input from a numeric entry.
this only seems to round up to one decimal place not to a whole number am i missing something?
my result = 28.57%
after javascript = 28.6%
- OwenHolt9 years agoSuper Hero
I just tested the JavaScript and it worked as it should for me. Here are a few things to remember:
1) you can't change the StoryLine quiz variables directly. You need to set up your own variable in StoryLine and set it equal to the appropriate StoryLine quiz variable. You can then modify/manipulate your variable.
2) Order matters. Set you variable value equal to StoryLine's quiz variable 1st; as soon as the timeline starts.
3) The timeline you should be using is the slide's timeline.
4) Remember that JavaScript is case sensitive. Also, it is easier to troubleshoot if you perform steps 1 at a time. You will notice that my code performs the math round on its own line before sending the result to StoryLine. This isn't required but makes the code easier to follow and understand and facilitates debugging.- JarrodBriehof-09 years agoCommunity Member
I tested this with a short 6 question quiz. I wanted to see how the rounding would effect the actual quiz results. I made the passing percentage 67%. In testing I got 2 wrong and 4 right in which without rounding would produce a score of 66.66%. I am able to get the score percent to show as 67% and the passing percent shows as 67% but the result slide shows as fail. Am I doing something wrong?
- OwenHolt9 years agoSuper Hero
This is why I don't recommend traditional rounding. Technically, if the user scored 66.66 they did fail. They were close, but they failed. Rounding up to show them 67 on a results slide gives them the impression that they reached the goal when they didn't. StoryLine won't let you access the hard wired quiz results that get passed to the LMS so they will show as failed there. The rounding only manipulates the score that is displayed but not the actual result that is used by the course.
The non traditional rounding method of always rounding down is probably the better practice here. I would recommend using Math.floor(score); in the code instead of Math.round(score);
Math.floor(); will return the number representing the largest integer less than or equal to the specified number.
Math.floor( 66.66); will return 66 and the user fails.
Math.floor( 66.99); will return 66 and the user fails.
Math.floor( 67 ); will return 67 and the user passes.
Math.floor(67.66); // will return 67 and the user passes.
Math.floor(67.9999); // will return 67 and the user passes.