Setting Up the 'If' Branch, Part 2 My .gsub! method doesn't work!


#1

https://www.codecademy.com/courses/learn-ruby/lessons/thith-meanth-war/exercises/setting-up-the-if-branch-part--1?action=lesson_resume

<In what way does your code behave incorrectly? Include ALL error messages.>
The .gsub! method doesn’t work yet I put user’s input please string this means war at the terminal clicked enter and nothing happened ???
BUT strangely the exercice is considered as succeed ??? Green next button && green instructions


print "Could you give some 
input ? "
user_input=gets.chomp
user_input.downcase!
if user_input.include? "s"
   user_input.gsub!(/s/, "th")
end


thanks for your help !


#2

gsub is working is fine, but everything is happening under the hood.

the substitution is working fine, but you need use puts to display the new string if you want.


#3

Oh yes ! It works when you add puts user_input .
I thought gets.chomp would be enough ???
Thanks a lot Stetim94 ! :smiley:


#4

no, gets.chomp is only prompting the user for input, to display output we need to use puts (or print)


#5

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.