javascript - JS Timer with setTimeout get a "Uncaught SyntaxError: Unexpected token (" -
i've been trying make javascript timer using settimeout() command. when @ in browser console returns "uncaught syntaxerror: unexpected token (".
also can see code here: http://mathiakiaer.site88.net/timer/
this html code:
<!doctype html> <html> <head> <title>timer</title> <link rel="stylesheet" type="text/css" href="style.css"> <script src="script.js" type="text/javascript"></script> <meta charset="utf-8"> <meta name="viewport" content="width=device-width, initial-scale=1.0"> </head> <body> <article> <p id="timertime"><span id="timertimeminutes">00</span>:<span id="timertimeseconds">00</span></p> <button id="timerstart" onclick='repeattimer()'>start</button> <div id="timerchangediv"> minutes: <input id="timerinputminutes" value="0" type="number" min="0" max="60"><br> seconds: <input id="timerinputseconds" value="0" type="number" min="0" max="60"><br> <button onclick="settime()">change time</button> </div> </article> </body> </html>
and javascript code:
var seconds=0; var minutes=0; function countdown() { if(seconds!==0) { repeattimer(); seconds--; } else { if(minutes!==0) { minutes--; seconds=59; repeattimer(); } else { alert("the timer done"); } } refresh(); } function repeattimer() { settimeout("function() {countdown();}", 1000); } function settime() { seconds=parseint(document.getelementbyid("timerinputseconds").value); minutes=parseint(document.getelementbyid("timerinputminutes").value); document.getelementbyid("timerinputseconds").value=0; document.getelementbyid("timerinputminutes").value=0; refresh(); } function refresh() { if(seconds>9) { document.getelementbyid("timertimeseconds").innerhtml=seconds; } else { var secondsshow="0" + seconds; document.getelementbyid("timertimeseconds").innerhtml=secondsshow; } if(minutes>9) { document.getelementbyid("timerminutes").innerhtml=minutes; } else { var minutesshow="0" + minutes; document.getelementbyid("timertimeminutes").innerhtml=minutesshow; } }
first param function not string.
function repeattimer() { settimeout(function() {countdown()}, 1000); }
or
function repeattimer() { settimeout(countdown, 1000); }
Comments
Post a Comment