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 trialSarah A. Morrigan
14,329 PointsWhat is undefined variable e here?
since there is no value assigned to variable e this seems to not work at all.
# Assume get_answer() is already defined
loop do
answer = get_answer()
if answer == e
break
end
end
3 Answers
William Li
Courses Plus Student 26,868 Pointsif answer == e
Because at this line, you are comparing variable e to answer, but the variable e can't be found anywhere else in your program, it just pop up all the sudden at this line, so Ruby doesn't know what to do with it and gives you a syntax error.
either you define the e somewhere before that line, or perhaps if answer == 'e'
.
Sarah A. Morrigan
14,329 Pointsnever mind.
I thought "Using a loop construct, assign the value of the get_answer() method to an answer variable. Use the break keyword to exit the loop if the answer variable is equal to the string e. Assume get_answer() is already written" meant answer variable == variable e.
Instead it was supposed to be a string consisting of a letter "e".
Lyndon Headley
12,430 PointsThat tripped me up as well, thanks for posting this, it cleared it up for me!
John Magee
Courses Plus Student 9,058 PointsYes, there is no value assigned to e, but you have all the code you need in front of you to create an assignment to e so it can be tested against answer