Can anyone help me with this timer code? not getting output..please help(ignore the ui issue) | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
0

Can anyone help me with this timer code? not getting output..please help(ignore the ui issue)

<!DOCTYPE html> <html> <body> MINUTES: <input id ="t1" type="text" ><br> SECONDS: <input id="t2" type="text" ><br> <img src="https://www.dhresource.com/200x200s/f2-albu-g5-M01-DC-57-rBVaJFoqtHqASz5FAAGMcw4dJ2A582.jpg/8cm-mini-mechanical-countdown-kitchen-tool.jpg" width="100px" height="100px"/> <button onclick="myFunction()">START</button> <p id="demo"></p> <p id="demo1"></p> <p id="demo3"></p> <script> function myFunction() { var x = document.getElementById("t1").value; var y = document.getElementById("t2").value; var t=(parseInt(x)*60)+parseInt(y); var y1= setInterval('timer()', 1000); function timer() { if(t<59) { document.getElementById("demo").innerHTML=t; } else { document.getElementById("demo").innerHTML= getMinute(); document.getElementById("demo1").innerHTML= getsecond(); } if(t<10) { document.getElementById("demo").style.color="red"; document.getElementById("demo1").style.color="red"; document.getElementById("demo3").innerHTML="HURRY UP!!!!!!!"; } if(t<=0) { alert("<b>TIMES UPs!!!!!!!!!</b>"); document.getElementById("demo").innerHTML= 00; document.getElementById("demo1").innerHTML= 00; clearInterval(y1); } else{ t--; } } getMinute() { var p= Math.floor(parseInt(t)/60); return p; } getsecond() { return t-Math.round(parseInt(p)*60); } } </script> </body> </html>

15th Dec 2019, 9:49 AM
Rahul Ankit
Rahul Ankit - avatar
2 Answers
0
Can u please tell me what exactly you have done? i can see you have made t and p as global variable ryt?
15th Dec 2019, 12:32 PM
Rahul Ankit
Rahul Ankit - avatar