How can I get the result of this function to display on my slide?
Hello everybody,
I'm struggling with a task I have to complete, any help is very much welcome at this point.
Context: at the end of the elearning I'm developing, I need to include a slide (that will be printed for archives and payment and stuff ) with the duration the trainee took. Each trainee is going to have a different time due to questions, quiz etc. I also like to say that I'm more a specialist in the stuff I teach then in javascript or advanced actions.
What I did: on the page where I want to display the time, I trigger an advanced action.
In it, I assign the variable FinalTime with cpInfoElapsedTimeMS (it would be so nice if it had immediate formatting options as for the current date
).Now, I need this ElapsedTime to look readable, not just in seconds but as a human timing as for a video.
So then in the advanced action I try to execute a Javascript which is:
var millisec = window.cpAPIInterface.getVariableValue("FinalTime");
function getMyTime(millisec) {
var seconds = (millisec / 1000).toFixed(0);
var minutes = Math.floor(seconds / 60);
var hours = "";
if (minutes > 59) {
hours = Math.floor(minutes / 60);
hours = (hours >= 10) ? hours : "0" + hours;
minutes = minutes - (hours * 60);
minutes = (minutes >= 10) ? minutes : "0" + minutes;
}
seconds = Math.floor(seconds % 60);
seconds = (seconds >= 10) ? seconds : "0" + seconds;
if (hours != "") {
return hours + ":" + minutes + ":" + seconds;
}
return minutes + ":" + seconds;
}
window.cpAPIInterface.setVariableValue("Duration",getMyTime);
Well, let's add that I declared all my variables in CP and that on my slide I inserted $$Duration$$
The answer I receive is 0 when running everything. So can anybody tell me what I did wrong, and ideally tell me how to do it right?
Thanks so much for reading.


