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
182,269 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
182,269 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.