Setting up the 'Else' branch


#1

Hey , Anyone have the solution?
I am stuck at this exercise !
The code is not working at all…

print "Pleathe enter a thtring: "
user_input = gets.chomp
user_input.downcase!

if user_input.include? "s"
user_input.gsub!(/s/, “th”)
else prints "there is no ‘s’"
end

Replace this line with your code.

<do not remove the three backticks above>

#2

Is that line even asked for?

Did you mean, puts, or print?


#3

Actually, I tried this version too but it’s not working neither:

print "Pleathe enter a thtring: " 
user_input = gets.chomp
if user_input.include? "s"
  user_input.gsub!(/s/, "th")
  else puts "there is no 's'"
end

#4

Please post a link to the lesson. Thanks.


#5

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


#6

I’ll have to go back to the beginning to read all the instructions, because my code does have the .downcase! but on the gets.chomp. That shouldn’t be an issue, though, either way. You have to make sure there is at least one uppercase letter in the input string if that method is being applied, else it returns nil.

Your input would be appreciated! surprise
undefined method `include?' for nil:NilClass
Your input would be appreciated! Surprise
Your string: thurprithe

It should not matter to Ruby how you indent, but for the reader, it’s nice to see structures line up and the code statements have their own block.

if ___
  # code
else
  # code
end

As you progress along, string interpolation is a handy feature in Ruby.

  puts "Your string: #{user_input}"
else
  puts "Yes, there are no 's's"
end

The argument may be any expression or value.


#7

I’m having the same issue!


#8

Be sure your input has at least one uppercase letter.


#9

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