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 Ruby Control Structures If challenge!

"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

Use the boolean value true, not a string value "true".

And make sure these are 3 separate lines, it won't work as one line.

@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

I know, I was referring to the code that Juliana showed, with end at the end :)

 car_speed = 55speed_limit = 60

if car_speed > speed_limit
  too_fast = true 
else
  too_fast = false
end

THIS IS IT.

type the following:

too_fast = true

Hey 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

Hey 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

Hey 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

this works

too_fast = true

The 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.

This 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
Nasser Sanou
6,896 Points

This 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

if car_speed > speed_limit

too_fast = true

end

That is the answer.