Forum Discussion

MohamedAmineSAL's avatar
MohamedAmineSAL
Community Member
3 years ago

Addition of slide's elapsed Time

hello,

i want to know how to add elapsed time of a quiz slide with an other one. and to have the sum of both in the result slide.

when i use the variable "slide.elapsedtime" it shows just how many milisecondes elapsed for each slide.

need your help guys, thank you :)

  • Hi, Mohamed.

    Were you trying to preview the project after adding the Javascript code? 

    When working with Javascript, you need to publish the project if you'd like to test it, instead of previewing it. 

    Let me know if this works!

  • Hi, Mohamed.

    Thank you for reaching out!

    Since the variable slide.ElapsedTime will change its value depending on which slide the user is currently viewing, you need to assign it to a different variable per slide.

    I'm attaching a sample .story file with three slides (two that track the amount of time the user spends on the slide, and one results slide that calculates the total):

    • Slide 1: Set Slide1_Time (a numeric variable) to variable Slide.ElapsedTime when the user clicks the Next button.
    • Slide 2: Set Slide2_Time to variable slide.ElapsedTime when the user clicks the Next button.
    • Slide 3:
      • Add Slide1_Time and Slide2_Time to the numeric variable Total_Time
      • Set Total_Seconds to Total_Time
      • Divide Total_seconds by 1000 (converting the time into seconds)

    Here are the variables used:

    Windows 10 (1) 2022-01-06 at 1.30.00 PM

    And here's what this looks like in Preview:

    Screen Recording 2022-01-06 at 01.32.27 PM

    I hope this helps!

  • Hi, Mohamed.

    I'm happy it worked for you!

    If you want to display the time as minutes and seconds, you will likely need Javascript. I'm not very good with Javascript, but I found a few helpful discussions, like this one

    I edited my sample file to execute a similar code, and it seems to work.

    Screen Recording 2022-01-07 at 11.48.46 AM

    Take a look at the attached updated file.

    I hope this helps!

  • thank you so much :), it works.

    i added an other variable of minutes (totalminutes divided per 60) and it shows for exemple 1.27min

    can i change the display of the result to have "01 min 30 sec" ?

  • hi Maria,

    i tried to run your story file but it doesn't work on it, neither on mine :(

    thank you 

  • yes it works, sorry i didn't know that i have to publish the project befor testing.

    thank you Maria :)