Guest User

Untitled

a guest
Nov 14th, 2018
100
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.69 KB | None | 0 0
  1. const INGREDIENT_PRICES = {
  2. salad: 5,
  3. cheese: 10,
  4. meat: 20,
  5. bacon: 10
  6.  
  7. state ={
  8. ingredients: {
  9. salad: 0,
  10. bacon : 0,
  11. cheese: 0,
  12. meat: 0
  13. },
  14. totalPrice: 30,
  15. purchaseble: false
  16. }
  17.  
  18. addIngredientHandler = (type) => {
  19. const oldCount = this.state.ingredients[type];
  20. const updatedCount = oldCount +1;
  21. const updatedIngredients = {
  22. ...this.state.ingredients
  23. };
  24. updatedIngredients[type] = updatedCount;
  25. const priceAddition = INGREDIENT_PRICES[type];
  26. const newPrice = this.state.totalPrice + priceAddition
  27. this.setState({totalPrice: newPrice, ingredients: updatedIngredients})
  28. this.updatePurchaseState();
  29. }
Add Comment
Please, Sign In to add comment