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 trialtamirg
6,201 PointsI've tried several times, went back to video and researched on forum. I can't get the variable to work.
"Set a variable called "too_fast" equal to "true" if the car_speed is > than the speed_limit." Why is answer wrong? I've tried it several ways.
print "too_fast: " name = gets.chomp
if car_speed > "speed_limit" puts "false" if car_speed < "speed_limit" puts "true" end
or
too_fast = "true"
if car_speed > "speed_limit" puts "false" if car_speed < "speed_limit" puts "true" end
car_speed = 55
speed_limit = 60
# Write your code here
too_fast = "true"
if car_speed > "speed_limit"
puts "false"
else car_speed < "speed_limit"
puts "true"
end
3 Answers
Salman Akram
Courses Plus Student 40,065 PointsHi Tami,
Let's think clearly in order way, if the car speed is faster than limit then put true in too_fast variable.
Else if car speed is less than limit then puts false
car_speed = 55
speed_limit = 60
# Write your code here
if car_speed > speed_limit
too_fast = true
else
too_fast = false
end
You don't need to put double quotes on variables names (i.e: car_speed, speed_limit, and too_fast) and boolean value should be either true or false without double quotes as well. :)
Hope that helps.
tamirg
6,201 PointsHi Salman and Jason,
I appreciate both of your input. I went back to the code challenge and followed your instruction above and it worked. I do believe I did try to "else" statement when I was working through this challenge but maybe I was missing something. I made sure I broke it down so the rule is immersed into my train of thought.
Thank you, Tami
Derrek Hennessy
4,483 PointsThe best part about the ones that drive you crazy is after you figure it out you will never forget!
Jason Anello
Courses Plus Student 94,610 PointsJason Anello
Courses Plus Student 94,610 PointsHi Salman,
The
else
shouldn't have a condition with it.Salman Akram
Courses Plus Student 40,065 PointsSalman Akram
Courses Plus Student 40,065 PointsJust make it easier to read, thanks Jason