Re: Newbie help, please

Mike W. wrote:

Hello all,

I am a complete novice to programming. I have chosen Ruby as my first
language.

I am attempting to follow some tutorials in a book I have. However, I am
running into some errors, and can not figure out why. Can you please
guide me?

You cannot simply add strings and numbers together; you must convert
number to string first.

Try this code:

puts (2+4).to_s + ’ is the sum of 2+4.’

and

puts ‘Hello, what is your favorite number?’
number = gets.chomp
better = number.to_i+1
puts number.to_s + '?? Don\t you know that ’ + better.to_s + ‘is a
superior
selection?’

But the right way to do this is to use expression inlining, such as
there:

puts “#{2+4} is the sum of 2+4.”

or

puts “#{number}?? Don\t you know that #{better} is a superior
selection?”

It does .to_s implicitly. Notice the double quotes, it won’t work with
single.

 WBR, Peter Z.