Skip to content
  • Unlock Pro
  • Log in with GitHub
Solution
Submitted 6 months ago

E-COMMERCE PRODUCT PAGE HTML | CSS | JS

Hendrixx•430
@BeeAlmighty
A solution to the E-commerce product page challenge
View live sitePreview (opens in new tab)View codeCode (opens in new tab)

Solution retrospective


What are you most proud of, and what would you do differently next time?
  • This is one of the most challenging projects i have taken on in a while and i feel so good to have at least taken an attempt to making my solution as close as possible to the design.
  • I know there are always better ways to do things and there is always room for improvements but honestly, i cannot see how i could have done things differently.
What challenges did you encounter, and how did you overcome them?
  • It was a hassle trying to implement both the lightbox and the carousel / slideshow but with the help of Stack overflow and W3 schools, i was able to tackle the problem and provide a good solution.
What specific areas of your project would you like help with?
  • The code base is quite lengthy so kudos to who takes out time to assess my solution, i would like alternative approaches to the problem and also best practices.
Code
Select a file

Please log in to post a comment

Log in with GitHub

Community feedback

  • Aakash Verma•9,500
    @skyv26
    Posted 6 months ago

    Hi @BeeAlmighty,

    You've done a commendable job putting together the JavaScript for this project! The code works well and showcases your learning journey. 🚀 However, there are a few areas where you can improve to make the code cleaner, more readable, and aligned with best practices. Here are my suggestions:


    🛠 Code Suggestions:

    1. Use Arrow Functions:
      Instead of traditional function declarations, you can simplify with arrow functions for consistency and brevity. For example:

      const openModal = () => {
          document.getElementById("myModal").style.display = "block";
      };
      
    2. Follow the DRY Principle:
      There are repetitive code patterns, especially in the showSlides and showSlides2 functions. Consider creating a helper function that handles both scenarios dynamically based on parameters (like the class names or indices).

    3. Shortcuts for Querying Elements:
      Instead of calling document.querySelector repeatedly, you can store frequently accessed elements in a central object or use a utility function for querying:

      const $ = (selector) => document.querySelector(selector);  
      const sidebar = $('.nav--sidebar');  
      
    4. Add Meaningful Variable Names:
      Some variable names (e.g., docBod, docBody, itemCart) could be more descriptive. Consistent naming will make the code more intuitive.

    5. Reduce Global Variables:
      To avoid potential conflicts and improve modularity, wrap the related code into a single object or IIFE (Immediately Invoked Function Expression).

    6. Spacing for Readability:
      Add blank lines between sections of your code. For example, separate sidebar-related code, cart operations, and carousel code into distinct blocks.


    💡 Best Practices:

    • Add Comments: Briefly explain what each function or block of code does. This will make it easier to understand and maintain.
    • Group Logic: Use modular design by separating different functionalities (e.g., cart, sidebar, carousel) into distinct classes or modules.
    • Event Delegation: For elements like addCartBtn or delIcon, you can use event delegation to attach a single listener to a parent element.

    🏆 Overall Feedback:

    • Your code demonstrates a solid understanding of DOM manipulation and event handling. 👏
    • Although the script is lengthy, it’s effective. Refactoring the repetitive parts will make it more concise and maintainable.
    • The output is impressive, and it’s clear you’ve put a lot of effort into learning through this project!

    ⭐ Action Plan:

    1. Refactor repetitive logic like showSlides and showSlides2 into a single function.
    2. Use arrow functions and reduce redundant selectors with utilities like querySelector.
    3. Modularize your code into logical sections for improved readability and debugging.

    Let me know if you need help implementing these improvements. You're on the right track—keep going! 🌟

    Best,
    Aakash 😊

    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

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