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

How do I format this if/ elsif statement to be correct?

It gives me 2 variables. One for car speed and another for speed limit. the answer is supposed to read true if the car speed is greater than the speed limit but unless I change the car speed... that statement will never read true. I have changed the speeds, order, and I even tried to take not def "too_fast:" I don't know what I'm doing wrong.

ruby.rb
def "too_fast:"

car_speed = 55
speed_limit = 60


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

2 Answers

William Li
PLUS
William Li
Courses Plus Student 26,868 Points

Hi, Aaron, you shouldn't use the puts statement here, instead, you should assign the true/false to the variable too_fast

# Write your code here
  if car_speed > speed_limit
    too_fast = true
  elsif car_speed < speed_limit
    too_fast = false
  end

Also, you have to delete this first line in your code, it serves no purpose and will definitely cause syntax error

def "too_fast:"

Hi Aaron you don't need to use the puts since you are not outputting anything to the console. You simply need to assign the true or false value to the too_fast variable. Also, you don't need the elsif condition because you only have two possible conditions:

  1. You are going over the speed limit
  2. You are not going over the speed limit

Using a if/else statement like this will work just fine.

car_speed = 55
speed_limit = 60

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

Hope this helps!