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!
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
Nicholas Wallen12,278 Points
Not sure why the total price isn't calculating...
I have it copied word for work what the instructor had. But mine is calculating some crazy random numbers. Thoughts?
Emmanuel C10,636 Points
Looking through your code, I noticed that the totalValues variable in your totalValue function is initialized to an empty array instead of a 0 like the instructor had it, which was causing all sorts of funkyness. After setting it to 0 the value returned was the same that the instructor had. So that should do it.
This is correct, for those curious the reason that the "funkyness" occurs is that the
+=operator can only be used on
So the variable gets converted from a list to a string once the
+=operator runs the first time, and from there it just has numbers concatenated to it. That's why you end up with such a long number, all of the prices are just glued together in a line instead of actually being added together mathematically.