0

Please help, how would you make a timer that runs some code for a time specifed by the user selecting an option from a dropdown menu ? Jquery please. PS: I tried to attach my code but I'm getting errors (here on the stacks) Please help, any ideas welcome. I'm really struggling

1 Answers1

0

First of all, to set a "timer" in js in general, you use

setTimeout(() => some_stuff, time_in_ms)

for example, to send a console.log in half a second, you'll use

setTimeout(() => {console.log("hi");}, 500);

So, when the user selects the option from the dropdown menu, just start a timer with the delay as what the user chose, and the function as whatever you want to run. If you don't already have a dropdown menu, this tutorial might come in handy to create it: https://www.w3schools.com/howto/howto_js_dropdown.asp

But yea, as the comment mentioned, please also send your code, because without it its really hard to give accurate help.

PlainXYZ
  • 126
  • 1
  • 8
  • Thank you very much for the answer. Let me try to attach my code again: – viwe mgoduka Apr 14 '22 at 14:06
  • Don't try to attach it, just copy paste it in using the code formatting option – PlainXYZ Apr 14 '22 at 14:07
  • can I please send you a link to the live site ? – viwe mgoduka Apr 14 '22 at 14:12
  • https://tentimes-5cb71.web.app/? – viwe mgoduka Apr 14 '22 at 14:13
  • Tbh, i rather not click on random websites I find on the internet, just copy paste the code into your original question – PlainXYZ Apr 14 '22 at 14:13
  • Hi again. I created a JSfiddle. Please if you can spare a few moments to help with code please. I want the code to run for example 10 mins.And during that 10 mins the code must store and update the user's score. My stuck point is that the page reloads every time and therefore does'nt save the score. Here's the fiddle, please take a look and share your thoughts. https://jsfiddle.net/viwe/18yhtuo6/2/ – viwe mgoduka Apr 24 '22 at 05:03