Rounding the score variable

Hi guys,

I'm new to Javascript and wondering what I'm doing wrong on the below:

player.getvar ("Results.ScorePercent");

alert ("Variable result is " + player.GetVar("Results.ScorePercent"));

player.setvar ("Results.ScorePercent");

I'm trying to get the Results Percent variable, provide an alert to test the function. I eventually want to round the result to a whole value, and set it back.


14 Replies
Alexandros Anoyatis

At first glance, you are "getvar-ing" twice. The first line can be omitted - although that's not really the problem here, just redundancy.

Instead, I would :

  • Create a new variable (say rounded) which (via trigger or JS, your call) will "inherit" the value of Results.ScorePercent. Then replace the JS code above with this one.
  • var player = GetPlayer();
    var res = player.GetVar("rounded");
    var result = Math.round(res*10)/10;

This would round the number to 1 decimal point. If you want two decimal points then replace (res*10)/10 with (res*100)/100 and so on and so forth.

Also bear in mind you need to upload this to a webserver in order for JS to function correctly.

Hope this helps,

Jason Tilley

Hi, thanks for the replies. Alexandros, if I do this, using trigger I can change the score variable on the results page to read from my new variable. Will this impact uploading of the score? I assume that the system variables will still be submitted to the LMS and what is viewed on the results screen is merely a value.

Is this correct?


Tim Neill

Why is it that - over 3 years on - Storyline is still incapable of rounding a Quiz  score to a whole number?

Javascript is not the answer because Storyline 2 still doesn't trust us to set 'Results.ScorePercent' or 'Results.ScorePoints' to equal our own variable values before sending to an LMS. I've been using authoring tools for 30 years, 18 years with Authorware, and I'm extremely disappointed with SL's lack of some absolutely basic functionality like this.

There really is no excuse and whenever anyone puts their head over the parapet to mention such omissions, they are thanked for 'reaching out' and advised to put in a feature request. This is the equivalent of buying a new car in 2017 and discovering that it doesn't have electric windows or a heater speed control, complaining and then asked to write in ... come on Storyline, start listening and making good on such basic facilities.

I've filled pages with the things I wanted to do in SL2 and can't. I come on this forum and find that many other folk are feeling the same way. What is your problem? Another moan: I've just finished producing a quiz for a client, in which some questions need to mark according to how well the user performed. e.g: labelling a diagram of the body. There are 10 empty boxes and 10 text labels. It's an important question and one which can take a minute to answer carefully. So they place 8 labels correctly but swap the last 2. Their score? Zero. Not 8 out of 10 but a big empty zero. Thanks Storyline. Clever. And please don't suggest splitting the question up into lots of other smaller questions. That's like giving me a handle to wind down my non-electric windows.

Leslie McKerchie

Hi Tim - Sorry to hear that you are so disappointed as we are certainly here to assist. 

As far as rounding your score, you could certainly adjust the score values or total number of questions to be round numbers, for instance, 10 points and 10 questions. I know other users have found a workaround as shown in this thread. I don't pretend to fully understand or dabble in JavaScript, so I'll trust your response there and it wouldn't be my answer anyway :)

We really do like hearing from users and do not intend for you to feel a thank you as anything but that. Internally, we have acknowledged that we'd like to handle feature requests better as well. Check out our current article here to better understand. 

Now, as for your current challenge with the diagram - please feel free to share your .story file as we have many savvy users here that could probably assist with this.

How else do you roll down non-electric windows?


Use your existing slide but have each label  interaction control a hidden T/F question. This way each interaction on the slide is scored. I know this may feel like you're "asking 10 questions" scenario but it really isn't. You are asking 1 but creating 10 very simple hidden slides. I call this a Ghost Assessment and you can read more about it here.

Tim Neill

Thank you Owen. I have had to do this quite a lot in the past as a workaround but it is less than ideal. I have used both an 'auto run-through' of several hidden T/F questions as well as the same technique by setting values in hidden numeric entry question types.

The questions in my quiz are  selected at random from a pool so this workaround doesn't work because the ghost questions following the 'real' question won't be immediately following it. I then had to put the 'real' question plus its ghost followers into their own pool to ensure they execute in the correct order.

These are all really annoying additional tricks we have to play because the product doesn't do what it should be able to do. 

Jane Maloney

I think this response from a similar thread sums up Storyline nicely  

" I spend 10% of my development time just creating workarounds to things that I assumed would be built in by now."

It's a shame but storyline is falling behind some competitors quite quickly because of this work around culture that the online help team promotes

Judy Nollet

As far as I know, there's still no way to easily round the score variable. My solution: I don't show the score percentage. I set all questions to be worth 1 point, and I have the Results slide only show how many points the learner got (e.g., 7 out of 9). Alas, that fixes the problem within the course. However, it doesn't change how the score is reported to the LMS (though perhaps some LMSs are set up to round percentages to the nearest whole number).