Reputation: 105
So I'm completely new to Ruby. I apologize in advance.
A few lessons in on code-academy and I thought of testing the waters a bit. The code I am playing with is like so,
puts "Enter some text"
input_value = gets.chomp
hello_value = "whats up"
if input_value.include? "hello"
input_value.gsub! "hello", "#{hello_value}"
end
puts input_value
This seems to work fine. However, when I try adding a number like so,
puts "Enter some number"
input_value = gets.chomp
number_value = 1000
if input_value.include? "100"
input_value.gsub! "100", "#{number_value}"
end
puts input_value
This seems to freeze up after entering the number. I have no idea as what could be wrong. I was actually looking at ways to replace a entered value. Unfortunately, my very limited knowledge has stumped me completely lol. Any feedback on what I could do to resolve this would be appreciated.
Thanks everyone.
Upvotes: 2
Views: 49
Reputation: 6862
The code looks fine. Just be sure that you're inputting 100
, because that's your condition: input_value.include? "100"
.
So, if you input
Hello100World
Your code outputs
Hello1000World
As expected, right?
Upvotes: 1