Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- const ingredientId = {
- salad: 'Salad',
- carotte: 'Carotte',
- };
- class Recipe {
- constructor(ingredientList = {}) {
- this.ingredients = ingredientList;
- }
- getAmount(ingredientId) {
- const amount = this.ingredients[ingredientId];
- if (amount) return amount;
- return 0;
- }
- }
- const i = new Recipe({ salad: 2, carotte: 4 });
- const amount = i.getAmount(ingredientId.salad); // Expected to be 2
- console.log(`Amount = ${amount}`);
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement