Jump to content

Tabata-like Timer


jhuppi

Recommended Posts

HiI'm trying to make a tabata-like timer that counts up and then counts down once the user clicks the "reverse" button. At first I had two separate functions to accomplish this, but the functions would fight with each other and the timer wouldn't react until the "reverse" button was clicked twice.Right now I'm trying to use a switch case within one function so the timer reverses with only one click of the button.Any insights would be appreciated./*<!DOCTYPE html><head><script>var t=0;var x;var on=1;function timer(){ switch(on) { case 1: document.getElementById("txt").value=t; t=t+1; x=setTimeout("timer()",1000); break; case 2: document.getElementById("txt").value=t; t=t-1; x=setTimeout("timer()",1000); break; }}function stop(){ clearTimeout(x);}</script></head><body>Under Construction...<form><input type = "text" id="txt" /><p><input type = "button" value = "Start" onClick = "timer()" /><input type = "button" value = "Reverse" onClick = "timer()" /><input type = "button" value = "Stop" onClick = "stop()" /></form></body> */

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...