Skip to content
This repository has been archived by the owner on Oct 29, 2024. It is now read-only.

Number of Items Issue Solved #93

Merged
merged 3 commits into from
Oct 13, 2022
Merged

Number of Items Issue Solved #93

merged 3 commits into from
Oct 13, 2022

Conversation

ranjankuldeep
Copy link
Contributor

#92

The Cart is working as expected now.

Here is the ScreenShot showing correct number of items.

I have tested many possibilities of adding to the cart and editing in the cart, Everythings work fine.

Screenshot 2022-10-12 at 4 10 54 PM

@roopeshsn

@@ -23,7 +23,7 @@ const CartScreen = ({ match, location, history }) => {
const { cartItems } = cart

const cartItemsPrice = cartItems.reduce(
(acc, item) => acc + item.qty * item.price,
(acc, item) => acc + +item.qty * +item.price,
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What did this plus sign (+) do?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The unary plus operator (+) precedes its operand and evaluates to its operand but attempts to convert it into a number, if it isn't already.

It basically makes string to number.
So these are now no longer added as string but as a number.
@roopeshsn

Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why have you not used a function? It will improve readability instead of using the unary plus operator.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We can also go with the parseInt(),
But i choosen '+' operator here.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ohhk so I will make the changes.
Will be using function now .

@roopeshsn
Copy link
Owner

Also, format the code using the prettier command. Check the package.json file.

@ranjankuldeep
Copy link
Contributor Author

Please Review,
I have made the necessary changes. @roopeshsn

@@ -79,7 +79,7 @@ const CartScreen = ({ match, location, history }) => {
<Form.Control
as="select"
size="sm"
value={item.qty}
value={+item.qty}
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why have you not changed here?

@@ -116,7 +116,7 @@ const CartScreen = ({ match, location, history }) => {
<ListGroup variant="flush">
<ListGroup.Item>
<h5>
Subtotal ({cartItems.reduce((acc, item) => acc + item.qty, 0)})
Subtotal ({cartItems.reduce((acc, item) => acc + +item.qty, 0)})
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Here too

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ahh, I missed that.

@roopeshsn
Copy link
Owner

roopeshsn commented Oct 13, 2022

Whether the changes didn't affect the working of the application right? Have you formatted the code using prettier?

@ranjankuldeep
Copy link
Contributor Author

I made the changes in the cart screen.
@roopeshsn

@roopeshsn
Copy link
Owner

Whether there the changes didn't affect the working of the application right? Have you formatted the code using prettier?

Reply appropriately!

@ranjankuldeep
Copy link
Contributor Author

yes i formatted ,
i run the command

npm run prettier 

I didn't get the first question.

@ranjankuldeep
Copy link
Contributor Author

The application is working fine now.
I added changes only where quantity was involved so that it won't break at any point

@roopeshsn roopeshsn merged commit 3b44a4c into roopeshsn:master Oct 13, 2022
@roopeshsn roopeshsn added the hacktoberfest-accepted Accepted PR for hactoberfest label Oct 13, 2022
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
hacktoberfest-accepted Accepted PR for hactoberfest
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants