Wanderlust Help Needed: Uncaught SyntaxError: await is only valid in async function

Hello everyone,

I am stuck on Step 11 of the Wanderlust Intro to JavaScript project.

When I type the code exactly as in the hint and hit Save

const response = await fetch(urlToFetch);

I get the following error in my browser console:
Uncaught SyntaxError: await is only valid in async function

I have checked all of my code against the hints and I can’t find the cause of the problem.

Here is my full code - any help greatly appreciated!

// Add AJAX functions here:
const getVenues = async () => {
const city = $input.val();


const urlToFetch = url + city + '&limit=10&client_id=' + clientId + '&client_secret=' + clientSecret + '&v=20180401';
}
try {
  const response = await fetch(urlToFetch);
...

I just figured out the problem on my own.

In case anyone else runs into this in the future, the problem was that I accidentally had put the try and catch statements outside of the getVenues function.

:crazy_face:

Once I placed them inside, everything ran correctly.

OK, on with the rest of the project!

1 Like

Good job finding the mistake!