Welcome to the Treehouse Community

The Treehouse Community is a meeting place for developers, designers, and programmers of all backgrounds and skill levels to get support. Collaborate here on code errors or bugs that you need feedback on, or asking for an extra set of eyes on your latest project. Join thousands of Treehouse students and alumni in the community today. (Note: Only Treehouse students can comment or ask questions, but non-students are welcome to browse our conversations.)

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and a supportive community. Start your free trial today.

JavaScript DOM Scripting By Example Editing and Filtering Names Filter Invitees Who Have Not Responded

Birthe Vandermeeren
Birthe Vandermeeren
17,146 Points

Why do you have a line of code for when the class name is 'responded'?

I used .visibility = 'hidden' instead of .display = 'none' in my code, but nevertheless, why do you have a line of code for when the class name is 'responded'? I just check with an if statement if .className !== 'responded' and then set the visibility to hidden.

Here's my code: https://w.trhou.se/q8v8al1ebt

Hello Birthe, we check if the list item has the class responded to distinguish it from the other list items that haven't been checked. There are other ways to find which of them are checked, not necessary difficult but they require more code. The class checking is brief and intuitive I think.

Birthe Vandermeeren
Birthe Vandermeeren
17,146 Points

Thanks for your reply, Anastasios! I think my question wasn't clear enough. I too checked the class, but checked for it to not be equal to responded instead of it to be equal to responded. In the else statement, i set them to visible, while Guil sets display to none in the else statement. I wanted to know if there's a reason for doing so, if that's the better way to do it. I my head it makes more sense to do it like I did. :) Doesn't really matter I guess.

2 Answers

I think I get what you're saying. I assume that Guil put the else for readability. You can omit the else clause if you check for the list item to not have the class responded, like you did.

Kristaps Buls
Kristaps Buls
3,656 Points

I kind of was thinking that also. you get 3 lines less if you just write. if (li.className !== 'responded') { li.style.display = 'none'; } no else needed.