Skip to content
  • Unlock Pro
  • Log in with GitHub
Solution
Submitted about 4 years ago

static-job-listings-master

Jay•695
@Junjiequan
A solution to the Job listings with filtering challenge
View live sitePreview (opens in new tab)View codeCode (opens in new tab)

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.

Code
Select a file

Please log in to post a comment

Log in with GitHub

Community feedback

  • Raymart Pamplona•16,040
    @pikapikamart
    Posted about 4 years ago

    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^^

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
Frontend Mentor logo

Stay up to datewith new challenges, featured solutions, selected articles, and our latest news

Frontend Mentor

  • Unlock Pro
  • Contact us
  • FAQs
  • Become a partner

Explore

  • Learning paths
  • Challenges
  • Solutions
  • Articles

Community

  • Discord
  • Guidelines

For companies

  • Hire developers
  • Train developers
© Frontend Mentor 2019 - 2025
  • Terms
  • Cookie Policy
  • Privacy Policy
  • License

Oops! 😬

You need to be logged in before you can do that.

Log in with GitHub

Oops! 😬

You need to be logged in before you can do that.

Log in with GitHub

How does the accessibility report work?

When a solution is submitted, we use axe-core to run an automated audit of your code.

This picks out common accessibility issues like not using semantic HTML and not having proper heading hierarchies, among others.

This automated audit is fairly surface level, so we encourage to you review the project and code in more detail with accessibility best practices in mind.

How does the CSS report work?

When a solution is submitted, we use stylelint to run an automated check on the CSS code.

We've added some of our own linting rules based on recommended best practices. These rules are prefixed with frontend-mentor/ which you'll see at the top of each issue in the report.

The report will audit 1st-party linked stylesheets, and styles within <style> tags.

How does the HTML validation report work?

When a solution is submitted, we use html-validate to run an automated check on the HTML code.

The report picks out common HTML issues such as not using headings within section elements and incorrect nesting of elements, among others.

Note that the report can pick up “invalid” attributes, which some frameworks automatically add to the HTML. These attributes are crucial for how the frameworks function, although they’re technically not valid HTML. As such, some projects can show up with many HTML validation errors, which are benign and are a necessary part of the framework.

Oops! 😬

You need to be logged in before you can do that.

Log in with GitHub