# Variable place value

Jun 18, 2020

I have created a count down timer that starts at the beginning of a module and continues to count down as you progress. What I have noticed is that single numbers are only represented with one digit. I was hoping to have all the numbers represented with two digits. I think this would look better in a countdown timer (03:20:05). Is there any simple way to make that work? Not in SL.  I use javascript:

Create Seconds_T, Minutes_T, Hours_T, and ElapsedTime_T as case sensitive text variables, and TotalSeconds as case sensitive number variable in SL. By case sensitive, I mean the name of the variable must be exactly as you see it here.

Set The value of TotalSeconds in SL, and execute this script:

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)

ElapsedTime_T returns:

:ss up to 59 sec,
m:ss after 59 sec up to 59 min, 59 sec
h:mm:ss after 1 hour