0

Auto increment?

So I want to create a js counter that simply updates every 1 second with start and stop functions, I'd add my attempt, but I forgot to save it. Anyone want to help? Needless to say, I'm an idiot xD

11th Jun 2018, 6:09 AM
Daniel Cooper
Daniel Cooper - avatar
6 odpowiedzi
+ 9
just re-write it nothing to be afraid of sometimes it's actually a good thing to re-write your code from scratch. you might find new ways to write it which are shorter, more efficient, or simply nee approach to the taks at hand.
11th Jun 2018, 6:17 AM
Burey
Burey - avatar
+ 1
here's my attempt Sorry it took a while. Was watching movies with my wife. Anyway, what am I doing wrong? https://code.sololearn.com/Ww3EOsdA4WdZ/?ref=app
11th Jun 2018, 7:47 AM
Daniel Cooper
Daniel Cooper - avatar
+ 1
Firstly, that is fast for every second. Try changing the "100" to "1000". The JavaScript Tutorial course covers this. Secondly, you have the counter doing things in your JS, but the button is not connected to the counter in any way in your code. "value='Stop'" just tells it what to say, not what to do. As for the additional JS, there are many ways to get the button to do what you want it to do with the counter, so I will simply say that you could probably get a lot of learning mileage from trying to implement this using as many different ways as possible (like "switch", "case", "break", and "default" for one and trying a "while" loop in another). Incidentally, the JavaScript Tutorial also spends quite a bit of time on these concepts. Hopefully this points you in the right direction. :)
14th Jun 2018, 5:01 AM
Janning⭐
Janning⭐ - avatar
+ 1
I had actually forgotten about this code. I'm still working on the toggle switch, but the counter was the problem when I first posted this. But thanks!
14th Jun 2018, 5:19 AM
Daniel Cooper
Daniel Cooper - avatar
+ 1
Plus I just chose a random number. I wasn't really worried about the 1 second part at the time since that wasn't the problem.
14th Jun 2018, 5:21 AM
Daniel Cooper
Daniel Cooper - avatar
0
Well, I know how to re-write it, but the problem is that it crashes every time. Give me a few and I could re-write it.
11th Jun 2018, 6:30 AM
Daniel Cooper
Daniel Cooper - avatar