Javascript help: setting test score

Jul 07, 2014

Hello Javascript Wizards!

Here's what I'm trying (in vain) to do:

I've set up the course so that users can test out of the content slides in each of three sections. This gives me three sets of results variables. If they don't make a perfect score on all three sections, they have to take a final quiz at the end. I'd like to add up the three Results.ScorePercent variables, and if they add up to 300, set the final quiz results slides to 100% and full points so they can get credit for the course.

Here's my code:

var player=GetPlayer();

var AddedScore = player.GetVar("Results.ScorePercent') + player.GetVar("Results1.ScorePercent") + player.getVar("Results2.ScorePercent");

var PerfectScore = 300;

if (AddedScore === PerfectScore) {player.SetVar("Results3.ScorePercent",100);}

if (AddedScore === PerfectScore) {player.SetVar("Results3.ScorePoints",90);}

What am I doing wrong? I've tried to rewrite this code so many times now I can't see straight!  

Or is there a much easier way to do this that I'm just not seeing?

Thanks,

Chance

3 Replies
Steve Flowers

Hi Chance,

You can't grab or write those particular variables. You should be able to do what you're looking to do from triggers within Storyline. 

Create a new variable in SL called AddedScore. 

Create a trigger to set AddedScore to zero.

Create another trigger to add Results.ScorePercent to AddedScore

Create another trigger to add Results1.ScorePercent to AddedScore

Create another trigger to add Results2.ScorePercent to AddedScore

This will get you a value 300 or less. Next create a trigger to show your final exam directions if AddedScore is less than 300. To manage setting a custom score in the LMS, you'll need to use another piece of JavaScript since you can't currently write to Results.ScorePercent.

James offers a script example here:

https://elearningenhanced.com/blog/2012/09/13/update-storyline-courses-status-lms-javascript

Philip  Palmer

Howdy,

Trying to figure out how to put a button page in my PowerPoint deck that essentially would trigger SetStatus("completed"). We have a very old version of SumTotal and the player is not sending a completed status to the LMS on newer browsers and thought that perhaps if we put the completed status into the content itself we could avoid using the player for that function.

Regards,

Philip

This discussion is closed. You can start a new discussion or contact Articulate Support.