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 Booleans Ruby Booleans Negation

Anuj Nagpal
PLUS
Anuj Nagpal
Courses Plus Student 3,748 Points

Using the negation operator, reverse the logic in the boolean statement.

Bummer! The going_too_fast method did not return the correct value.

def going_too_fast?(car_speed, speed_limit) if !(car_speed > speed_limit) return false else return true end end

car_speed.rb
def going_too_fast?(car_speed, speed_limit)
  if !(car_speed > speed_limit)
    return false
  else
    return true
  end
end

2 Answers

Hi Anuj,

You already add negation operation ( ! ) there as far I can see, that's good but your return method are switching from false to true in third and fifth lines. That's why you get errors messages which requires you not to change anything in boolean values except only negation operation.

def going_too_fast?(car_speed, speed_limit)
  if !(car_speed > speed_limit)
    return true
  else
    return false
  end
end
Mateo Sossah
Mateo Sossah
6,598 Points

If car_speed is NOT greater than speed_limit, going_too_fast? should answer FALSE. Isn't there an error in the compiler on this one?

def going_too_fast?(car_speed, speed_limit)
  if (!(car_speed > speed_limit))
    return true
  else
    return false
  end
end