App Academy

I am Mark, learning to code again at age 63

firstnum =4
secondnum = 5
puts “#{firstnum} + " is” + #{secondnum} + " is"}

got me stumped, do not know offhand how to get it to work thanks gang

Hi Mark, it seems to me that you got a bit mixed up, please try this:

firstnum = 4
secondnum = 5
puts “#{firstnum}” + " + " + “#{secondnum}” + " is"

puts - will put the string out in the console so will be able to see it.
“#{firstnum}” this is called intrapolation, so you are putting a variable inside a string, that is why you need the #{} (and you also need the quote because it’s a string)

  • here you are adding another part
    " + " here you want the plus sign to be visible in the console so you need to put it in the quotes, include spaces on each side so that it’s more readible. Try without spaces and see what happens.
  • again, you are adding another part
    “#{secondnum}” - again like with the firstnum, you are using a variable inside a string so you need to use #{}
  • again, you are adding another part
    " is" - printing a string. This is just a string, not a variable that will change, so you don’t need #{}

I hope that is clear, if not, please feel free to ask questions.

you could also write puts firstnum.to_s +" is" + secondnum.to_s + “is” #=> 4 is 5 is

to_s stands for to string.

somehow, I don’t believe that would be what you want.
Are you trying to end up with “first num is 4 second num is 5”?