If you’re working on the Shopping List Challenge and feeling a bit stuck, here are some hints to get you coding.
The Fish and Lemon Loops
The first loop we need to make is a for loop to add the fish to the shopping basket.
Let’s start by copying in the for loop reference from our review:
Now we have two questions:
- How many times should we loop?
- What should happen each time we loop?
Try to answer these questions yourself, then check your answer:
Now trying filling in the reference for loop using the answers to those questions!
Check your answer:
Now test it out! Try clicking on the Get New Shopping List button and then the Fill Basket button. Did you get the right number of fish icons in your basket?
Using the fish loop as a reference, can you write the lemon loop?
The Other Items Loop
Now we need a for-of loop to add the other items to our shopping basket. We’ll add one of each item in the otherItems array.
Let’s start by copying the reference for-of loop to our fillBasket() function
Now we have two questions:
- What array do we want to loop over?
- What should happen each time we loop?
Try to answer these questions yourself, then check your answer:
Let’s fill in the reference for-of loop!
Check Your Answer:
Test it out! Try clicking on the Get New Shopping List button and then the Fill Basket button. Are you getting all the correct items in your basket?