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 trialIra Salem
3,031 PointsReturn vs. Puts
I noticed in one of my challenges it asked me to "return" a specific string. Well I used the term "puts" and kept getting it wrong. I changed puts to return and it was correct.
My question is what is the big difference between the 2?
2 Answers
Jennifer Nordell
Treehouse TeacherThe difference is one outputs the value to the screen. The other sends back or return
s the value to the code that called it. Using return is a way to pass information around in your program while the puts is simply for outputting the information. Hope this helps!
Kevin Liu
5,589 PointsYo Ira Salem, Just had same question. let me get it a try
In Ruby, every method returns the evaluated result of the last line that is executed.
It is very different from the Javascript world
However, a important feature of return is that it exits from your function (prematurely)
Hope this helps! Cheers,