The Student Room Group

Please help [html]

Hello :smile:
I am currently doing my coursework and have encountered a problem, I have created a timer and whenever i press the button the timer stops, I was wondering how to get the timer to run again with a DIFFERENT button press? (Another button to start the timer)
(The code I use to stop the timer)
<input type="button" onclick="clearTimeout(timer)" value="Stop">
(edited 7 years ago)
Do you want to start the timer from zero, or resume from when it stopped?
Just make a value and set it to 0. When the value reaches 2, which indicates a second press (add 1 to the said value each time button clicked)
use if/else so that when the value's set to 2, run the function again and set the value to its original state.
Original post by bobcat124
Capture.JPG
Here is my code, I have made some adjustments since i last made the thread. The buttons should start and stop the cycle of images but they dont, please help


You dun goofed. If I were you, i'd delete this fast.
You should also use "setInterval()" to recall the function after a certain amount of time.
(edited 7 years ago)
Reply 4
Original post by Carthaginian
You dun goofed. If I were you, i'd delete this fast.
You should also use "setInterval()" to recall the function after a certain amount of time.


How did i mess up?
Original post by bobcat124
How did i mess up?


I'm pretty sure exam moderators look here from time to time.
A few weeks ago my boy in CS classes got DQ'd for posting his code on stackoverflow.


Just PM people and send your code, just to be safe.
Reply 6
Original post by Carthaginian
I'm pretty sure exam moderators look here from time to time.
A few weeks ago my boy in CS classes got DQ'd for posting his code on stackoverflow.


Just PM people and send your code, just to be safe.


ah ok thanks, so I need to delete the buttons and use setinterval() ??
Original post by bobcat124
ah ok thanks, so I need to delete the buttons and use setinterval() ??


So you're on task 4 right?
Wasn't task 3 the one where you click the button and it changes, and task 4's the one where it automatically does?
Use set interval outside of the function where you change it, and it should call the function automatically after the given time.
Reply 8
Original post by Carthaginian
So you're on task 4 right?
Wasn't task 3 the one where you click the button and it changes, and task 4's the one where it automatically does?
Use set interval outside of the function where you change it, and it should call the function automatically after the given time.


Yeah ive done task 3 which is to change the lights on a button press, now im on task 4 which is to have a button where you press it once and it cycles through and press it again to stop it
Original post by bobcat124
Yeah ive done task 3 which is to change the lights on a button press, now im on task 4 which is to have a button where you press it once and it cycles through and press it again to stop it


Yes. Then use setInterval and get rid of those stop/start buttons.
It's so much easier and it's 1 line of code.
Reply 10
Original post by Carthaginian
Yes. Then use setInterval and get rid of those stop/start buttons.
It's so much easier and it's 1 line of code.


ah ok thanks :smile:

Quick Reply

Latest