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

I dont understand the question what i need to do with it

Set the return value of the "check_speed" method to the string "safe" depending on the following condition: The speed passed in as an argument is at least 40. The speed passed in as an argument is less than or equal to 50. You should use the "&&" logical operator to accomplish this task.

def check_speed(car_speed)

end

Can you link to the Challenge so we can help you better?

http://teamtreehouse.com/library/ruby-operators-and-control-structures/logical-operators/the-and-operator

and its also the next challenge. I just wrote return true but thats nt enought im pretty sure. It passed but i dont think its right.

For the challenge after that, you need to check if command == 'y' and all the other ones there. If it's equal to 'y' or 'yes' or 'Y' or 'YES', return "true".

5 Answers

Alright, so the challenge asks you to make the function "check_speed" return the string "safe" if:

  • car_speed is at least equal to 40. So it needs to be more than or equal to 40.

  • and

  • car_speed is less than or equal to 50.

Here's the code you'll need, minus the operators:

def check_speed(car_speed)
    if car_speed [operator] 40 [operator] car_speed [operator] 50
        return "safe"
    end
end

Does that help you?

aa okay , i do understand it now , i get a bit confusing with english ;/ and i get now the challenge , i need to pause now and practice it all. Thank you

No problem, Aurelian :)

Good luck with the rest of the course!

Thank you :) Ijust finished Basics and this one course and now im doing codeacademy for a better understanding :) Hope you engioj treehouse :D its awesome :D no need for college :D i mean here is everyhing a boy needs :D well .. till one point xd

Hey Bryan, that was very helpful, thank you. If you don't mind imparting just a bit more wisdom...why do we need two 'end's? Am I right in thinking it's one end for the 'if' statement and another for the 'def'?

the def needs an end and also the "if" needs an end. you created an "if" under the whole section of "def". need to end them both respectively.

I was stuck too I didn't know you can put conditionals inside of a method. Thanks Brian!

I used this and it passed on the quiz, but it returns nothing on workspaces:

def check_speed(car_speed)
  if (car_speed > 39) && (car_speed <= 50)
    return "safe"
 end
end

Im not sure why it accepts 39 but not 40.

it does accept 40. Just remember to use >=