So I have an array of objects that looks like:
list = [firstObject {name: 'a', price: 0.5, quantity: 5, total: 2.5},
secondObject {name: 'b', price: 2, quantity: 2, total: 4},
thirdObject {name: 'd', price: 2, quantity: 1, total: 2}]
I'm trying to write a function that would allow me to print something like
- 5 a's costs $2.5
- 2 b's costs $4
1 c costs $2
The total was $8.50
So far I have something like
let summary = (name, quantity, total) => {
let item = list.name;
let amount = list.quantity;
let cost = list.total;
return (`${amount} ${item} costs ${cost}`);
};
But it obviously doesn't work. I guess I'm a little confused as to how to go about how to properly access the values in those objects with my function. Any input would be greatly appreciated!