Welcome to the Treehouse Community

The Treehouse Community is a meeting place for developers, designers, and programmers of all backgrounds and skill levels to get support. Collaborate here on code errors or bugs that you need feedback on, or asking for an extra set of eyes on your latest project. Join thousands of Treehouse students and alumni in the community today. (Note: Only Treehouse students can comment or ask questions, but non-students are welcome to browse our conversations.)

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and a supportive community. Start your free trial today.

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.