+ 1

stop and continue in javascript

how can i stop execution of my code with mouse events and play it again

12th Feb 2019, 8:22 AM
ABDELMOUGHIT GARDAM
ABDELMOUGHIT GARDAM  - avatar
9 Respostas
+ 7
First of all, do not use loops to sleep the thread, it's a bad practise and blocks the execution of all javascript in all browser tabs!! Second, your code is a bit unreadable which makes it hard to debug, try splitting your html/css/js into their respective sections. You should try changing the "20" to "0" (countdown) with js instead of having another hidden html section and keeping all of your js organised (use only as many timing functions as needed), Plus, the solution i offered you is complete enough if applied well, i can't do the work for you. Your code needs a big rewrite, try completing the tutorials and trying again, i definitely can't make this work as you want it to /:
13th Feb 2019, 7:42 PM
Valen.H. ~
Valen.H. ~ - avatar
+ 8
Yes. You can do anything.
12th Feb 2019, 8:35 AM
Valen.H. ~
Valen.H. ~ - avatar
+ 7
Can you show me your code?
12th Feb 2019, 8:54 AM
Valen.H. ~
Valen.H. ~ - avatar
+ 5
Which part/lines you want to start/stop?
12th Feb 2019, 8:59 AM
Valen.H. ~
Valen.H. ~ - avatar
+ 5
Okay, the event you need is dbclick, put a stop case inside your interval, controlled by a global variable. "dbclick" will set the "stop" variable from false to true and "click" will set it back to false. setInterval(function interval() { if (stop) return; //code here }, ...); alldivs.ondbclick = () => stop = true; alldivs.onclick = () => stop = false; //implement that and tell me if it doesn't work as it should.
12th Feb 2019, 9:11 AM
Valen.H. ~
Valen.H. ~ - avatar
+ 1
@valen.h how i can do it ???
12th Feb 2019, 8:51 AM
ABDELMOUGHIT GARDAM
ABDELMOUGHIT GARDAM  - avatar
12th Feb 2019, 8:57 AM
ABDELMOUGHIT GARDAM
ABDELMOUGHIT GARDAM  - avatar
+ 1
@valen.h if the user doublclick on any div stop toggle and wait for click to run again.
12th Feb 2019, 9:05 AM
ABDELMOUGHIT GARDAM
ABDELMOUGHIT GARDAM  - avatar
+ 1
@valen.h i did not understund please this is my code do it please https://code.sololearn.com/Wm53vDCQ49UR/#html
12th Feb 2019, 1:33 PM
ABDELMOUGHIT GARDAM
ABDELMOUGHIT GARDAM  - avatar