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 trialRavel Oliveira
Front End Web Development Techdegree Student 10,337 PointsWhy am i getting the 'Bummer: Both the `reduce` and `filter` methods have not been called yet.' ERROR?
I tested my code in the console and it worked by getting the result 9.47, but when i try to check the exercise it send me the error "Bummer: Both the reduce
and filter
methods have not been called yet" and i dont know why. I used the code below:
groceryTotal = purchaseItems .filter(item => item.dept === 'groceries') .reduce((total, itemPrice) => total + itemPrice.price, 0).toFixed(2);
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.dept === 'groceries')
.reduce((total, itemPrice) => total + itemPrice.price, 0).toFixed(2);
1 Answer
Travis Alstrand
Treehouse Project ReviewerHi there Ravel Oliveira 👋
I was toying around with your code for a bit and realized it was the .toFixed(2)
being added to the end that was throwing the whole thing off. After removing that your code worked perfectly
groceryTotal = purchaseItems
.filter(item => item.dept === 'groceries')
.reduce((total, itemPrice) => total + itemPrice.price, 0);
Unfortunately, it seems it's another scenario where a simple addition of something (or sometimes a lack of something) was triggering the failure, but the error message provided was not helpful in that scenario. Sorry for that inconvenience!
Nice work!