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 trialChris Drummond
1,469 PointsThis version of the check_speed only prints "speed OK" if the speed is exactly 55 miles per hour. It would be better to
This version of the check_speed only prints "speed OK" if the speed is exactly 55 miles per hour. It would be better to allow a range of speeds. Update check_speed with this logic:
If we pass a speed of less than 45, check_speed should print "too slow". If we pass a speed of 45 to 60, check_speed should print "speed OK". If we pass a speed of greater than 60, check_speed should print "too fast".
Here is the code I have tried but I'm missing something. Any help is appreciated.
def check_speed(speed) if speed < 45 puts "too slow" elsif speed >= 45 && <= 60 puts "speed OK" else speed > 60 puts "too fast" end end
def check_speed(speed)
if speed < 45
puts "too slow"
elsif speed >= 45 || >= 60
puts "speed ok"
else speed > 60
puts "too fast"
end
end
speed(53)
1 Answer
KRIS NIKOLAISEN
54,972 PointsYou can try it in a workspace and errors will be presented that should walk you through it. Mainly this line:
elsif speed >= 45 || >= 60
You'll want to check speed <= 60
Also the function is check_speed() so this line won't work
speed(53)
Chris Drummond
1,469 PointsChris Drummond
1,469 PointsHi Kris...I posted the wrong code. I meant to post this below:
def check_speed(speed) if speed < 45 puts "too slow" elsif speed >= 45 && <= 60 puts "speed ok" else speed > 60 puts "too fast" end end