Forum Discussion

cameron's avatar
cameron
Community Member
15 days ago
Solved

JavaScript Communicating Points to Canvas LMS

Hello! I am working on a project where students are to "label" the different parts of a heart and get a score based on how many labels they got right. 

I will include the file, but it basically works by each input box having a state for every possible answer. And when they have an input box selected they can choose an answer from the "word bank" on the bottom. The input box will then change to the applicable state. The submit button appears when all words have been used.

I created a variable called "score" and once they click submit, a value of 1 is added to the score variable for every object that's in the correct state. Clicking submit also takes them to another layer where it shows them the score variable. As soon as that layer shows up, there is a trigger to execute the following javascript:

let player = GetPlayer();
let score = player.GetVar("score");
let scorePerc = (score/26)*100;

let lmsAPI = window.parent;
lmsAPI.SetScore(scorePerc, 100, 0);

 

When I test this in Canvas, it always gives me full points no matter what score I actually get. So my main question is, why isn't this working? I also wonder if there's something I need to do to have it communicate a point value instead of a percentage and if that makes a difference

5 Replies

  • It might be that you just needed make sure the data was a number before using it. I did this and tested on SCORM Cloud and it reported the score correctly.

    In the attached file I've adjusted and added some console.logs so you can see the data being processed by JavaScript.

    I also changed "26" to a Storyline variable called maxscore. You could just grab this JS and overwrite your existing script, or use the attached SL file.

    let player = GetPlayer();
    let score = Number(player.GetVar("score"));
    console.log("score",score);
    let maxscore = Number(player.GetVar("maxscore"));
    console.log("maxscore",maxscore);
    let scorePerc = (score/maxscore)*100;
    console.log("scorePerc",scorePerc);
    let lmsAPI = window.parent;
    lmsAPI.SetScore(scorePerc, 100, 0);

     

    • cameron's avatar
      cameron
      Community Member

      Thanks! I played around with your solutions and I do think it was functioning better. Unfortunately I found out that the network for my institution will not access Javascript info to transfer to the LMS, so I had to find another work around. I am linking my solution below.

      • SamHill's avatar
        SamHill
        Super Hero

        Hi cameron​, Storyline runs on JavaScript. It doesn't sound right that you institution will not access JavaScript as that would mean the Storyline content would not work at all. To transfer any data to an LMS, Storyline uses the SCORM JavaScript API and to run any slide, JavaScript is used. I'm just flagging that you have potentially been given incorrect information regarding JavaScript.