Reporting Number Variable in 2-Digit Place Value

Apr 05, 2017

I need to track start and end times of student practice time. I've got it set up with a number variable field for StartHour, another one for StartMinute. (I couldn't figure out how to enter a time in the Number field; it didn't like the colon.)

The results page tracks the response just great, but if I enter in "07" in the Minutes field, the reported result shows as just "7" (so a 9:07 time would look like 9: 7).

Is there a (relatively simple ;-)) way to have the %StartMinute% value show the two-digit place value so the minutes display accurately?

Thanks,

Helen

6 Replies
Walt Hamilton

Helen,

I had a timer that changed a variable every second. When it changed, I triggered this javascript, which returns formatted total time to a variable named ElapsedTime_T, hours in Hours_T, minutes in Minutes_T, and seconds in Seconds_T.  You display any combination to get the result you want. 

Of course, you can trigger it on any action you want and if TotalSeconds has a value, it will be returned as that many seconds in a time format.

SL needs to change TotalSeconds (numeric variable) and execute this script when it changes. JS starts after line:

_____________________________________________________________________________

var player = GetPlayer();

var TotalSeconds = player.GetVar("TotalSeconds");

var Seconds = TotalSeconds % 60;
var TotalMinutes = parseInt(TotalSeconds / 60);
var Minutes = TotalMinutes % 60;
var Hours = parseInt((TotalMinutes - Minutes)/60)
if (Seconds < 10 ) {Seconds = "0" + Seconds};
if (Minutes < 10 && Hours >= 1) {Minutes = "0" + Minutes};
if (Minutes < 1 && Hours >= 1) {Minutes = "00:"};
if (Minutes < 1 && Hours <1) {Minutes = ""; Seconds = ":" + Seconds;};
if (Minutes >= 1) {Minutes = Minutes + ":"};
if (Hours < 1) {Hours = ""};
if (Hours >= 1) {Hours = Hours + ":"};
player.SetVar("Seconds_T",Seconds);
player.SetVar("Minutes_T",Minutes);
player.SetVar("Hours_T",Hours);
player.SetVar("ElapsedTime_T", Hours + Minutes + Seconds)

________________________________________________________________

JS ends above line


Display with any combination of %Hours_T%%Minutes_T%%Seconds_T% OR %ElapsedTime_T% (These are Text variables)
: are added as needed

Hours are displayed as H:
Minutes as MM: if H is over 1, M: if under
Seconds are displayed as :SS if M is under 1, SS if over

This discussion is closed. You can start a new discussion or contact Articulate Support.