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 Logical Operators The And (&&) Operator

John Park
John Park
5,323 Points

I can't figure out the answer to this problem despite my efforts. The larger issues is: Why can't I get immediate help?

I shouldn't have to submit a question and sit around waiting for a response. There should be an answer to every challenge that can be accessed if one is unable to figure out the answer and learn from the code.

ruby.rb
def check_speed(car_speed)
  # write your code here
  if (car_speed >= 40) && (car_speed <= 50)
    check_speed == "safe"
end

3 Answers

Hi John.

def check_speed(car_speed)
  # write your code here
  if (car_speed >= 40 && car_speed <= 50)
    return "safe"
  end
end

You have to write an if statement in one piece. If you compare to to values they both have to be between the "( )".

And the challenge says you have to "return" a string "safe". If you write:

check_speed == "safe" //this will set the value string "safe" to check_speed but you can only work with this value in this function (because of the variable scope) but if you return it you can use it in the rest of your code

Happy Coding!!!

John Park
John Park
5,323 Points

Thank you, Nejc.

Seth Kroger
Seth Kroger
56,413 Points

There are 2 issues with your code:

  1. You didn't put "end" after the if statement which is a syntax error.
  2. "==" means "is it equal to?" which will give true or false, not "safe". You just need to use "safe" in an implicit or explicit return
  3. (Your parentheses are redundant.)
def check_speed(car_speed)
  # write your code here
  if car_speed >= 40 && car_speed <= 50
    "safe"
  end
end
John Park
John Park
5,323 Points

Got it. Thanks, Seth.

Taylor Boudreau
Taylor Boudreau
7,285 Points

Hey John! As an answer to your question - "There should be an answer to every challenge that can be accessed if one is unable to figure out the answer and learn from the code."

I don't work for Treehouse, but have found the fact that they don't have this available, hugely helpful. This forces you to figure out the issue on your own, or if necessary, ask for a little help from the community who have generally proven to be extremely helpful and responsive.

I've often found the answer to my questions/troubles was in the previous lesson, so often going back and rewatching the lesson, and checking the teachers notes may help you find answers to your questions without having to wait for a response. It's all part of learning to read, write, and understand code, so try to embrace it!

John Park
John Park
5,323 Points

Taylor, you're right about the community being extremely helpful, but I still believe that having access to help instantly would be very helpful. Having the option to either peek at hints or to hack away until I figure it out both have benefits.

Still, Treehouse is THE best resource for learning this stuff I've come across and I love it.

Well if you ask me -> it's the best way to figure things for yourself.

If you are stuck you could take a look at the videos again or refer to the documentation of the programming language.

It's nice to get past a problem quickly, but the hard way makes you remember more specific detail about the problem and it will be easier to refer back when a similar problem arises.

This way you are more prone to details by coding and you can find solution to a problem faster because you know what to look for.

Happy Coding!!!