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 Making Decisions in Your Code with Conditional Statements Conditional Statements and Operators Review

lion comes before zebra

How does ('lion' > 'zebra') true when "l" comes before "z?" Shouldn't it be true/

3 Answers

Hi Alana!

( 'lion' > 'zebra' )

evaluates to false.

Quiz Question 4 of 7
Is the following condition true or false?

( 'lion' > 'zebra' )
 Well done! When comparing strings, the first letter of the first string is compared to the first letter of the second string.  
True. Since 'l' comes before 'z' in the alphabet, 'lion' is greater than 'zebra.'

B   <--- I picked this answer and it passed
False. Since 'l' comes before 'z' in the alphabet, 'lion' is not greater than 'zebra.'

I hope that helps.

Stay safe and happy coding!

yes, that is what I am asking why is it false when "l" comes before"z." It should be true

Hi Alena!

In the computer world (and other places, too), 'z' is considered a higher character than 'a' (or 'l').

In a database, if you sorted a table of animals by the animal name in ascending (low to high/default) order, it will sort it from a-z.

If you sort in descending (high to low) order, it would sort z-a.

You can test it this way:

var animals = ["zebra", "aardvark", "lion"];
animals.sort(); // default sort is ascending (from low to high)

It should print out "Array(3)", which if you expand it, will give you:

0: "aardvark"
1: "lion"
2: "zebra"
length: 3

aardvark being the lowest value and zebra being the highest

I hope that helps.

Stay safe and happy coding!

Hi Peter,

I want to thank you for your help with the "if" "else" comparison. I had no idea to copy and past in the challege, but I did and it worked. Thanks again ... I'm so thankful.