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

Product cart notification using flexbox and javascript

@MiguelAponte18

Desktop design screenshot for the Product preview card component coding challenge

This is a solution for...

  • HTML
  • CSS
1newbie
View challenge

Design comparison


SolutionDesign

Solution retrospective


I have made that when you press the "add to cart" button, a notification comes out and that when you press the button in the corner with the cart, it tells you the product that you added. How can I make the corner button only have to be pressed once and not twice?. Any advice to improve is welcome :)

Community feedback

@Daniel77apr

Posted

Hey, Miguel!

I,ve had this problem before. Try using b.style.visibility!='visible' instead of b.style.visibility=='hidden' as the condition in your last function like this:

cart.addEventListener('click', function hola(){
    b.style.visibility!='visible'? b.style.visibility='visible': b.style.visibility='hidden';
});

I'm not sure why (beginner here), but I have noticed that JavaScript does not recognize property values previously added in CSS, only the ones added in JavaScript. So basically, after loading the page with the previous code, b.style.visibility=='hidden' returns false, and when you click for the first time, b.style.visibility='hidden' is run. Now that JavaScript added the hidden value, b.style.visibility=='hidden' returns true when clicking a second time and b.style.visibility='visible' is run. The new code solves this since b.style.visibility!='visible' returns true after loading the page.

Hope this helps!

0

@VCarames

Posted

Hey there! 👋 Here are some suggestions to help improve your code:

  • The Alt Tag Description for the image needs to be improved upon. You want to describe what the image is; they need to be readable. Assume you’re describing the image to someone.

  • The old price 🏷 is not being announced properly to screen readers. You want to wrap it in a Del Element and include a sr-only text explaining that this is the old price.

  • Implement a Mobile First approach 📱 > 🖥

With mobile devices being the predominant way that people view websites/content. It is more crucial than ever to ensure that your website/content looks presentable on all mobile devices. To achieve this, you start building your website/content for smaller screen first and then adjust your content for larger screens.

If you have any questions or need further clarification, let me know.

Happy Coding! 👻🎃

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