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 trialRosario Dawson
400 PointsMy solution wont work. Why?
Here is the snap:
If i check the console, it throws this error:
Uncaught TypeError: Cannot set property 'disabled' of null at disableButtons (app.js:43) at app.js:58
My code passes the first if(list[i] == firstListItem) statement and sets the : up.disabled = true; list[i].style.backgroundColor = 'lightskyblue';
.. but on the else if() statement throws the mentioned error. Why?
Thank you!
4 Answers
Steven Parker
231,261 PointsWhenever you actually move an item up or down (or remove one), you probably want to call "disableButtons" again to reset the button properties and list item background colors.
Also, inside "disableButtons", you may need to set the "disabled" property of the button back to "false" when it is not the top or bottom anymore.
Steven Parker
231,261 PointsOn line 54, there's a loop which calls "buttonLiMaker" and "disableButtons". Yet "disableButtons" seems intended to work with buttons on every list item; but during the first loop pass, they don't exist yet except on the first one.
So I'd bet the call to "disableButtons" on line 58 should be moved to outside the loop (after the brace on line 61).
Rosario Dawson
400 PointsSteven Parker, oh - thanks for that. But it only gets me half-way there. If I start clicking the buttons (up, down) it won't change the value for the new current first/last item. What should I do?
Rosario Dawson
400 PointsOh, ok. Thank you. Yes, I've solved it - thanks for your help!