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 trialpgmd
6,897 PointsCode question
function compare(a,b) { console.log(a+"<"+b, a<b); }
not sure what this does!
4 Answers
Tristan Gaebler
6,204 PointsIt takes two arguments (a and b), and compares them. When you call the function you input 2 numbers ( a and b), then the body of the function compares them. It logs to the console a then the character "<" then b. Then compares and b to see if it is true.
pgmd
6,897 PointsIn full example: function compare(j,c) { console.log(j+"<"+c, j<c); }
compare('a','b'); compare('a','A');
It seems that console should be outside of the curly braces. I know that compare('a','b'); compares the two arguments but....I think that I am lost in the order of processing.......
Tristan Gaebler
6,204 Pointsconsole.log should be inside the braces. Once the function receives input it heads to the body, which will compare a and b.
Daniel Stepanenko
2,376 PointsI won't quite understand why the ,a<b) portion does a comparison.
Is there something implicate in this syntax?
pgmd
6,897 Pointspgmd
6,897 PointsIn full example: function compare(j,c) { console.log(j+"<"+c, j<c); }
compare('a','b'); compare('a','A');
It seems that console should be outside of the curly braces. I know that compare('a','b'); compares the two arguments but....I think that I am lost in the order of processing.......