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

General Discussion

Jonathan Grieve
MOD
Jonathan Grieve
Treehouse Moderator 91,253 Points

Those "Why am I in this business" moments :)

I couldn't let this moment pass without sharing this.

I'm doing the new practice session for Selecting DOM elements. Easy enough I thought but we can never have enough practice and I thoroughly approve of them and love doing them.

The first task in the practice was to simply select an element by its ID. No problem. In the bag.

The second one was to select elements using a method that grabs a collection of elements. While I didn't think in those terms... I got the idea... I'm aware of the methods to use.

It was a while before I thought to use a loop to iterate through the entire collection though. But that's not the thing. That's what the practice is for.

But do you know what the real killer was? I must have lost an hour of my time trying to figure out what I had done wrong here.

let cards = document.getElementsByClassName('.card');

for (let i=0; i<cards.length; i +=1) {
  cards[i].style.backgroundColor = 'seashell';
}

Absolutely flawless, right? I mean.. the console didn't pick anything up anything. Yet when I tried and tried and tried little different bits of code and tried and tried to rack my brains as to why the background colour didn't change to seashell like in the video... I couldn't it out. Maybe my browser just had a bug. I didn't try seashell at first, so I just thought... maybe... I was using a colour the browser didn't support for JavaScrpt... but that didn't ring true.

And then, at last, it hit me....

I was using .card as the reference, with a method that returns class names. It was really painful when I did. A whole hour.

As a Neurodiverse person, it's moments like these that make me question my sanity. I mean, I could on another day have worked it out on the spot... but sometimes the answer just escapes me because my brain is single minded. It will only consider what is fresh in my memory and the grey matter doesn't switch on.

But it can be the same for neuro-typical people tool. Has anyone else had those moments when you wonder how you got into the tech business?

1 Answer

Steven Parker
Steven Parker
231,271 Points

Everybody has those moments when you can stare at something again and again and still not see the little typo or stray character. Especially in this kind of situation where ".card" would be the perfect argument to a different method that would return the desired result ("querySelectorAll"). So the method is good, and the argument is good, just not for each other.

Jonathan Grieve
Jonathan Grieve
Treehouse Moderator 91,253 Points

Right. It was like... to me... obviously this should work because I wasn't getting any feedback from Chrome DevTools. It's a learning experience that everything is not always as it seems, even when you're giivng computers instructions :)

Steven Parker
Steven Parker
231,271 Points

And they give you what you ask for. In this case, it was "iterate over this empty list". :laughing: