RESOLVED (Can't delete this) Wanderlust Step 32 - Cannot access 'venue' before initialization

Issue was at line 56: I wrote

const venue = venue[index]

and it should have been:

const venue = venues[index]

:slight_smile:

I’m at step 32 and I’m getting this error all of a sudden:

Uncaught (in promise) ReferenceError: Cannot access ‘venue’ before initialization

I’ve looked at the live project and I don’t see any difference between the code on there and my own code. Can anyone help?

// Foursquare API Info
const clientId = 'OIWJ2NBIZCCXLGBYJK54UMWGV3MYTUN2DYAFZPMF30SGVUZE';
const clientSecret = 'SCOC22YKOLSO5OSIUNDHJL3LFOZ4CCVYSMRNDWALNEOMG0WR';
const url = 'https://api.foursquare.com/v2/venues/explore?near=';

// OpenWeather Info
const openWeatherKey = '35616d7b9a8daeddcb1f323e06c390da';
const weatherUrl = 'https://api.openweathermap.org/data/2.5/weather';

// Page Elements
const $input = $('#city');
const $submit = $('#button');
const $destination = $('#destination');
const $container = $('.container');
const $venueDivs = [$("#venue1"), $("#venue2"), $("#venue3"), $("#venue4")];
const $weatherDiv = $("#weather1");
const weekDays = ['Sunday', 'Monday', 'Tuesday', 'Wednesday', 'Thursday', 'Friday', 'Saturday'];

// Add AJAX functions here:
const getVenues = async () => {
  const city = $input.val()
    const urlToFetch = `${url}${city}&limit=10&client_id=${clientId}&client_secret=${clientSecret}&v=20180101`;
  try {
    const response = await fetch(urlToFetch);
    if (response.ok) {
      const jsonResponse = await response.json();
      const venues = jsonResponse.response.groups[0].items.map(item => item.venue);
    return venues
    }
  }
  catch(error) {
    console.log(error)
  }

}

const getForecast = async () => {
  const urlToFetch = `${weatherUrl}?q=${$input.val()}&APPID=${openWeatherKey}`
try {
  const response = await fetch(urlToFetch);
  if (response.ok) {
    const jsonResponse = await response.json();
    return jsonResponse
  }
}
catch(error) {
  console.log(error);
}
}


// Render functions
const renderVenues = (venues) => {
  $venueDivs.forEach(($venue, index) => {
    // Add your code here:
    const venue = venue[index];
    const venueIcon = venue.categories[0].icon;
    const venueIconSrc = `${venueIcon.prefix}bg_64${venueIcon.suffix}`;

    let venueContent = createVenueHTML(venue.name, venue.location, venueIconSrc);
    $venue.append(venueContent);
  });
  $destination.append(`<h2>${venues[0].location.city}</h2>`);
}

const renderForecast = (day) => {
  // Add your code here:
  
	let weatherContent = '';
  $weatherDiv.append(weatherContent);
}

const executeSearch = () => {
  $venueDivs.forEach(venue => venue.empty());
  $weatherDiv.empty();
  $destination.empty();
  $container.css("visibility", "visible");
  getVenues().then(venues => renderVenues(venues));
  getForecast()
  return false;
}

$submit.click(executeSearch)