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 trialPatrick Shushereba
10,911 PointsRuby Operators and Control Structures
I need help figuring out what is wrong with my code:
def check_speed(car_speed)
speed = car_speed.to_i
if (speed > 40) && (speed <= 50)
puts "safe"
end
end
The message that I'm getting is that the check_speed method is not giving the correct output.
2 Answers
Salman Akram
Courses Plus Student 40,065 PointsHi Patrick,
- Need to add equal (=) that would be maximum up to 40. Also other way, you can do this speed > 39 instead 40.
- return value for "safe" string according to the question, puts vs return are not the same thing.
def check_speed(car_speed)
speed = car_speed.to_i
if (speed >= 40) && (speed <= 50)
return "safe"
end
end
Hope that helps. ;)
kabir k
Courses Plus Student 18,036 PointsHi Bogere,
The to_i method is added to convert the car_speed argument from an input string to an actual number.
Hope that helps.
Bogere Sanders
2,195 PointsBogere Sanders
2,195 Pointswhy did you add "speed = car_speed.to_i" ?