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 trialRachel Heneault
12,401 PointsDifferent way of doing things
I always end up with different code than the instructor. This time I used toLocalString to convert the currency, It was great seeing how much easier it was when he just add the dollar sign an it converted it to money.
const price = prices.map(item => item.toLocaleString('en-US',{style:'currency',currency:'USD'})); console.log(price);
2 Answers
Joel Kraft
Treehouse Guest TeacherAwesome solution! Actually, while the solution shown in the video was a little quicker to type, your solution is much more robust, and better for production code. Relying on toLocaleString
rather than writing your own currency converting logic actually saves time and is less brittle in the long run. If you ever wanted to change the currency to euro, for example, you can just alter the currency parameter. Better yet, you could let your website user alter the currency by connecting that property to a form select element, for example.
Anyway, having a different way of doing things is great. Solving problems takes creative thought, which is what people mean when they talk about "thinking outside the box". In this case, it actually meant you wound up with better code! :)
Rachel Heneault
12,401 PointsThanks Joel! You guys are great and I appreciate all that you do! :)
Ian Ostrom
Full Stack JavaScript Techdegree Student 10,331 PointsIan Ostrom
Full Stack JavaScript Techdegree Student 10,331 PointsThanks for sharing Rachel!