Not Found
Not Found
Not Found
Not Found
Not Found
Not Found
Not Found
Not Found
Not Found
Not Found
Not Found
Not Found
Not Found
Not Found
Not Found
Not Found
Not Found
Not Found
Not Found
Not Found

Submitted

static-job-listings-master

Jay 695

@Junjiequan

Desktop design screenshot for the Job listings with filtering coding challenge

This is a solution for...

  • HTML
  • CSS
  • JS
3intermediate
View challenge

Design comparison


SolutionDesign

Solution retrospective


This is pure javascript based solution.

//Not like I want to but because all I know is just some basics of javascript at the moment.

This challenge was beyond my skill level. But somehow I managed to "complete" it with some bugs (filter logic related ).

To point out the bug. Click "frontend ", "css" and "javascript" in order, then remove "css" tag. In this case, the filter somehow doesn't work and contents with 'frontend' and 'javascript' tag doesn't refresh properly.

I would be really grateful if anyone could point out potential issues with the JS code and give me some NOOB friendly advices.(I highlighted possible issue causing area with comments in JS file.)

Lastly, any kinds of feedback are greatly appreciated.

Community feedback

@pikapikamart

Posted

Hey, great work on this one. For the UI, the layout is good and I am sure by now, you are a fan of spiniru (that is what I call on small spinning things in web) and the mobile state is good as well.

But the real problem is the filter does not properly runs. Though when clicking the clear all, it works just fine.

Upon looking your javascript, well it is fine until this section which you highlighted.

store.forEach(each=>{       
            const checkValue = tagArrays.includes(each);
            if(checkValue){
                if(store.length <= 1){      // <<<<<<<<<<< this logic is definitely deficient
                    jobListingWrapper.classList.add('marked')
                };
            }else if(jobListingWrapper.classList.contains('marked')){
                jobListingWrapper.classList.remove('marked')
            }
        })
        if(jobListingWrapper.classList.contains('marked')){
            jobListingWrapper.style.display = "flex";
        }

As you can see, the reason it won't filter properly because you loop for every item of the store right, but you are declaring const checkValue = tagArrays.includes(each); every time it runs. So meaning whatevery is the last value of the store is the one that will determine if the item will be filtered or not.

Let's see an example.

Imagine this is the filter bar [ Frontend, css, javascript, react, sass]

If i removed the sass the code will run right, so it will loop for every item in the filter bar, which are Frontend, css, javascript, react. But as I said, only the last one will determine if an item will be filtered, because you are repeating the declaration of const checkValue = tagArrays.includes(each);. So everytime it runs, the result will change. So first run, the checkValue checks if tagArrays includes FrontEnd if it does then the if statement will run, the next loop it checks again if the tagArrays includes css. As you can see, only the last will determine the outcome.

To fix this, remove that whole section, and instead add this.

if (store.every(item => tagArrays.includes(item))) {
            jobListingWrapper.classList.add("marked");
            jobListingWrapper.style.display = "flex";
        } else {
            jobListingWrapper.classList.remove("marked");
        }

This way, it will only run one time, and it will check if every item in the store is included in the tagArrays. If all 4 example, Frontend, css, javascript, react is present, then it runs, if it does not. Then it won't display the item.

So in whole, this section will be present

jobTagsGroup.forEach(index=>{   
        const jobListingWrapper = index.closest('.job-listing-wrapper')
        jobListingWrapper.style.display = "none";

        //convert tags list into readable string arrays
        const tagArrays = index.textContent.replace(/\s+/g, ' ').trim().split(' ') 

        if (store.every(item => tagArrays.includes(item))) {
            jobListingWrapper.classList.add("marked");
            jobListingWrapper.style.display = "flex";
        } else {
            jobListingWrapper.classList.remove("marked");
        }
    })

But still, good work on this one okay and if need help, just drop it here okay^^

2

Jay 695

@Junjiequan

Posted

@pikamart

I can't thank you enough for your efforts explaning details to me with examples.

You are truly my savior.

The exaplanation is really clear and thorough, it solved all of my problems regarding the filter logic.😆

I can see now, const checkValue = tagArrays.includes(each) was the key point that causes all of the problems. I was thinking it loops along with the parent loop and returns boolen value for each one of the arrays .

I've had spent over 10 hours trying to figure out how to make the filter and ended up with that logic deficient filter which is not even working properly .😂

btw, regarding the spinner wheel embeded, which is actually a color theme button, but I guess it wasn't a optimal way to present a color theme changer like that.

anyways, Thank you sooooooo much.😆

0

@pikapikamart

Posted

@a331998513 Hey, glad that it worked just fine and you're welcome on that one, that's what we do here in FEM^^

0

Please log in to post a comment

Log in with GitHub
Discord logo

Join our Discord community

Join thousands of Frontend Mentor community members taking the challenges, sharing resources, helping each other, and chatting about all things front-end!

Join our Discord