Setting Up the 'if' Branch, part 1

what is wrong with my code??

print “user_input”
user_input = gets.chomp.downcase!
if user_input.include? “s”
print “OK”
end

It keeps telling me to try again your code doesn’t looks quite right.

Hi,

You need to input something in the console when you are prompted to do so. Also, remove the ! in the second line. It will return nil if your input string is already downcase.

3 Likes

yaaaaaaayyyyy thank you so much!!!

we were told to put the line as user_input = gets.chomp.downcase! to make any S / s they input be converted to a lower case s. Why / when / how are we supposed to determine when we need to remove this? how do we deal with them inputting an “S” afterwards?

Hi czglory, technically, from the exercises 2 and 3, I can see that you were told to put the line:

Exercise 2

Declare a variable called user_input and set it equal to the user’s input using gets.chomp.

user_input = gets.chomp

Exercise 3

Call the .downcase! method on user_input.

user_input.downcase!

So, the complete code is:

user_input = gets.chomp
user_input.downcase!

which is correct and the original poster squalo had a different code.

Hope that helps! :slightly_smiling:

Hey

my code is
print “City?”
user_input = gets.chomp
user_input.downcase!

if unser_input.include? “S”
print “OK”
end

and for some reason I cannot figure out what it’s supposed to be. You guys have an answer?

thanks

Then why does the example code at the beginning of the lesson not follow this more correct code? Seems like an error in their lesson?

Hello, the first lesson, is following the same first two lines of code as I have written.

Exercise code:

// print is unnecessary
user_input = gets.chomp
user_input.downcase!

What I had written:

user_input = gets.chomp
user_input.downcase!

I am having a similar issue as the rest of you and still have not figured out the solution.

@felixlienau check the spelling in your code.

Very late to reply to this but you put unser_input not user_input

Hi, recently started with code academy my problem is that:

print “hi hows it going?”
user_input = gets.chomp.
user_input.downcase!

if user_input.include? “s”
print “this contains an s awesome!”

end

typing “sok” in console returns: “undefined method `user_input’ for “s”:String”

not sure what im doing wrong,

lowell

fixed!

retyped all my code without a space between include? and “s”… sorted!