I think the lesson about Arrays is wrong (step 3, task 9 / 12)

Hi there,

I think the arrays exercise / instructions on step 9 of the arrays part of the JS course is wrong.

The task reads as follows:

You’re in a hurry so you decide to ask a friend to help you with your grocery shopping. You want him to pick up the 'bananas' , 'coffee beans' , and 'brown rice' .
Under the code you added for step 2, use .slice() to provide your friend with a list of these three things.
Log this part of the list to the console. Unlike the two previous checkpoints, you should do both of these steps in one line.

The solution (according Codecademy) is this:

console.log(groceryList.slice(1, 4));

But the 3 elements in the list have the index number 1, 2 and 3 hence I think the correct statement would be

console.log(groceryList.slice(1, 2, 3));

Or am I totally wrong?

Hello, and welcome to the forums!

The Codecademy solution is correct.

You’re trying to use the .slice() method as if it’s taking in a list of individual indexes, but that isn’t what it requires. Double check the documentation that task #3 linked: MDN’s slice documentation. Instead of individual indexes, you need to supply a range of indexes.

1 Like

As they say in my country “if you can read, you have an advantage”

Of course you’re perfectly right… (note to myself: read that ■■■■ manual better next time…)

Thank you for pointing me in the right direction.

1 Like