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 Modify Object Properties

Dimitris Karatsoulas
Dimitris Karatsoulas
5,788 Points

How and why is the log of the processSale function shown in that way?

In Challenge 2 at the end of the challenge function processSale () is run by referring it in the console.log()
"console.log("Total sale: $" + processSale(product, 3));" even though in the code the function is referred after the "Total sale..." part we can see in the console that the log "3 chairs were sold" is print before the "Total sale..." part. Can anyone please explain that behavior?

1 Answer

seth aruby
seth aruby
9,354 Points

Dimitris, since the processSale function first logs the quantity sold to the console (ie, prior to returning the total sale), then the quantity sold is displayed prior to the total sale. Hope this helps.