0

Why can't it run?

<!DOCTYPE html> <html lang="en"> <head> <title>Can you stop at 10 seconds?</title> </head> <body> <form> <input type ="button" value="START!" onClick="timedCount()" id="b1"> <input type="text" id = "time"> <input type ="button" value="STOP!" onClick="stopCount()" id="b2"> </form> <p>Please click the start button, time increases from 0,Please click the stop button near 10</p> <script type = "test"> var c=0; var t; function timedCount(){ document.getElementById('time').value=c; c=c+0.01; t=setTimeout(timedCount(),10); } function stopCount(){ clearTimeout(t) } </script> </body> </html> Question 1: why can't it run? Question 2: how to implement timing in this format?00:00 I'm a beginner, and I'd appreciate it if you could help me. It's nice to meet people who have a common interest. Thank you!

22nd Feb 2019, 2:29 PM
Xiunan
Xiunan - avatar
2 Answers
+ 2
1.) You're using the wrong type for the script tag. You can either omit the type entirely or use "text/javascript". 2.) Use setInterval instead of setTimeout. With your current code, you'll be running to a max call stack error.
22nd Feb 2019, 2:50 PM
Jomari Pantorilla
Jomari Pantorilla - avatar
0
Thanks very much
22nd Feb 2019, 2:54 PM
Xiunan
Xiunan - avatar