Advertisement
Guest User

Untitled

a guest
Dec 9th, 2019
121
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. const ingredientId = {
  2.   salad: 'Salad',
  3.   carotte: 'Carotte',
  4. };
  5.  
  6. class Recipe {
  7.   constructor(ingredientList = {}) {
  8.     this.ingredients = ingredientList;
  9.   }
  10.  
  11.   getAmount(ingredientId) {
  12.     const amount = this.ingredients[ingredientId];
  13.     if (amount) return amount;
  14.     return 0;
  15.   }
  16. }
  17.  
  18. const i = new Recipe({ salad: 2, carotte: 4 });
  19. const amount = i.getAmount(ingredientId.salad); // Expected to be 2
  20. console.log(`Amount = ${amount}`);
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement