4. Setting Up the "if" Branch, Part 1 -- What is wrong ?:c


#1

print "Qué pasa bato?"
user_input = gets.chomp.downcase!

if user_input.include? "s"
print "s"
end

Error said:"Oops, try again. Your code doesn't look quite right. Check the first exercise if you need help!"


#2

as in this thread, if your input is already lowercase, it will throw an error. Try input something with uppercase.


#3

any chance you could explain why this throws an error?
or how to avoid getting this error?

I'm new to ruby (obviously) but i havent seen this type of behaviour before in other languages i've used.

This seems like a pretty poorly designed exercise for someone learning how Ruby behaves, if the code is correct, but the "wrong" user input returns an error.


#4

use the .downcase! on a new line rather than combining them, otherwise it will throw the error, here is my code here:

print "give me some words: "
user_input = gets.chomp
user_input.downcase!

Hope that helps :smiley:


#5

It does not work this way either :slight_smile:

if user_input.downcase.include? "s"
print "got it !! "
end

I get the error : Oops, try again.
Don't forget to call .include? on user_input.

But it works fine on my computer. Looks like problem with this interface


#6

Just remove the '!' after downcase. Hope that helps


#7

print 'user_input'
user_input = gets.chomp
print "give an input"
user_input = gets.chomp
user_input2 = user_input
user_input.downcase!
if print "give me some words"
user_input gets.chomp
user_input.downcase!
end
print "Thtring, pleathe!: "
user_input = gets.chomp
user_input.downcase!

if user_input.include? "s"
user_input.gsub!(/s/, "th")
else
puts "Nothing to do here!"
end

puts "Your string is: #{user_input}"

That should work. It worked for me


#8

thank you very much lol


#9

Hi guys,
I am getting the same error for the following code:

print "Enter stuff"
user_input = gets.chomp
user_input.downcase!

if user_input.include? "f"
print "yes, its there"
else
print "nothing to do here"
end

ERROR MESSAGE: Oops, try again. Don't forget to call .include? on user_input.
Is it me or Codecademy?


#11