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![](https://ecs-static.teamtreehouse.com/assets/views/marketing/shared/community-banner-white-47072046c51352fe6a69f5e691ff5700b28bb11d45197d7bdf066d9ea3f72d0c.webp)
![Aurelian Spodarec](https://uploads.teamtreehouse.com/production/profile-photos/1177692/micro_10471458_10202778181965421_3972579228476600668_n.jpg)
Aurelian Spodarec
7,369 PointsIf , else , when, case etc..
Hello,
When i get throw half the code , it breaks im not sure whats the right think to do .
puts "What is your name ?"
name = gets.chomp
name.capitalize!
puts "Hello #{name}!"
print " Are you male or female?"
gender = gets.chomp
case gender
when "male"
puts " I have a car for you"
when " female"
puts " i have clothes for you "
else
puts " Woops, we don't have anything for #{gender}"
end
case male
when gender = male
puts "How old are you?"
age = gets.to_i
if age >= 18
puts " You are allowed to vote"
end
case female
when gender = female
puts " Whats your date of birth?"
femaleAge = gets.to_i
if femaleAge >= 1996
puts " You are allowed to enter"
end
end
2 Answers
![Maciej Czuchnowski](https://uploads.teamtreehouse.com/production/profile-photos/103489/micro_IMG_3403.jpg)
Maciej Czuchnowski
36,441 PointsWhat David said, plus, some of your male
and female
are strings (in double quotes) and some are just variables (no double quotes). Like here:
when gender = male
I think you meant:
when "male"
![David Tonge](https://uploads.teamtreehouse.com/production/profile-photos/447992/micro_profile_web.jpg)
David Tonge
Courses Plus Student 45,640 PointsHi, I noticed that you're no longer comparing cases but assigning them at he bottom of your program.
when gender = male
when gender = female
// I'm guessing should be
when gender == male
when gender == female
![Aurelian Spodarec](https://uploads.teamtreehouse.com/production/profile-photos/1177692/micro_10471458_10202778181965421_3972579228476600668_n.jpg)
Aurelian Spodarec
7,369 PointsI changed it but i still get an error .
But thank you i did mess up a bit : p
Maciej Czuchnowski
36,441 PointsMaciej Czuchnowski
36,441 PointsAlso, the whole second case seems a bit off.
case male
suggests that you have a variable namedmale
, but you don't, so it can't really work. Please read more on CASE in Ruby to understand it more thoroughly, you can start here:http://www.skorks.com/2009/08/how-a-ruby-case-statement-works-and-what-you-can-do-with-it/
Aurelian Spodarec
7,369 PointsAurelian Spodarec
7,369 PointsI changed it a bit but i have some error about male
Aurelian Spodarec
7,369 PointsAurelian Spodarec
7,369 Pointsokay i check it now
J Scott Erickson
11,883 PointsJ Scott Erickson
11,883 Pointsyour case statements are using unassigned variables male and female.
I think what you actually want is this:
Aurelian Spodarec
7,369 PointsAurelian Spodarec
7,369 Pointsthank you :) i see what wrong i did but i was close![:smiley: :smiley:](https://image-proxy-cdn.teamtreehouse.com/f266e5f075421fb8b3a44f1b8d72534e51ae5854/68747470733a2f2f7374617469632e7465616d74726565686f7573652e636f6d2f696d616765732f656d6f6a692f756e69636f64652f31663630332e706e67)
bdw i know not to ask a lady about her age but i though you can ask what year was she born in xd