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

Function addToCart

2-copy-of-code/lesson-18/data/cart.js:25–45  ·  view source on GitHub ↗
(productId)

Source from the content-addressed store, hash-verified

23}
24
25export function addToCart(productId) {
26 let matchingItem;
27
28 cart.forEach((cartItem) => {
29 if (productId === cartItem.productId) {
30 matchingItem = cartItem;
31 }
32 });
33
34 if (matchingItem) {
35 matchingItem.quantity += 1;
36 } else {
37 cart.push({
38 productId: productId,
39 quantity: 1,
40 deliveryOptionId: '1'
41 });
42 }
43
44 saveToStorage();
45}
46
47export function removeFromCart(productId) {
48 const newCart = [];

Callers 2

renderProductsGridFunction · 0.90
cartTest.jsFile · 0.90

Calls 1

saveToStorageFunction · 0.70

Tested by

no test coverage detected