-
Notifications
You must be signed in to change notification settings - Fork 58
Conversation
frontend/src/screens/CartScreen.js
Outdated
@@ -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, |
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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 .
Also, format the code using the prettier command. Check the package.json file. |
Please Review, |
frontend/src/screens/CartScreen.js
Outdated
@@ -79,7 +79,7 @@ const CartScreen = ({ match, location, history }) => { | |||
<Form.Control | |||
as="select" | |||
size="sm" | |||
value={item.qty} | |||
value={+item.qty} |
There was a problem hiding this comment.
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?
frontend/src/screens/CartScreen.js
Outdated
@@ -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)}) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Here too
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ahh, I missed that.
Whether the changes didn't affect the working of the application right? Have you formatted the code using prettier? |
I made the changes in the cart screen. |
Reply appropriately! |
yes i formatted ,
I didn't get the first question. |
The application is working fine now. |
#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.
@roopeshsn