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

Rick Buffington
Rick Buffington
8,146 Points

Negation operator incorrect?

Not sure what I am missing here...the negation operator is used and I have tested this on my own. Any thoughts?

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

Jason Anders
MOD
Jason Anders
Treehouse Moderator 145,860 Points

Hey Rick,

Your code is correct, but you seemed to have switched the true/false return values. The challenge wants you to use the negation to reverse the logic, which you did, but then you switched the values, and now it returns what it originally did.

When you use the ! symbol, the condition now asks if something is "Not". So, originally, if the car_speed was greater than, it would return true. With the negation, if the car_speed was greater than, it will return false. Make sense? (It's kind of like making it "opposite day")

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

Keep Coding! :dizzy:

Rick Buffington
Rick Buffington
8,146 Points

Oooooh I get it. It was seriously only caring about me switching the operator. Not whether or not the logic was correct. Thank you for the response!