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

Ruby Ruby Operators and Control Structures Ruby Operators Greater Than

sergio verdeza
PLUS
sergio verdeza
Courses Plus Student 10,765 Points

Write the Ruby code to check if the variable "a" is greater than the variable "b".

Ruby Operators using the greater than sign

This is the answer I'm writing on the code but is not correct even though I'm checking the correct answer the treehouse workspace?

"a" > "b"

The answer is false but I'm not sure what is not accepting my code?

Any help will be greatly appreciated, thank you.

10 Answers

J Scott Erickson
J Scott Erickson
11,883 Points

You don't need the quotes. This makes the comparison happen on the string literals "a" and "b"

a > b

I got confused here as well!

Cara Hill
Cara Hill
2,859 Points

I was confused as well - we used the quotes in the example in the video!

Mary Dickson
Mary Dickson
7,293 Points

It's so frustrating to not have a hint here... I got confused with this as well. Would be nice to have a "reveal answer" option to move forward.

Hunter Rancourt
Hunter Rancourt
3,485 Points

Just curious, in a real code situation wouldn't we need the quotes because we did not define what variables a and b are equal to?

J Scott Erickson
J Scott Erickson
11,883 Points

Well, operation under the assumption that variables a and b exist wrapping them in quotes would never actually compare the values in the variables.

And comparing "a" > "b" is akin to writing the bool false. So I can't think off the top of my head where that would necessarily be useful.

William Lynch
William Lynch
5,636 Points

ok, I figured it out. It was worth pursuing. You have to have a space before and after the operator.

I tried these on the challenge and got:

a>b fails a > b works.

Bill

There's no reason for the quotes in the question. It should read: "Write the Ruby code to check if the variable a is greater than the variable b." "a" implies that it's a string.

I also go confused....even rewatched the examples over and over again...the answer needs to be fixed to match the video.