Please help... What am i doing wrong in this code? | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
0

Please help... What am i doing wrong in this code?

https://code.sololearn.com/W8MzXsZpb6k3/?ref=app

2nd Jan 2020, 4:43 PM
Sax
Sax - avatar
4 Answers
+ 5
1. Put all your js inside a window.onload=function(){ //your js } 2. It is not click, it is "click". 3. At line 24, replace display with width
3rd Jan 2020, 10:11 AM
🍇 Alex Tușinean 💜
🍇 Alex Tușinean 💜 - avatar
+ 3
If you use document.getElementById("progress") instead of el, the code works. function click() { //var el = document.getElementById("progress"); var neWidth = 15; var id = setInterval(frame, 50); function frame() { if (neWidth <= 100) { neWidth++;} else{ clearInterval(id); } document.getElementById("progress").style.width = neWidth + "%"; document.getElementById("progress").innerHTML= neWidth + "%"; } } I also replaced a }, because you put the 2 document.getElement... inside the else{}
2nd Jan 2020, 5:02 PM
🍇 Alex Tușinean 💜
🍇 Alex Tușinean 💜 - avatar
+ 3
Works perfectly now... Thumbs up man...
3rd Jan 2020, 11:15 AM
Sax
Sax - avatar
0
Thanks Alex, but its not still working in my playground. 1. Btw how possible is it that i couldnt use document.getElementById('progress') as a stored variable. 2. The errors i keep getting most is that Javascript can't read property of null... Meaning couldnt get my ID.. 3. I also tried using the addEventListener method but still getting the same error. 4. The only time i get it to run, it did so automatically as soon as i refreshed the browser... Meaning that the click function didnt do anything... Please help me out... 😭😭😭😭
3rd Jan 2020, 9:06 AM
Sax
Sax - avatar