Welcome to the Treehouse Community

The Treehouse Community is a meeting place for developers, designers, and programmers of all backgrounds and skill levels to get support. Collaborate here on code errors or bugs that you need feedback on, or asking for an extra set of eyes on your latest project. Join thousands of Treehouse students and alumni in the community today. (Note: Only Treehouse students can comment or ask questions, but non-students are welcome to browse our conversations.)

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and a supportive community. Start your free trial today.

JavaScript

Looping through a jQuery collection: the code from the video works okay in the devTools but not in the Worskapces. Why?

I launched the Worskspace for this video and copied Treasure´s code correctly (even with the backticks):

$('a').each(function(index, link){ const url = $(link).attr('href'); $(link).parent().append((${url})); });

When I refresh the preview it doesn´t work though. So I tried to copy the code correctly in the Console of devTools and refreshed the preview and all works well!

I was wondering: Why? It happened to me in several previous videos. That the exactly copied code would only work from the devTools console, but not from the Workspaces.

It usually gives me this error in the devTools console:

Uncaught SyntaxError: missing ) after argument list app.js.4

So I diligently check the line 4 in app.js every time, but there is nothing missing nor nothing wrong. It is a brain teaser indeed:)

Thank you for your explanation:) I love the courses!

1 Answer

It is working:) Hurray!

There was an error on line 4 in app.js. Originally it was this:

const $pdfCheckbox = $('<label><input type='checkbox'> Allow PDF downloads</label>');

This is the new corrected version:

const $pdfCheckbox = $('<label><input type="checkbox"/> Allow PDF downloads</label>');

I changed the single quotes into double quotes and added a closing slash and it started to work! I just copied this line from the index.html before and didn't think more about it until today.

Happy coding and bug finding:)!