JavaScript JavaScript and the DOM Traversing the DOM Getting the First and Last Child

Kjetil-Lennart A. Lorentzen
Kjetil-Lennart A. Lorentzen
13,387 Points

Can't get my code to work. Can anybody take a look at it?

https://w.trhou.se/iasfv7n7nx

There's a snapshot of my code. I tried to keep it clean so it would be easy to read. I've tried making a function with a loop and if-statements to crawl over the buttons to make them disapppear. They do disappear, but! The last if-statement on line 61 doesn't add them again. I've been at this for a couple of days, decided to look at the video for the challange solution, but there wasn't any, haha.

I can't see the solution to this, i have no idea how to fix this, my frustration is clouding my thinking like you wouldn't believe. I appreciate the help, a solution to this would end my frustrations.

1 Answer

Steven Parker
Steven Parker
163,772 Points

It doesn't make sense for "firstChild" and "lastChild" to be global constants, since using the buttons will change the order of the items.

But if you assign them inside the "buttonCrawler" function, then it can correctly identify the items that need buttons to be made visible again.

Kjetil-Lennart A. Lorentzen
Kjetil-Lennart A. Lorentzen
13,387 Points

It works!!

Oh, my, god that felt nice. Thank you so much. This is the second time you've helped me out!

I didn't think of this, he declared them on the top in the video, and i just left them there. Lesson is learned, have a good one