Setting up the if branch, part 1


#1

Hi Folks,
On this lesson, I get different results from the following code -
https://www.codecademy.com/en/courses/ruby-beginner-en-JdNDe/0/4?curriculum_id=5059f8619189a5000201fbcb
This works, putting the downcase! command on a separate line.

print "enter a text string to DaffyDuckify"
user_input = gets.chomp
user_input.downcase!

if user_input.include? "s"
  print "found an s there"
else
  print "no s found"
end

The following throws an error - undefined method `include?' for nil:NilClass

print "enter a text string to DaffyDuckify"
user_input = gets.chomp.downcase!

if user_input.include? "s"
  print "found an s there"
else
  print "no s found"
end

This only errors if the input is all lowercase...an uppercase S works fine..

Can anyone explain the difference in the two methods?
Much appreciated,
Ian


Setting up the if branch, part 1
#2

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