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

tamirg
tamirg
6,201 Points

I've tried several times, went back to video and researched on forum. I can't get the variable to work.

"Set a variable called "too_fast" equal to "true" if the car_speed is > than the speed_limit." Why is answer wrong? I've tried it several ways.

print "too_fast: " name = gets.chomp

if car_speed > "speed_limit" puts "false" if car_speed < "speed_limit" puts "true" end

or

too_fast = "true"

if car_speed > "speed_limit" puts "false" if car_speed < "speed_limit" puts "true" end

ruby.rb
car_speed = 55
speed_limit = 60

# Write your code here

too_fast = "true"

if car_speed > "speed_limit"
  puts "false"
else car_speed < "speed_limit"
    puts "true"
  end

3 Answers

Hi Tami,

Let's think clearly in order way, if the car speed is faster than limit then put true in too_fast variable.

Else if car speed is less than limit then puts false

car_speed = 55
speed_limit = 60

# Write your code here

if car_speed > speed_limit
  too_fast = true

else
  too_fast = false

end

You don't need to put double quotes on variables names (i.e: car_speed, speed_limit, and too_fast) and boolean value should be either true or false without double quotes as well. :)

Hope that helps.

Hi Salman,

The else shouldn't have a condition with it.

Just make it easier to read, thanks Jason

tamirg
tamirg
6,201 Points

Hi Salman and Jason,

I appreciate both of your input. I went back to the code challenge and followed your instruction above and it worked. I do believe I did try to "else" statement when I was working through this challenge but maybe I was missing something. I made sure I broke it down so the rule is immersed into my train of thought.

Thank you, Tami

Derrek Hennessy
Derrek Hennessy
4,483 Points

The best part about the ones that drive you crazy is after you figure it out you will never forget!