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 Logical Operators The And (&&) Operator

Alejandro Loja
Alejandro Loja
6,541 Points

def check_speed(car_speed) if (car_speed>=40) && (car_speed<=50) puts check_speed="safe" end whats wrong??

help

ruby.rb
def check_speed(car_speed)

if (car_speed>=40) && (car_speed<=50)
  puts check_speed="safe"
end

2 Answers

The question asked that the speed is at 40 so your condition should check if something was greater than 39 which would 40. You currently have greater than or equal to 40. You also forgot to close your if statement block and you're suppose to return the value as "safe"...you're currently assigning the string "safe" to the function name.

def check_speed(car_speed)
  if (car_speed > 39) && (car_speed <= 50)
    return "safe"
  end
end
Tal Kovach
Tal Kovach
2,174 Points

Here is the correct code:

def check_speed(car_speed)
  if (car_speed >= 40) && (car_speed <= 50)
    return "safe"
  else
    return "unsafe"
  end
end