Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add quantity col #1

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 1 addition & 2 deletions src/App.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,7 @@ import Total from './components/total/total'
class App extends Component {
state = {
items: [
{id:1, product:'Pen', price:2},
{id:2, product:'Book', price:10}

]
}

Expand Down
8 changes: 6 additions & 2 deletions src/components/addItem/addItem.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,8 @@ import React, {Component} from 'react';
class addItem extends Component {
state = {
product: '',
price: ''
price: '',
quantity:''
}

handleChange = (e) => {
Expand All @@ -18,7 +19,8 @@ class addItem extends Component {
this.props.add(this.state)
this.setState({
product: '',
price: ''
price: '',
quantity:''
})
}

Expand All @@ -28,6 +30,8 @@ class addItem extends Component {
<form onSubmit={this.handleSubmit}>
<input type="text" value={this.state.product} placeholder="Enter Product" id="product" onChange={this.handleChange} required/>
<input type="number" value={this.state.price} placeholder="Enter Price" id="price" onChange={this.handleChange} required/>
<input type="number" value={this.state.quantity} placeholder="Enter Quantity" id="quantity" onChange={this.handleChange} required/>

<input type="submit" value="Add"/>
</form>
</div>
Expand Down
2 changes: 2 additions & 0 deletions src/components/item/items.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ const Items = (props) => {
<div key={item.id} className="item">
<p>{item.product}</p>
<p>{item.price}</p>
<p>{item.quantity}</p>
<p className="delete" onClick={() => del(item.id)}>&times;</p>
</div>
)
Expand All @@ -21,6 +22,7 @@ const Items = (props) => {
<div className="header item">
<p>Product</p>
<p>Price</p>
<p>Quantity</p>
<p>Edit</p>
</div>
{ListItem}
Expand Down
2 changes: 1 addition & 1 deletion src/components/total/total.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ const Total = (props) => {
const {items} = props;
let total = 0
for (let i = 0; i < items.length; i++) {
total += parseFloat(items[i].price)
total += parseFloat(items[i].price *items[i].quantity)
}
return (
<div>
Expand Down