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

Jason Smith
Jason Smith
17,879 Points

I can't seem to figure this code challenge out. I used the to_i to convert a string to an integer but...

We've assigned the string "123" to a variable named string. Take string, use a method to convert it to an integer, and store the result in a variable named integer. Then call a second method on string to convert it to a floating-point number, and store the result in a variable named float.

program.rb
string = "123".to_i
float = "123".to_f
Jason Smith
Jason Smith
17,879 Points

nevermind I got the code to work. I made the silly mistake of not reading everything carefully.

string = "123" integer = string.to_i float = string.to_f

1 Answer

Ari Misha
Ari Misha
19,323 Points

Hiya there! You're code is right on point infact. But you see you're not following the challenge all the way. It said you need to store converted values in the integer and float respectively. Your code should look like this:

string = "123"
integer = string.to_i
float = string.to_f

~ Ari

Jason Smith
Jason Smith
17,879 Points

Thank you, I just figured this out a few mins ago after I read the question again. haha You are right I wasnt following the challenge correctly. Thanks again for the reply.