Doubt how to solve this question, i have tried but i am fail

groceries( [{item: ‘Carrots’}, {item: ‘Hummus’}, {item: ‘Pesto’}, {item: ‘Rigatoni’}] );
// returns ‘Carrots, Hummus, Pesto and Rigatoni’

hey, buddy! can you also post the groceries function so we can see how it works and maybe help you find out where things are going wrong?

from your return statement, I would assume that at some point your code iterates through an array (the argument) and then prints the value of each object’s item property.
So, going out on a limb, I’d guess you have a line somewhere that has the object.item returning ‘Carrots’ or ‘Hummus’ or whatever.
You probably return/log something like console.log(`${firstItem}, ${secondItem}, ${etc} and ${lastItem}`)

If you post the code for the groceries() function, I might be more helpful, but I hope this may be of use =] cheers

Hello everyone. My approach on this was the following, though it seems I have a syntax error, as the Check answer reveals. Do you think you could help me? :slight_smile: Thank you very much!

// Write function below function groceries(obj) { if (Object.keys(obj).length === 1) { return obj[0].item; } else if (Object.keys(obj).length === 2) { return obj[0].item + ' and ' + obj[1].item; } else { let sentence = ''; for (i = 0; i < Object.keys(obj).length - 2; i++) { sentence += obj[i].item + ', ' } return sentence + obj[i].item + ' and ' + obj[i+1].item } } console.log(groceries( [{item: 'Carrots'}, {item: 'Hummus'}, {item: 'Pesto'}, {item: 'Rigatoni'}] ));