Skip to main content
Participating Frequently
November 28, 2017
Question

Javascript compare variables in captivate

  • November 28, 2017
  • 1 reply
  • 191 views

Hi, 

I seem to be having a problem with comparing vars. I have two in captivate, one is called LMSpass and is set to 80 and the other grabs the score from my moodle LMS and populates LMSscore.  Then on the quiz results page I compare one with the other and it doesn't work. I want the learner to go to the next page if they pass which is a certificate. Can anyone offer some help, it looks like it should work ok

 

This is the code on my test results page- both variables are populated.

window.cpAPIInterface.setVariableValue("LMSscore", SCORM_CallLMSGetValue("cmi.core.score.raw"));

if (LMSscore>=LMSpass) {

    window.cpAPIInterface.next();

} else {

    {alert("Hi you have failed the test. Please retake. If you need technical help please contact ....");

}

This topic has been closed for replies.

1 reply

TLCMediaDesign
Inspiring
November 28, 2017

Your code doesn't really make any sense since you are setting a value (LMSscore) with the value of cmi.core.score.raw. If cmi.core.score raw is set, then the values would always be the same. If you know that you need 80 to pass, then all you need to do is:

var getScore = Number(SCORM_CallLMSGetValue("cmi.core.score.raw"));//ensure the result is a number

if(getScore>=80)

{

     window.cpAPIInterface.next();

}

else

{

     alert("Hi you have failed the test. Please retake. If you need technical help please contact ....");

}

By the way, you have a curly brace before the alert in your code which would break it anyway.