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 Control Structures Else challenge

Chris Brennan
PLUS
Chris Brennan
Courses Plus Student 551 Points

Set a variable called "too_fast" equal to "true" if the car_speed is faster than the speed_limit and "false" if the car_

It's telling me to put down true for car_speed is greater than speed_limit which it is not because (car_speed = 55 and speed_limit = 60) so I put down false. I put down true for the else statement because yes the speed_limit is greater than the car_speed. I'm confused yet the code I have down is right.

Plz explain why the true and false contradicts the expressions?

ruby.rb
car_speed = 55
speed_limit = 60

# Write your code here

if
  car_speed > speed_limit
  too_fast = true
else
  car_speed < speed_limit
  too_fast = false 
end

6 Answers

I just realized what you where asking so i deleted my answer from before but:

car_speed = represents how fast the car is going
speed_limit = represents the speed limit

too_fast (over the speed_limit) = true
too_fast (under the speed limit) = false

There isn't anything wrong with how the question is structured. If you're going over the speed limit then you're driving too fast.

no prob

Jeremi Watabiki
Jeremi Watabiki
4,833 Points
car_speed = 55
speed_limit = 60

if car_speed > speed_limit
  too_fast = true
else
  too_fast = false
end

Sorry, I know this is really old, but I didn't see a clear answer in the above responses. I just did this exercise and my above code worked fine.

Your answer is correct but he wasn't asking for an answer to the question. His concern was the logic of the question.

Chris Brennan
PLUS
Chris Brennan
Courses Plus Student 551 Points

It doesn't seem to matter elsif or else(tried both and it takes the code above as correct) Why do the conditions contradicts it's true and false?

Chris Brennan
PLUS
Chris Brennan
Courses Plus Student 551 Points

to me the correct answer should be:

if car_speed > speed_limit too_fast = false elsif car_speed < speed_limit too_fast = true end

not(the answer treehouse accepts)

if car_speed > speed_limit too_fast = true elsif car_speed < speed_limit too_fast = false end

Here is the simply answer needed. All that is being asked in this question is for you to set the too_fast variable only so below the whole code

car_speed = 65 speed_limit = 60 too_fast = car_speed > speed_limit

car_speed = 65 speed_limit = 60 too_fast = true

if car_speed > speed_limit too_fast = true end