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
11 Antworten
+ 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
+ 2
Sponge ßob what do you want it to do?
+ 2
Thanks 👍
+ 2
Thanks bro... You really helped
+ 1
Can you describe your problem or error that you are getting?
+ 1
To change display of the quiz to none and display a timeout once the timer is zero
+ 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
+ 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.
+ 1
Happy to help 👍
0
no error, but its not working like i want it to
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.