Welcome to the Treehouse Community
Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.
Looking to learn something new?
Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.
Start your free trialBrian Johnson
Front End Web Development Techdegree Graduate 20,818 PointsThese JavaScript problems are difficult. Can someone tell me what I'm wrong?
Thank you in advance
const purchaseItems = [
{
name: 'apples',
dept: 'groceries',
price: 2.49
},
{
name: 'bread',
dept: 'groceries',
price: 2.99
},
{
name: 'batteries',
dept: 'electronics',
price: 5.80
},
{
name: 'eggs',
dept: 'groceries',
price: 3.99
},
{
name: 't-shirts',
dept: 'apparel',
price: 9.99
}
];
let groceryTotal;
// groceryTotal should be: 9.47
// Write your code below
groceryTotal = purchaseItems
.filter(item => item.price > 10)
.reduce((sum, price) => sum + item.price, 0);
2 Answers
Steven Parker
231,268 PointsCongratulations on resolving your issue!
For the benefit of other students, there are two issues in the code:
- the filter should select items in the grocery department instead of items with a price over 10
- the second parameter of the function in "reduce" should be named "item" instead of "price"
Brian Johnson
Front End Web Development Techdegree Graduate 20,818 PointsThanks Steve
Brian Johnson
Front End Web Development Techdegree Graduate 20,818 PointsBrian Johnson
Front End Web Development Techdegree Graduate 20,818 PointsNevermind I figured it out! Thanks