Reporting Number Variable in 2-Digit Place Value
Apr 05, 2017
By
HR Graves
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
Hi Helen - Perhaps a Text Entry will work better for what you need here. That would hold the 'place'. Attaching brief example.
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
Thanks so much for your suggestion. The instructor is afraid students will forgot to include the colon separating hour from minutes so we’d hoped to avoid a text box. But it does seem the simplest solution.
Thanks again, Leslie.
Warmly,
~Helen
I understand Helen and it looks like Walt is offering another solution above as well if that may work better for you.
I also wanted to mention that replying to the forums via e-mail attaches your signature. You are welcome to pop in and edit if needed.
Hi, Walt,
Wow, this goes a bit beyond my technical expertise but I think it will be music to the ears of my colleague. So, I’ll have her break it down for me. ;-)
Thanks so much for taking the time to offer a suggestion.
Warmly,
~Helen
Glad that sounds like something that will assist you Helen :)
I just wanted to mention that replying to the forums via e-mail attaches your signature. You are welcome to pop in and edit if needed.
This discussion is closed. You can start a new discussion or contact Articulate Support.