

I have tried javascript and interactions to create a button that when clicked multiple times will open a different quiz slide but cannot get it to work. I am in the new Captivate.
I have tried various scripts and interactions and I cannot get it to work. When I use interactions with a quizCounter variable (assigning a new number for each interaction) it ignores the conditions and simply takes me to the last quiz slide on the list.
I have tried various edits with JavaScript, including slide delays, and button won’t open any slides: Example:
var cpAPI = window.cpAPIInterface;
var index = parseInt(cpAPI.getVariableValue(“quizCounter”));
var quizSlides = [
1, 2, 3, 4, 5, 6, 7, 8, 9, 10,
11, 12, 13, 14, 15, 16, 17, 18, 19, 20,
];
console.log(“Current quizCounter value: ” + index);
if (index < quizSlides.length) {
console.log(“Navigating to quiz slide with index: ” + quizSlides[index]);
cpAPI.setVariableValue(“quizCounter”, index + 1);
setTimeout(function() {
cpAPI.call(“gotoSlide”, quizSlides[index]); // Using call() method to invoke gotoSlide
console.log(“Navigation completed to slide: ” + quizSlides[index]);
}, 300);
} else {
console.log(“All quizzes completed. Resetting to start…”);
cpAPI.setVariableValue(“quizCounter”, 1);
setTimeout(function() {
cpAPI.call(“gotoSlide”, quizSlides[0]); // Reset to first quiz slide
console.log(“Navigated to first quiz slide: ” + quizSlides[0]);
}, 300);
}
I am not a coder so I also tried working in ChatGPT and after hours of tries and reviewing the inspection panel, this is what it came up with (see image).
Anyone have an idea to help me get it to work?
I have tried various scripts and interactions and I cannot get it to work. When I use interactions with a quizCounter variable (assigning a new number for each interaction) it ignores the conditions and simply takes me to the last quiz slide on the list.
I have tried various edits with JavaScript, including slide delays, and button won’t open any slides: Example:
var cpAPI = window.cpAPIInterface;
var index = parseInt(cpAPI.getVariableValue(“quizCounter”));
var quizSlides = [
1, 2, 3, 4, 5, 6, 7, 8, 9, 10,
11, 12, 13, 14, 15, 16, 17, 18, 19, 20,
];
console.log(“Current quizCounter value: ” + index);
if (index < quizSlides.length) {
console.log(“Navigating to quiz slide with index: ” + quizSlides[index]);
cpAPI.setVariableValue(“quizCounter”, index + 1);
setTimeout(function() {
cpAPI.call(“gotoSlide”, quizSlides[index]); // Using call() method to invoke gotoSlide
console.log(“Navigation completed to slide: ” + quizSlides[index]);
}, 300);
} else {
console.log(“All quizzes completed. Resetting to start…”);
cpAPI.setVariableValue(“quizCounter”, 1);
setTimeout(function() {
cpAPI.call(“gotoSlide”, quizSlides[0]); // Reset to first quiz slide
console.log(“Navigated to first quiz slide: ” + quizSlides[0]);
}, 300);
}
I am not a coder so I also tried working in ChatGPT and after hours of tries and reviewing the inspection panel, this is what it came up with (see image).
Anyone have an idea to help me get it to work?
You must be logged in to post a comment.

- Most Recent
- Most Relevant