MCPcopy Create free account
hub / github.com/SuperSimpleDev/javascript-course / addToCart

Function addToCart

2-copy-of-code/lesson-14/data/cart.js:17–36  ·  view source on GitHub ↗
(productId)

Source from the content-addressed store, hash-verified

15}
16
17export function addToCart(productId) {
18 let matchingItem;
19
20 cart.forEach((cartItem) => {
21 if (productId === cartItem.productId) {
22 matchingItem = cartItem;
23 }
24 });
25
26 if (matchingItem) {
27 matchingItem.quantity += 1;
28 } else {
29 cart.push({
30 productId: productId,
31 quantity: 1
32 });
33 }
34
35 saveToStorage();
36}
37
38export function removeFromCart(productId) {
39 const newCart = [];

Callers 1

amazon.jsFile · 0.90

Calls 1

saveToStorageFunction · 0.70

Tested by

no test coverage detected