JavaScript Practice: Arrays, Loops, Objects, Iterators. groceries()

Hello everyone :slight_smile:
I’ve been running and testing the grocery shop exercise on the console and as I can tell it is working as expected but I’m not passing the tests for the coding question.

This is the code I’m using:

const groceries =(arr) => {
arr= arr.map(i=> i.item )
arr.splice(-1,0,‘and’)

return arr
}

I appreciate your support, thank you
My code testing

What if there is only one item in the list?

You haven’t included a link to the exercise. But based on the feedback in the screenshot, the returned value is supposed to be a string. You are returning an array instead.

I fixed that part, adding an if to check the length.

I fixed that by converting the array to a string and adding the (,) but now I do not know how to remove the (,) after the (and)

This topic was automatically closed 41 days after the last reply. New replies are no longer allowed.