Last active
April 17, 2023 19:21
-
-
Save isaacviannadev/507147a35bf973acc47c6db57fe2f869 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| function addProduct(id) { | |
| let cart = JSON.parse(localStorage.getItem("products")) || []; | |
| const foundItem = cart.find((product) => product.id === id); | |
| if (foundItem) { | |
| foundItem.quantidade++; | |
| } else { | |
| cart.push({ id: id, qtd: 1 }); | |
| } | |
| localStorage.setItem("products", JSON.stringify(cart)); | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment