Welcome to the Treehouse Community

The Treehouse Community is a meeting place for developers, designers, and programmers of all backgrounds and skill levels to get support. Collaborate here on code errors or bugs that you need feedback on, or asking for an extra set of eyes on your latest project. Join thousands of Treehouse students and alumni in the community today. (Note: Only Treehouse students can comment or ask questions, but non-students are welcome to browse our conversations.)

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and a supportive community. Start your free trial today.

Ruby Ruby Basics Numbers Converting Strings to Numbers

Saadia Fattah
Saadia Fattah
1,939 Points

I tried both of these methods for the integer part,but for to_i say it is nil but when i try that it says unidentified

Please i need some help on this problem

program.rb
string = "123"
# YOUR CODE HERE
string = integer.to_i
string = float.to_f

1 Answer

Stephen Falck
Stephen Falck
7,558 Points

im assuming you are trying to convert the string into an integer and a float. In this case the reason its not correct is that you are performing your to_i and to_f methods on "integer" and "float" which have no values assigned to them and trying to assign the result to the variable "string"

integer = string.to_i
float = string.to_f

this will perform the methods on the string variable and save the result to new variables called integer and float