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

<noob />
<noob />
16,316 Points

My take of the shopping list :}

Thomas McAdoo
Thomas McAdoo
4,140 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
3,746 Points

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