Thith Meanth War! Lesson 7

ruby

#1

I don't understand what it is that I'm supposed to learn or accomplish here, can someone give me some more detail?

This is my code:

print "What comes after Friday?"
user_input = gets.chomp
user_input2 = user_input.downcase
user_input.downcase!
if user_input.include? "s"
user_input.gsub!(/s/, "th")
else
print "Looks like you don't even have an s in your answer!"
end

my_string = "muchachos"
puts "Adios, #{my_string}"

The prompt shows:

What comes after Friday? Saturday
Adios, muchachos
nil

Why isn't "Thaturday" appearing anymore as it did in the previous exercise before adding the muchachos lines?

Also, I think it's worth mentioning that if I delete everything except for the last 2 lines, I'm still marked as correct.


#2

The above lines are not needed if we write the first line like so,

user_input = gets.chomp.downcase

This will permit entering all lowercase.

Not a part of the exercise, but instruction example. That can be removed, as well.

I think there may be a line missing at the end, where we show the user the transformed text:

puts "Your string is: #{user_input}"

#3

Thanks for clearing that up!


#4

I still dont understand here is what I have so far:

print " Input goes here "
    gets.chomp
user_input = gets.chomp.downcase!
if user_input.include? "s"
    then user_input.gsub!(/s/, "th")
    puts "Your string is: #{user_input}" 
else print " No words had the letter s"
   
end

#5

The random floating "gets.chomp" needs to be removed, your print statements have random spaces, and you need do and end keywords for your logic statements.


#6

Leading and trailing spaces are rarely used. We don't need them in strings, and probably should not get in the habit of using them.

As the earlier reply mentions, the stray gets.chomp is not doing anything and should be removed.

If you want to be able to enter any text case, such as all lower, then don't use .downcase! Instead, use .downcase.


#7

Ok thanks for the help!

How would I prompt the user for input if none is given? Here is what I have tried

print "Input goes here"
user_input = gets.chomp.downcase
if user_input == nil
    then print "Please enter somthing"
end
if user_input.include? "s"
    then user_input.gsub!(/s/, "th")
    puts "Your string is: #{user_input}" 
else print " No words had the letter s"
   
end

#8

The way to force input is to use a loop. Only two conditions permit the loop to end. Quit, or not an empty string.

The empty string could be interpreted as 'Quit'. Anything else would be up for string testing.

def get_user_input():
    x = raw_input("User input")
    return x if len(x) > 0 else False

This is not a loop, but it is the seed of what might become a loop.

Edit:

Language mixup.

Do I fall on my sword or just move on from this? Too much mixing of languages for this cohort.