-
Notifications
You must be signed in to change notification settings - Fork 30
/
_W4D3.js
34 lines (30 loc) · 1.22 KB
/
_W4D3.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
/*
Write a function called onlyPayForHealthyThings, that takes an array of objects.
Each object is a grocery item with the following properties: name, nutritionalValue, price.
The nutritionalValue is also an object, which has the following properties: lowSugar, lowSodium
Your function should add the prices of all the items in the array if the item is true for both lowSugar and lowSodium
Finally, your function should return the sum total of all the healthy items
function onlyPayForHealthyThings(foodList) {
}
var myCart = [
{ name: 'chips',
nutritionalValue: { lowSugar: true, lowSodium: false },
price: 0.75 },
{ name: 'carrots',
nutritionalValue: { lowSugar: true, lowSodium: true },
price: 1.5 },
{ name: 'cookies',
nutritionalValue: { lowSugar: false, lowSodium: true },
price: 2.5 },
{ name: 'apples',
nutritionalValue: { lowSugar: true, lowSodium: true },
price: 0.6 },
{ name: 'soda',
nutritionalValue: { lowSugar: false, lowSodium: true },
price: 1.1 },
{ name: 'avocados',
nutritionalValue: { lowSugar: true, lowSodium: true },
price: 0.75 }
];
Calling onlyPayForHealthyThings(myCart) should return 2.85 from adding the prices of "carrots", "apples", and "avocados"
*/