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 trial

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,547 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.