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 trialPaulo Moreira
2,963 PointsPlease, what am I doing wrong?
What's wrong with the code I wrote? It just presents my ELSE messages, never the IF.
print "What days do you have swimming classes? "
swim = gets.chomp.capitalize
if (swim == "Mondays") && (swim == "Wednesdays")
puts "Great! We can meet there."
else
puts "Ok then! I thought we had classes on the same days."
end
print "And when do you go to the gym? "
gym = gets.chomp.capitalize
if (gym == "Tuesdays and Thursdays") || (gym == "Tuesdays and Fridays")
puts "Awesome! I'll be there and we can train together."
else
puts "That's fine! If you decide to come on Mondays and Wednesdays as well, just look me up. I'm here every day from Monday to Friday."
end
Thank you in advance and sorry if I misspelled any word, I'm brazilian.
PS. the real code is all indented.
1 Answer
Beatrice Nilsson
6,234 PointsYour code prints the else options because your ifs are never true.
For the first one you only allow one input but require the swim variable to be both Mondays and Wednesdays.
On the second if statement you're only capitalizing the first letter of the string with the capitalize method. So, for this to work you either have to type the second day with a capital letter to the input, or you need to change your if statement.
Paulo Moreira
2,963 PointsPaulo Moreira
2,963 PointsYou're totally right :) thank youuuuu
Paulo Moreira
2,963 PointsPaulo Moreira
2,963 PointsAny hint on how to allow more than one input, Beatrice?