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

Ewerton Luna
Ewerton Luna
Full Stack JavaScript Techdegree Student 14,346 Points

When I check the checkbox, it hides the li correctly, but when I uncheck, the items are not displayed back again.

My code is exactly equal to Guil's (or I think it is).

filterCheckbox.addEventListener('change', (event) => {
    const isChecked = event.target.checked;
    const lis = ul.children;
    if (isChecked) {
        for (let i = 0; i < lis.length; i += 1) {
            let li = lis[i];
            if (li.className === 'responded') {
                li.style.display = '';
            }
            else {
                li.style.display = 'none';
            }
        }
    } else {
        for (let i = 0; i < lis.length; i += 1) {
            let li = lis[i];
            li.style.display = '';
        }
    }

});

Why is it not working properly? Am I missing something?

2 Answers

KRIS NIKOLAISEN
PRO
KRIS NIKOLAISEN
Pro Student 51,979 Points

You have filterCheckbox.addEventListener twice in your code. The second one doesn't have an else statement but should be deleted anyways.

KRIS NIKOLAISEN
PRO
KRIS NIKOLAISEN
Pro Student 51,979 Points

You may have to post more code - or better yet a snapshot. I tried your code and it worked. It's not exactly the same in that the B in Box of filterCheckBox is uppercase, but that would have produced a different error. Is there anything in the console and can you post a snapshot?