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 trialJoshgun Huseynov
365 PointsUnexpected return type in Ruby
def check(input)
reversed = input.reverse
puts reversed
reversed == input
end
puts check(gets)
Why this code returns false when I prompt "123321" or "helloolleh"?
1 Answer
Basto Biih
5,334 PointsYou made a 1st mistake on the reverse! method by not putting the [!]. Also drop the (input) and just input your string you want before the reverse! method. This is also shown in the video.
def check
reversed = "helloolleh".reverse!
puts reversed
end
puts check
Joshgun Huseynov
365 PointsThanks for answer
Lukasz Walczak
6,620 PointsLukasz Walczak
6,620 Pointsmethod returns the result of the last statement evaluation in this case it is boolean value, as the last line of code checks for equality between "reversed" and "input" variables