jhuppi Posted March 3, 2013 Share Posted March 3, 2013 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 More sharing options...
jeffman Posted March 3, 2013 Share Posted March 3, 2013 Looks like you need to change the value of on somewhere, or it will always = 1 Link to comment Share on other sites More sharing options...
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now