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


Stuck on extra credit for Input and Printing

Im attempting to do this at the end of the 2nd section for Ruby Foundations:

"Write a small Ruby program that asks you what your name is. Have the program print out the number of characters in your name. Also have the program print out a message if your name is longer than 25 characters."

I dont know how to figure out how to get the number of characters in the in-putted name and also I dont recall this being taught in the class, am I missing something?

2 Answers

Maciej Czuchnowski
Maciej Czuchnowski
36,441 Points

You should store the name in a variable and then use the length method like this:


This simply returns the number of characters in that variable. You can store that number in another variable:

characters = name_variable.length

and then use it in the condition:

if characters > 25

Hoep this helps. Extra credit means you have to find things on your own, not in the videos ;)

Thanks! I had actually done a lot of searching for the right terms to use but couldnt find them