Not sure what it wants me to do on 7/9 Instruction 3

3.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.

Use .slice() to provide him 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.

Not really sure what It wanted me to do here. How doesnt the slice syntax operate? How am I supposed to do that all in one line?

let groceryList = ['orange juice', 'bananas', 'coffee beans', 'brown rice', 'pasta', 'coconut oil', 'plantains'];

groceryList.shift(); // Q1

groceryList.unshift('popcorn'); //Q2

// not sure what it wants me to do here

Its probably simpler than I’m imagining but I took a look at the hint and it raised more questions for me than it answered:

console.log(array.method(first, last+1));

Not sure what the arguments in the brackets are getting at. ‘first’ and ‘last+1’ doesn’t make much sense to me. Can someone enlighten me to what I’m missing here?

you can always check external documentation if you are struggling with syntax:

we want our friend to get: ['bananas', 'coffee beans', 'brown rice'], so only part of the grocerylist, which is why we use slice. If we then look at the documentation, we see that slice has a begin and end parameter, maybe we can use this to our advantage so we get an array with the 3 items our friend should buy for us?

the whole hint is general syntax. its just showing you that slice (which can extract part of an array) can have a first and last value, this values are used to extract that specific piece of the array you want to have

1 Like

Thankyou for your reply, fortunately I figured it out by using the show code feature that appears when you repeatedly make a mistake. I did look through the documentation but I’ve always found it more difficult to understand than a simple example piece of code and output.

I understand the exercise itself was trying to point me in the direction of finding answers for myself using the documentation, which I can imagine is very useful later on as it teaches independence. I just found the wording of the question a bit misleading. Maybe it was just me lol.

Thanks anyway, its nice to know theres a helpful community out there that can give me support whenever I need it! Really enjoying using this site so far.

but that is the problem, a programmers job involves surprising little time writing code. Huh, wait what? Yes, huge part of programming is translating the clients wish into a good concept, workout the concept, look for the function and libraries you need, design the program, then write the code

Same here, its far more important to spend time delving into this function (slice), tearing the documentation apart and play with the examples, and then when you understand, implement the solution.

I am personally against the get code button, i much rather have that people come to the forum, explain there problem, and together work towards a solution in which you do the work, and i just push you in the right direction

that you came back here and said: I attempted x, this is what i expected, this is what happened instead, and can correct you where you go wrong, so you can improve upon :slight_smile:


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