• Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
    Dedicated community for Japanese speakers
  • 한국 커뮤니티
    Dedicated community for Korean speakers
Exit
0

How to create a timer with start and stop buttons by using JavaScript?

Explorer ,
Feb 06, 2020 Feb 06, 2020

Copy link to clipboard

Copied

Hi,

 

I want my users to click on a start button before doing something. after they completed the task/, they will click on the stop button to stop the counter. I want my user to be able to see the elapsed time on that slide.

By the way, I want this for only one slide and it is not a question slide. Of course, when user come and visit the slide again. I want to reset it again. Here is the screenshot of my current setup. Do you have any example and instructions for me to realize this action:

 

Screen Shot 2020-02-07 at 10.17.03.pngScreen Shot 2020-02-07 at 10.17.32.png

TOPICS
Advanced , Advanced actions

Views

1.3K

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Explorer ,
Feb 07, 2020 Feb 07, 2020

Copy link to clipboard

Copied

As you can below, I added the javascript code into the On Enter event of the slide.I gave my buttons IDs. But, still not working

var startTime, endTime;

function start() {
  startTime = new Date();
};

function end() {
  endTime = new Date();
  var timeDiff = endTime - startTime; //in ms
  // strip the ms
  timeDiff /= 1000;

  // get seconds 
  var seconds = Math.round(timeDiff);
  console.log(seconds + " seconds");


document.getElementById(“start_timer”).addEventListener(“click”, start());
document.getElementById(“stop_timer”).addEventListener(“click”, end());


window.cpAPIInterface.getVariableValue("elapsed_time") = seconds;

 

 

Screen Shot 2020-02-07 at 11.04.42.png

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Feb 07, 2020 Feb 07, 2020

Copy link to clipboard

Copied

I always use advanced actions for this type of rather simple requests. But since you insist on JS, wait for the JS experts. Why make it simple when....

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Explorer ,
Feb 07, 2020 Feb 07, 2020

Copy link to clipboard

Copied

Hi Lilybiri, If there is a way to do it with Advanced Actions, which probably there is, could you please share some your demo blog posts or advice? Do I need to acesss timeline/slide duration? 

 

Thanks for your help!

 

 

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Contributor ,
Feb 07, 2020 Feb 07, 2020

Copy link to clipboard

Copied

'Delay next action by ..' in advanced actions?

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
New Here ,
Apr 14, 2020 Apr 14, 2020

Copy link to clipboard

Copied

kindly help with the advanced actions please

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Apr 15, 2020 Apr 15, 2020

Copy link to clipboard

Copied

LATEST

Sorry I quit when JS experts come in... 

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Resources
Help resources