JavaScript problem with if/else statements
Hello!
I have a quiz page. The goal is to hide the custom Next Button when entering the page and enabling it when the quiz is either passed or failed for the last time. Then if the user navigates back to this same quiz page, the next button should already be displayed. I am trying to do this by assigning a value of 0 or 1 to a variable, and triggering an if statement if the value checks out.
When entering the page I run the following code:
var slideRef = window.cpAPIInterface.getCurrentSlideIndex(); //gets current page number
cp.hide('next_button_KBQ_' + slideRef); //hides the Next button
var isTaken = window.cpAPIInterface.getVariableValue("L4_KBQ1_taken"); //assigns a variable value (variable set in Captivate with initial value of 0)
console.log("isTaken value is " + isTaken);
if (isTaken = 1) { //if this quiz page was passed, Next button is displayed
cp.show('next_button_KBQ_'+slideRef);
console.log("Enabling Next Button");
} else if (isTaken = 0) {
cp.hide('next_button_KBQ_' + slideRef); //this shouldn't be unnecessary, but it's here for testing purposes
console.log("Next Button should be disabled");
}
on Success and on Last Attempt part of the quiz I run the following code:
var slideRef = window.cpAPIInterface.getCurrentSlideIndex();
window.cpAPIInterface.setVariableValue("L4_KBQ1_taken", 1); // assign the variable with a value of 1
cp.show('next_button_KBQ_'+slideRef);
When I launch the course, I get the following console output:
isTaken value is 0
Enabling Next Button
So the button is displayed from the start. If I pass the quiz and navigate back to the page, the console reads
isTaken value is 1
Enabling Next Button
So the variable is changing, Captivate reads the value of the variable just fine, but it skips the conditions and shows the button anyways from the very beginning. What is going on here?
Thank you!
