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 trialStefan Piatkov
14,312 PointsNow we need to output HTML <p> elements with the name attribute of each pet. Within the each block, add <p></p> HTML tag
Not sure where I'm wrong.. If someone could please explain why I was wrong it'd be greatly appreciated.
<% @pets.each do |name| %>
<p>
<%= pet.name %>
</p>
<% end %>
1 Answer
Jay McGavren
Treehouse TeacherThe name you used for your each
block's parameter doesn't match the name of the variable you're accessing within the each
block:
<!-- The next line stores each pet in a variable called "name" -->
<% @pets.each do |name| %>
<p>
<!-- The next line accesses a nonexistent variable called "pet" -->
<%= pet.name %>
</p>
<% end %>
Change it to @pets.each do |pet|
, and it should work.
If you haven't already done our Ruby Loops course, you may find some helpful info here.
Stefan Piatkov
14,312 PointsStefan Piatkov
14,312 PointsThat didn't seem to work for me. I had a look back at previous videos and it just didn't make sense.
I passed the challenge by changing the parameter to title and the embedded Ruby to title.name though.. could it be a bug?
Jay McGavren
Treehouse TeacherJay McGavren
Treehouse TeacherStefan Piatkov I was able to pass the challenge using this code:
Stefan Piatkov
14,312 PointsStefan Piatkov
14,312 PointsI just tried it again, it worked. Thanks for your help Jay. :)