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

I'm a bit confused about what this challenge is asking me to do. I'm not sure how to advance, as my code is wrong

I'm specifically confused about the 'set the return value' of the method to true portion.

ruby.rb
def check_speed(car_speed)
  # write your code here
  if (car_speed >= 40) && (car_speed <= 50)
    check_speed = "safe"

end

3 Answers

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

You got the logic of the code right, but here're couple of issues

  • missed the end for if condition
  • no return value. By default, in Ruby the last statement in method definition is the return value, but check_speed = "safe" is just a value assignment.

Set the return value of the "check_speed" method to the string "safe"

def check_speed(car_speed)
  # write your code here
  if (car_speed >= 40) && (car_speed <= 50)
    "safe"
  end
end
Konrad Pilch
Konrad Pilch
2,435 Points

HI, i dont know but, you can press a big arrow to go to next exercise or if this is the last one, click on the course and just look on sections and you can enter any video you like.

Jesus Mendoza
Jesus Mendoza
23,289 Points

Hello, you have to return a value using the return statement

def check_speed(car_speed)
  # write your code here
  if (car_speed >= 40) && (car_speed <= 50)
    check_speed = "safe"
    return check_speed
  end
end