Welcome to the Treehouse Community
Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.
Looking to learn something new?
Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.
Start your free trialJulia Thalita Da Silva Carrilo
1,347 PointsError about +
When I use the "+" always show this error and not show me result. my code: name = "Julia" string = "My name is #{name}" puts string
year = "2014" puts "The year is #{year}"
future = 5 puts "In #{future} years, the year will be #{year + future}"
error in console:
The year is 2014
hello.rb:9:in +': no implicit conversion of Fixnum into St
ring (TypeError)
from hello.rb:9:in
<main>'
1 Answer
andren
28,558 PointsThe issue is that the year
variable is considered a string (which is used to represent text) and not an int (which is used to represent numbers) due to the fact that you have wrapped the number in quotation marks.
Quotation marks are only used when declaring a string. For pure numbers you should just write them out normally like you have done with the future
variable.
So if you remove the quotation marks around the year like this:
year = 2014
puts "The year is #{year}"
future = 5
puts "In #{future} years, the year will be #{year + future}"
Then your code will work.