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

Birthe Vandermeeren
Birthe Vandermeeren
17,139 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

Anastasios Poursaitedes
Anastasios Poursaitedes
6,935 Points

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,139 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

Anastasios Poursaitedes
Anastasios Poursaitedes
6,935 Points

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.