JavaScript JavaScript Basics Making Decisions with Conditional Statements Review Conditional Statements and Comparison Operators

Dextane Rimmer
Dextane Rimmer
1,873 Points

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

rydavim
rydavim
15,321 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
7,306 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.

Dextane Rimmer
Dextane Rimmer
1,873 Points

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