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

JavaScript

David Gourdet
David Gourdet
3,095 Points

I'm having an "Uncaught SyntaxError: Invalid or unexpected token" with the exact same code

Hello,

The function generateImage() displays an error : "Uncaught SyntaxError: Invalid or unexpected token" at line 18

and I'm unable to correct it (I'm not very familiar with ES6, I think there is a problem with concatenation but I tried many things without success).

Can you help ?

This is my code :

const select = document.getElementById('breeds'); const card = document.querySelector('.card'); const form = document.querySelector('form');

// ------------------------------------------ // FETCH FUNCTIONS // ------------------------------------------ fetch('https://dog.ceo/api/breeds/image/random') .then(response => response.json()) .then(data => generateImage(data.message))

// ------------------------------------------ // HELPER FUNCTIONS // ------------------------------------------

function generateImage(data) { const html = ' <img src='${data}' alt> <p>Click to view images of ${select.value}</p> '; card.innerHTML = html; }

Regards,

David

2 Answers

Eric M
Eric M
11,545 Points

Hi David,

This might not be helpful because I'm not sure what video or exercise you're on, you've just posted this in JavaScript general, but it looks like you're trying to use a template literal and you've confused backticks ` and single quotes '

Check this out: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Template_literals

David Gourdet
David Gourdet
3,095 Points

Hi emck,

Thanks a lot ! that what I just figured out :) I think I will make a quick detour by the ES6 lessons ;)

Have a good day,

David

Eric M
Eric M
11,545 Points

Glad you got it David :)