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

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,274 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.