I can print a raw number with this code:
puts 'Please enter your favorite number'
favNumber = gets.chomp
betterNumber = favNumber.to_i
puts betterNumber + 1
but I need to set a message including the number. I changed the last two lines to this, but it’s wrong.
betterNumber = favNumber.to_i + 1
puts 'Your favorite number sucks, a better number is '+ betterNumber + '!'
Help me.
betterNumberis of classFixnumand your string is of course of classString. You can’t add a String and a Fixnum, you need to cast your Fixnum into a String usingto_s.Also, using interpolation calls
to_son any objects being interpolated. So this works, too (and is more common):Also, in Ruby we usually use
snake_casevariables as opposed tocamelCasevariables. So I recommend usingbetter_number