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 JavaScript Basics (Retired) Making Decisions with Conditional Statements Review Conditional Statements and Comparison Operators

I chose true for this question, because 'l' comes before 'z'. Could I get an explanation as to why that answer is wrong?

I got this message " Bummer! When comparing strings, the first letter of the first string is compared to the first letter of the second string. Since 'l' comes before 'z' in the alphabet, 'lion' is not greater than 'zebra.'"

Which doesn't agree with me in practice, but agrees with me in theory. I'm pretty confused, can anyone tell me what I'm missing here?

2 Answers

18,785 Points

This isn't exactly what's happening, but maybe you could think of it in terms of "numeric" values for numbers?

// (12 > 26) (l > z) = False
( 'lion' > 'zebra' )
Emmanuel C
Emmanuel C
10,635 Points

If you were to number the alphabet, where a = 1 , b=2, c=3.... z = 26.

The letter "l" would be 12 and z is 26. 12 is < 26. Thats why lion would be less than zebra. It takes the first letter of each string and compares them like that.

Thank you, I understand what I was missing, now!