+ 1

Not working ordered(1, 2, 3) increment in for loop

Hy learners, maybe its a silly thing, but I can not show an ordered number(1, 2, 3) after every text. Even though a variable named 'count'. See my attached code below. Thanks. https://code.sololearn.com/WG4KS7XcevD4/?ref=app

28th Nov 2019, 12:40 AM
Forhad Hossain
Forhad Hossain - avatar
5 Respuestas
+ 3
You seem to have used the wrong function when finding the child elements in this case. If you add the line: console.log(xArray[i]); within your for loop, you'll see that within that array contains not only the tags themselves but the actual text with them as well, considering that they would be considered nodes. If you want to only loop through the tags which are children to your parent div, then I'd recommend using the .children() function instead. Additionally, the count variable does absolutely nothing within your loop so there's not really much of a point of having it haha
28th Nov 2019, 1:36 AM
Faisal
Faisal - avatar
+ 2
Forhad Hossain No problem! I'm glad it helped d:
28th Nov 2019, 4:57 AM
Faisal
Faisal - avatar
0
You are setting count to zero every time you loop.
28th Nov 2019, 1:21 AM
G4rr3t
G4rr3t - avatar
0
@G4rr3t, yes I've set the value zero to count initially. But why it shows like "1,3,5" instead of "1,2,3"??
28th Nov 2019, 4:00 AM
Forhad Hossain
Forhad Hossain - avatar
0
@Faisal, thank you for answering me. The "count" variable is useless here I know. But the thing was "console.log(xArray[i])" gave me a 7-time iterated result. So that I was confused about ordering. Now it works fine. Thank you again for giving me a lesson about the different between "childeNode" vs "children".
28th Nov 2019, 4:51 AM
Forhad Hossain
Forhad Hossain - avatar