0

javascript problem

hey guys, i made a code with a progress bar so when the setInterval is up, a timeout fades in. Im already done with the code but i dont know whats wrong with it, please help me check my js code, especially the set interval function. If theres anything wrong https://code.sololearn.com/Wk9j38oYKC3l/?ref=app https://code.sololearn.com/Wk9j38oYKC3l/?ref=app

25th May 2022, 10:11 AM
Mikeey
Mikeey - avatar
11 ответов
+ 1
Sponge ßob Your errors: 1) You were checking the "p" value for 0 only once. You had to place that condition in the setInterval() method itself, so that it gets checked continuously or else it will be checked only once. 2) the methods "getElementsByClassName() and getElementsByTagName()" return a collection of html objects. You should be storing them in a variable and iterate over it with a loop. In the loop, apply the appropriate properties. https://code.sololearn.com/WUI6Da50i16h/?ref=app
26th May 2022, 5:40 AM
Bhaveshsingh Pawar
Bhaveshsingh Pawar - avatar
+ 2
Sponge ßob what do you want it to do?
25th May 2022, 2:42 PM
Bhaveshsingh Pawar
Bhaveshsingh Pawar - avatar
+ 2
Thanks 👍
26th May 2022, 10:41 AM
Mikeey
Mikeey - avatar
+ 2
Thanks bro... You really helped
26th May 2022, 9:37 PM
Mikeey
Mikeey - avatar
+ 1
Can you describe your problem or error that you are getting?
25th May 2022, 10:22 AM
Bhaveshsingh Pawar
Bhaveshsingh Pawar - avatar
+ 1
To change display of the quiz to none and display a timeout once the timer is zero
25th May 2022, 10:53 PM
Mikeey
Mikeey - avatar
+ 1
It worked but what I don't understand is why I'd have to iterate the html objects Pls can I message you so you'd explain I'm still a JavaScript beginner
26th May 2022, 10:51 AM
Mikeey
Mikeey - avatar
+ 1
Sponge ßob the reason is... These methods... getElementById(); getElementsByClassName(); getElementsByTagName(); all of the above methods have a "return type", that is they give you/provide you with a value or object which can be stored in a variable. For each of the above methods "return type" can be different. This is how it is... getElementById(); This method returns "only" a "single" Element which has the "Id" given in the brackets/parentheses. Since, you know "ID" in html are global values which are unique. So no two elements can have the same ID. getElementsByClassName(); getElementsByTagName(); Now these two methods above, both of these methods return a "HTML object collection" or a "NodeList". Now since it's a list. It can have any number of elements. And you know that "class" and "tag" can be same for multiple elements. That is why we have to iterate over this "list of objects" in order to apply the properties.
26th May 2022, 1:54 PM
Bhaveshsingh Pawar
Bhaveshsingh Pawar - avatar
+ 1
Happy to help 👍
27th May 2022, 4:14 AM
Bhaveshsingh Pawar
Bhaveshsingh Pawar - avatar
0
no error, but its not working like i want it to
25th May 2022, 11:17 AM
Mikeey
Mikeey - avatar
0
Other way is that if you have only "one single" element which is of that "class or tag" then you can simply do this. var element_list = getElementsByClassName("class_name"); var my_node = element_list[0]. Since, arrays and lists start from the index 0. The similar can be applied for getElementsByTagName() method.
26th May 2022, 1:56 PM
Bhaveshsingh Pawar
Bhaveshsingh Pawar - avatar