Welcome to the Treehouse Community

Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.

Start your free trial

JavaScript JavaScript Loops, Arrays and Objects Tracking Multiple Items with Arrays Useful Array Methods

My take of the shopping list :}

Thomas McAdoo
Thomas McAdoo
4,141 Points

The alert for showing that shows you have nothing in the mini-bar acts funny and throws the loop off. If you type anything in the prompt before the alert it will automatically add it to the variable. For example:

Prompt pops up I enter: add alert pops up "You have 0 items in the list, PRESS ADD to add items :}" Prompt pops up after hitting ok "Search for a product in my mini-bar. Type `list' to show the current inventory, Type 'add' to add new items, Type 'remove' to remove items" At this point the app runs as intended however when I enter "list" into the prompt it gives me: This is the current inventory: >> add, carrots, lettuce, pizza, beer, and etc.

Every time it will add the first prompt to the var and the alert will pop up and then continue the app as intended. This is due to the order of which the loop runs as well as the oddly placed push method.

I suggest removing the push method and placing the alert after the add condition but before the remove condition to make it more fluid.

Hope this helps!

1 Answer

Eduardo Vargas
Eduardo Vargas
5,871 Points

Interesting take on the exercise. I see there are a few things here students (including myself) haven't learned yet. Well done tho.