Why this code don't work well? I need that every time you click the button the progressbar increase 20% but it don't do nothing. | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
+ 3

Why this code don't work well? I need that every time you click the button the progressbar increase 20% but it don't do nothing.

js: ... function aaa() { } function qq() { let pre=document.querySelector("#pre"); var i=100; let id=setInterval(function(){ i-=20; if(i>=0){ pre.value=i} else { clearInterval(id); if (aaa()) { pre.value=i+=40; } } },1000); }; html: <p id="we">Sueño</p> <button id="me" onclick="aaa()">Dormir</button><progress value="100" max="100" id="pre"></progress> ////I need that every time you click the button the progressbar increase 20%

9th Sep 2020, 7:53 PM
Carmen Lucía
Carmen Lucía - avatar
2 Answers
+ 3
<body> <progress id="pre" value="20" max="200"></progress> <button onclick="add()">+20</button> <script> add = ()=>{ var valtag = document.querySelector("#pre"); var val = parseInt(valtag.getAttribute("value")); if(val<200){ val =(val)+20 ; } valtag.setAttribute("value",val); } </script> </body>
9th Sep 2020, 8:32 PM
Divya Mohan
Divya Mohan - avatar
+ 1
.value is used for input tags value. But here You are dealing with attributes Use getAttribute() & setAttribute()
9th Sep 2020, 8:35 PM
Divya Mohan
Divya Mohan - avatar