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 trialjulianacrispo
4,105 Points"Set a variable called "too_fast" equal to "true" if the car_speed is faster than the speed_limit." Why is answer wrong?
My answer was: if car_speed > speed_limit too_fast = "true" end
10 Answers
Ricardo Hill-Henry
38,442 PointsUse the boolean value true, not a string value "true".
Carl Sergile
16,570 Points car_speed = 55speed_limit = 60
if car_speed > speed_limit
too_fast = true
else
too_fast = false
end
THIS IS IT.
Roscoe Coney
13,124 Pointstype the following:
too_fast = true
missfit
18,561 PointsHey I came across this post and none of the answers above worked for me, however the code I typed in below finally worked. Hope that helps someone.
car_speed = 55 speed_limit = 60 too_fast = car_speed > speed_limit
if too_fast puts "true" else puts "false" end
missfit
18,561 PointsHey I came across this post and none of the answers above worked for me, however the code I typed in below finally worked. Hope that helps someone.
car_speed = 55 speed_limit = 60 too_fast = car_speed > speed_limit
if too_fast puts "true" else puts "false" end
missfit
18,561 PointsHey I came across this post and none of the answers above worked for me, however the code I typed in below finally worked. Hope that helps someone.
car_speed = 55 speed_limit = 60 too_fast = car_speed > speed_limit
if too_fast puts "true" else puts "false" end
ellie adam
26,377 Pointsthis works
too_fast = true
Maciej Czuchnowski
36,441 PointsThe section is called "control structures", so you were supposed to use an if
statement to get that result, assuming that the variable values may be different in the future, n which case your code would fail the expectation.
Jeremy Kerrigan
12,002 PointsThis is the answer and I believe it is the structure they want.
car_speed = 65 speed_limit = 60 too_fast = true //Set a variable called "too_fast" equal to "true"
if car_speed > speed_limit //if the car_speed is faster than the speed_limit. puts too_fast end
Nasser Sanou
6,895 PointsThis works as well!
car_speed = 55 speed_limit = 60
if car_speed > speed_limit too_fast = true else car_speed < speed_limit too_fast = false end
Ben Holland
Courses Plus Student 4,062 Pointsif car_speed > speed_limit
too_fast = true
end
That is the answer.
Maciej Czuchnowski
36,441 PointsMaciej Czuchnowski
36,441 PointsAnd make sure these are 3 separate lines, it won't work as one line.
Aurelien Schlumberger
6,127 PointsAurelien Schlumberger
6,127 Points@Maciej Czuchnowski, not that your answer is wrong, but actually you could do it in one line in Ruby and is still good design. ```ruby : too_fast = true if car_speed > speed_limit
Maciej Czuchnowski
36,441 PointsMaciej Czuchnowski
36,441 PointsI know, I was referring to the code that Juliana showed, with
end
at the end :)