Skip to content
  • Unlock Pro
  • Log in with GitHub
Solution
Submitted over 3 years ago

ARTICLE PREVIEW COMPONENT using Flexbox and Vanilla JavaScript

Ken•935
@kenreibman
A solution to the Article preview component challenge
View live sitePreview (opens in new tab)View codeCode (opens in new tab)

Solution retrospective


Wow, this took so long to make. After countless hours of studying JavaScript, watching crash courses and tutorials. I was finally able to create a simple pop-up on a page.

I'm very confident in HTML and CSS now, especially Flexbox. I hope I can have challenges that push me to utilize more CSS Grid. I also appreciate the challenge and countless hours of studying I went through to learn a little JavaScript.

I am still in the learning process of vanilla JavaScript, and I know the code I wrote for the pop-up is not exactly the cleanest. If anyone has feedback on how I can make the code cleaner, or acceptable for the industry, I would greatly appreciate any sort of feedback that you give me out of your time.

Code
Select a file

Please log in to post a comment

Log in with GitHub

Community feedback

  • Ken•4,915
    @kens-visuals
    Posted over 3 years ago

    Hey @lmaoken 👋🏻

    I took a look at your JS as you asked, and here are some suggestions:

    • First, it would be really great if you declared variables for all the selections, so you don't have to write document.querySelector('') each time. For example:
    const btn = document.querySelector('.btn__share');
    

    of course you should use more descriptive names, this was just a demonstration.

    • Next, I suggest creating classes in CSS and give all the styling that should be applied to the button or whatever you're toggling and then in JS just add and remove those classes or even better use toggle method. You can check out my **solution to see how to do it. When, you give styles with .style it adds inline styling, and then it's pretty much stuck in your HTML, unless you refresh the page, so it would be a lot better to implement those styles in CSS then play with the classes in JS.
    • Lastly, you should add `aria-expanded="false" in HTML, and then according to the state of the pop-up change to true, I also have that implemented in my solution.

    I hope this was helpful 👨🏻‍💻 other than that, you did a superb job, I knew you got this and this is just the begging. You've got a lot to do and to practice, but you'll get there, trust me. Cheers 👾

    Marked as helpful

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 all CSS, SCSS and Less files in your repository.

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.

How does the JavaScript validation report work?

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

The report picks out common JavaScript issues such as not using semicolons and using var instead of let or const, among others.

The report will audit all JS and JSX files in your repository. We currently do not support Typescript or other frontend frameworks.

Oops! 😬

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

Log in with GitHub