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 trial

Ruby Ruby Basics Numbers Converting Strings to Numbers

Pui Lun Christin C Hebron
Pui Lun Christin C Hebron
5,693 Points

We've assigned the string "123" to a variable named string. Take string, use a method to convert it to an integer, and s

I am a bit confused about this question. This is what I have

string = "123" integer = 123 string = integer.to_i

float = 123.0 string = float.to_i

Please help?

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

float = 123.0
string = float.to_f

1 Answer

Steven Parker
Steven Parker
231,268 Points

The instructions tell you to to convert the variable "string" to an integer, and to a float. You won't need to use any literal numbers in your code.

Pui Lun Christin C Hebron
Pui Lun Christin C Hebron
5,693 Points

I tried eliminating the numbers in the code like this, but not working

string = integer.to_i

string = float.to_f

Steven Parker
Steven Parker
231,268 Points

Check your syntax again. The thing being assigned goes on the left side of the operator (=), and the thing providing the value goes on the right.