Forum Discussion

CajaPopularM704's avatar
CajaPopularM704
Community Member
3 months ago
Solved

Timer issue

Hello everyone! Hoping you are having an amazing week, I am currently working on a project that requires a timer, this could be countdown or countup, but in this case I found (in the Articulate com...
  • Nedim's avatar
    3 months ago

    Try:

    var Total = getVar("Total_Time");
    
    var minutes = Math.floor(Total / 60);
    var seconds = Total % 60;
    
    var formattedTime = minutes + ' minute(s) ' + (seconds < 10 ? '0' : '') + seconds + ' second(s)';
    
    setVar("Split_Time", formattedTime);
    

    or:

    var Total = getVar("Total_Time");
    
    var minutes = Math.floor(Total / 60);
    var seconds = Math.floor(Total % 60);  // <-- Floor seconds to remove decimals
    
    var formattedTime = minutes + ' minute(s) ' + (seconds < 10 ? '0' : '') + seconds + ' second(s)';
    
    setVar("Split_Time", formattedTime);

    to remove decimals.