Welcome to the Treehouse Community

Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.

Start your free trial

JavaScript JavaScript and the DOM (Retiring) Traversing the DOM Getting the First and Last Child

Kjetil-Lennart A. Lorentzen
Kjetil-Lennart A. Lorentzen
13,390 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
231,261 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,390 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