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

Daniel Hildreth
Daniel Hildreth
16,170 Points

How does the > symbol work with alphabetical strings in JavaScript Basics Track Comparison Operators Course?

Like my title says, how does the > and < signs work with alphabetical strings? Is it counting Z the biggest and A the smallest? I posted one of the quiz questions below, and need help explaining why it is wrong.

Quiz Question 6 of 7

Is the following condition true or false?

( 'lion' > 'zebra' )

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.'

4 Answers

Alex Heil
Alex Heil
53,534 Points

hey daniel, when dealing with string comparisons the counting starts with a (smallest) up to z (highest). so given your example "lion" > "zebra" you have to ask if "l" is coming before "z" in the alphabet. as that's the case we know that "lion" is smaller than "zebra" so the task is false. hope that helps ;)

This compare letter in UTF order. For example:

'z' > 'Z' === true 'A' > 'z' === false

You can check an UTF table here: http://www.utf8-chartable.de/

No. From 0-9A-Za-z. That is why 'A' < 'a' and 'A' < 'z'. You should check UTF table to see an order.

Daniel Hildreth
Daniel Hildreth
16,170 Points

Ok so it is going from z-a (greatest to highest). That is weird and something I got to get used to.