bobcat124
Badges: 0
Rep:
?
#1
Report Thread starter 3 years ago
#1
Hello
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">
0
reply
A Mysterious Lord
Badges: 18
Rep:
?
#2
Report 3 years ago
#2
Do you want to start the timer from zero, or resume from when it stopped?
0
reply
Carthaginian
Badges: 2
Rep:
?
#3
Report 3 years ago
#3
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.
1
reply
Carthaginian
Badges: 2
Rep:
?
#4
Report 3 years ago
#4
(Original post by bobcat124)
Attachment 603734
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.
0
reply
bobcat124
Badges: 0
Rep:
?
#5
Report Thread starter 3 years ago
#5
(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?
0
reply
Carthaginian
Badges: 2
Rep:
?
#6
Report 3 years ago
#6
(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.
0
reply
bobcat124
Badges: 0
Rep:
?
#7
Report Thread starter 3 years ago
#7
(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() ??
0
reply
Carthaginian
Badges: 2
Rep:
?
#8
Report 3 years ago
#8
(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.
0
reply
bobcat124
Badges: 0
Rep:
?
#9
Report Thread starter 3 years ago
#9
(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
0
reply
Carthaginian
Badges: 2
Rep:
?
#10
Report 3 years ago
#10
(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.
0
reply
bobcat124
Badges: 0
Rep:
?
#11
Report Thread starter 3 years ago
#11
(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
0
reply
X

Quick Reply

Attached files
Write a reply...
Reply
new posts
Back
to top
Latest
My Feed

See more of what you like on
The Student Room

You can personalise what you see on TSR. Tell us a little about yourself to get started.

Personalise

University open days

  • The University of Law
    Solicitor Series: Assessing Trainee Skills – LPC, GDL and MA Law - Guildford campus Postgraduate
    Wed, 29 Jan '20
  • Nottingham Trent University
    Postgraduate Open Day Postgraduate
    Wed, 29 Jan '20
  • University of Groningen
    Undergraduate Open Day Undergraduate
    Fri, 31 Jan '20

Have you ever signed up for an open day and then not gone to it?

Yes (212)
53.13%
No (187)
46.87%

Watched Threads

View All