Skip to content
  • Unlock Pro
  • Log in with GitHub
Solution
Submitted about 1 year ago

FINALLY INPUT ECOMMERCE-PRODUCT-PAGE-MAIN

bootstrap
Ezequiel de Souza Rodrigues•150
@ezequieldesr
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?

It was to have made the functionality of adding the cart and deleting it.

const cartIcon = document.getElementById("cartIcon"); const cartCard = document.getElementById("cartCard"); const cartText = document.querySelector(".cart-text") const quantityInput = document.getElementById("quantity"); const btnBuy = document.querySelector(".btn-buy"); const cartItem = document.querySelector(".cart-item"); const cartPrice = document.querySelector(".cart-price") const cartNumbers = document.querySelector(".cart-numbers") const btnCheckout = document.querySelector(".btn-checkout") ``cartIcon.addEventListener("click", function () { if (cartCard.style.display === "none" || cartCard.style.display === "") { cartCard.style.display = "block"; } else { cartCard.style.display = "none"; } }); document.addEventListener("click", function (event) { if (!cartIcon.contains(event.target) && !cartCard.contains(event.target)) { cartCard.style.display = "none"; } }); productImage.addEventListener("click", function () { modal.style.display = "block"; });

closeModal.addEventListener("click", function () {
    modal.style.display = "none";
});

window.addEventListener("click", function (event) {
    if (event.target === modal) {
        modal.style.display = "none";
    }
});

window.increment = function () {
    var quantity = document.getElementById("quantity");
    quantity.value = parseInt(quantity.value) + 1;
};

window.decrement = function () {
    var quantity = document.getElementById("quantity");
    if (parseInt(quantity.value) > 0) {
        quantity.value = parseInt(quantity.value) - 1;
    }
};

window.addToCard = function () {
    const quantity = parseInt(quantityInput.value)
    if (quantity > 0) {
        const pricePerItem = 125.00;
        const totalPrice = pricePerItem * quantity;

        cartText.style.display = "none"

        cartItem.style.display = "block"
        btnCheckout.style.display = "block"

        cartNumbers.textContent = quantity
        cartPrice.textContent = `$${totalPrice.toFixed(2)}`

        circleResult.textContent = quantity
        circleResult.style.display = "block"
        circleResult.style.textAlign = "center"
        circleResult.style.fontSize = "10px"
        circleResult.style.fontWeight = "bold"
    }
}

btnBuy.addEventListener("click", addToCard)

deleteIcon.addEventListener("click", function () {
    cartItem.style.display = "none"
    btnCheckout.style.display = "none"
    cartText.style.display = "flex"
    circleResult.style.display = "none"
})

});

``

What challenges did you encounter, and how did you overcome them?

THE LIGHTBOX FEATURE I know perfectly well that the code is not clean. But I swear I tried everything to finish my last feature, which is when I click on the main image: image-product-1.jpg, the transparent window of the product appears. I'm dumb for using pure HTML CSS and JS, despite having used Bootstrap, I found it very difficult to do this last feature.

What specific areas of your project would you like help with?

PLEASE if someone can make the project working using JS, without a framework, send a suggestion message.

Code
Loading...

Please log in to post a comment

Log in with GitHub

Community feedback

  • Hale•330
    @halelite
    Posted about 1 year ago

    Hi @EzequielSR!

    Good job! your solution looks great and is very similar to the design provided.

    I have also done this project using pure JavaScript, and I'm very well aware of the challenges one might face while completing it. So congratulations as you have done a very great job!

    This is the approach I took:

    • For the slider in the modal, I have used almost the same functionality I wrote for the slider in the main component since they are very similar.

    • For the transparent background and the last feature you mentioned, I gave the container of the thumbnail images a white background. I also have defined an image-active class, so when the image is clicked the opacity of the image changes to 25%.

    This is the HTML:

    <div id="thumbnail" class="active">
        <img src="./images/image-product-1-thumbnail.jpg" class="image-active">
    </div>
    

    And the styles:

    #thumbnail {
        background: hsl(0, 0%, 100%);
        mix-blend-mode: darken;
    }
    
    .active {
        border: 2px solid hsl(26, 100%, 55%);
    }
    
    .image-active {
        filter: opacity(25%);
    }
    

    Of course, there may be much better ways to implement these features, and these are just suggestions.

    I hope it helps!

    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