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 trialRebecca Palumbo
5,506 Points2 questions about functions
Does one need to declare the parameter in a function? In my function, I wasn't sure if it's proper to declare i or not and where to declare it. I imagine in the function if so.
I could have put the code that's in the function in the for loop instead, but I think I heard that it's better to make a function separate. Any input on that?
Snapshot: https://w.trhou.se/4rjk1j55wv
Jason Dirnbauer
18,815 PointsJason Dirnbauer
18,815 PointsI believe it's always better to wrap logic in functions. You can always put looping logic in the function. This leads to reusability down the road. In looking at your code you have the function structure properly setup. You would then call your function by using compare(valueForI).You pass arguments from the function call which become parameters in the function declaration itself. More info can be found at the below two links.
https://www.w3schools.com/js/js_function_parameters.asp https://developer.mozilla.org/en-US/docs/Web/JavaScript/Guide/Functions