Bug in my code or codecademy?

I attempted the last challenge from the Javascript II, JavaScript Practice: Arrays, Loops, Objects, Iterators article, I managed to get my code to return the correct answer however the program tells me my output is not correct. Is there an invisible problem in my code? When I console.log() arrays it outputs the correct string.

Here is the question:

Write a function groceries() that takes an array of object literals of grocery items. The function should return a string with each item separated by a comma except the last two items should be separated by the word 'and' . Make sure spaces ( ' ' ) are inserted where they are appropriate.

Here is my Code:

const food = [{item: 'Carrots'}, {item: 'Hummus'}, {item: 'Pesto'}, {item: 'Rigatoni'}]

const list = []
function groceries (array) {
  for (let i = 0; i < array.length; i++){
    if (i < array.length - 2){
  list.push(array[i].item + ',')
    }
    else if ( i == array.length - 2){
      list.push(array[i].item)
    }
  else if (i == array.length - 1){
    list.push('and ' + array[i].item)
  }
}

return list.join(' ')
}
console.log(groceries([{item: 'Lettuce'}, {item: 'Onions'}, {item: 'Tomatoes'}]))

My result: Lettuce, Onions and Tomatoes
Codecademy response: Tested groceries([{item: 'Lettuce'}, {item: 'Onions'}, {item: 'Tomatoes'}]) and it did not return 'Lettuce, Onions and Tomatoes' .

All help appreciated