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 Loops Ruby Loops The While Loop

John Bamberg
John Bamberg
9,774 Points

answer string

Why empty answer string?

answer""

Maciej Czuchnowski
Maciej Czuchnowski
36,441 Points

Please explain your problem and link the proper challenge.

2 Answers

Hi John,

The reason is you need define the variable "answer" as an empty string. If you don't, you'll get an error saying "undefined local variable or method 'answer' ".

Hope that helps!

Tyler

rowend rowend
rowend rowend
2,926 Points

Hi, you need this variable before the loop to solve scope variable problems. If you define the variable answer inside the loop you could use the variable inside of code of block of while loop but you could not use it as part of the condition of the loop.