Code Not Printing Out but passing tasks?


#1

Hi there,

Does anyone have an idea why I'd pass the assigned tasks but I wouldn't be able to see the code work? In this exercise for example, all of the "S" stayed capitalized and the strings didn't print and "th" wasn't substituted, but I passed?? Now I'm not sure what's right or wrong? I just updated to newest chrome.

https://www.codecademy.com/courses/ruby-beginner-en-JdNDe/0/7?curriculum_id=5059f8619189a5000201fbcb


print "What is your favorite flavor of ice cream?"
user_input = gets.chomp.downcase!
if user_input.gsub!(/s/, "th")
else print "There's no Sss in that ice cream."
    puts "My favorite ice cream is #{user_input}!"
  
end


#2

Hi,

two things:

  • Try applying .downcase! on the user_input variable, rather than gets.chomp.
  • Your if statement is a bit odd, you're saying if user input replace all s by th, but you never ask if the user input includes an s in the first place?

You can check if there's an s with .include? "s"


#3

Hiya, thanks for speedy reply! I tried your suggestions but am now getting a syntax error: undefined local variable or method `user_input' for #

Have I not defined the variable for user_input properly?

print "What is your favorite flavor of ice cream?"
user_input.downcase!.gets.chomp
if user_input.include?"s".gsub!(/s/, "th")
else print "There's no Sss in that ice cream."
puts "My favorite ice cream is #{user_input}!"
end

I appreciate your assistance!


#4

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