Ruby Newbie needs some guidance adding 1 to an assignment

Hello everyone!
I need a little assistance.
I am working on a program that will add +1 to a gets.chomp assignment.
Please take a look:

puts ‘Hey, whats your name?’
firstname = gets.chomp
puts 'Thank you ‘+ firstname + ‘!’ ’ What’s you’re favorite number?’
favnumber = gets.chomp
puts ‘Awesome, but I think ’ + favnumber + ’ is way better and bigger’

How do I add 1 to their favorite number?

User input is a string. Convert it to a number first. If it is supposed
to be an integer, use gets.chomp.to_i, if it can be a decimal number,
use gets.chomp.to_f. Then you cann add 1 with favnumber+1.

If you’re going to build the end string like that, you’ll also need to
convert the number back into a string.
For example:
‘… think ’ + number.to_s + ’ is …’

Dansei Yuuki wrote in post #1178968:

User input is a string. Convert it to a number first. If it is supposed
to be an integer, use gets.chomp.to_i, if it can be a decimal number,
use gets.chomp.to_f. Then you cann add 1 with favnumber+1.

Thanks Dansei I am about to work on it now!

Joel P. wrote in post #1178988:

If you’re going to build the end string like that, you’ll also need to
convert the number back into a string.
For example:
‘… think ’ + number.to_s + ’ is …’

Thanks Joel, I am working with it now. Ill update you guys as soon as I
get it.

This forum is not affiliated to the Ruby language, Ruby on Rails framework, nor any Ruby applications discussed here.

| Privacy Policy | Terms of Service | Remote Ruby Jobs