Why buttons work only once? | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
0

Why buttons work only once?

When I add to function to the buttons, it only work once. How can I make it works more than once. https://code.sololearn.com/WPwH97maEoDP/?ref=app

24th Aug 2020, 6:32 AM
Allamprabhu Hiremath
7 Answers
+ 1
You can always use javascript to make that happen. That is you can use addEventListener() to make buttons more responsive. 🙂🙂🙂 I hope it helps.
24th Aug 2020, 6:49 AM
Hamza Rarani
Hamza Rarani - avatar
+ 7
Hello Allamprabhu Hiremath , In your stop function , you are clearing your interval 'Time'. which means basically deleting it. Again , in your start function , your are writing setInterval(moveUp , 2) but not assigning it to anything else. Thus , when you again run your stop function it clears "Time" which is undefined because you deleted it before. Thus , the progess does not stop. There is nothing wrong with your buttons. function start() { time = setInterval(moveUp , 2); } instead of setInterval(moveUp , 2); Have a good day, Cheyat
24th Aug 2020, 6:55 AM
Ćheyat
Ćheyat - avatar
+ 2
var time = setInterval(moveUp,1); var count = 0; var n = 10 ; function moveUp (){ count += n ; document.getElementById("a").innerHTML = count ; document.getElementById("meter").value = count ; } function stop(){ clearInterval(time); n = 0 ; } function start(){ setInterval(moveUp,2); n = 10 ; }
24th Aug 2020, 7:01 AM
Divya Mohan
Divya Mohan - avatar
+ 2
Allamprabhu Hiremath if(document.getElementById('meter')) {stop();} in moveUp() function
24th Aug 2020, 7:43 AM
Ćheyat
Ćheyat - avatar
+ 1
Js line 6 if(count<16000){count += 10 ;}
24th Aug 2020, 7:42 AM
Divya Mohan
Divya Mohan - avatar
0
How to stop this count when it reaches to 16000
24th Aug 2020, 7:38 AM
Allamprabhu Hiremath
0
Thanks to all. Its work
24th Aug 2020, 8:15 AM
Allamprabhu Hiremath