Skip to content

Instantly share code, notes, and snippets.

@codecademydev
Last active November 5, 2020 02:31
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save codecademydev/d41c1e076c2e8dcc73a6a66a87ed1ad7 to your computer and use it in GitHub Desktop.
Save codecademydev/d41c1e076c2e8dcc73a6a66a87ed1ad7 to your computer and use it in GitHub Desktop.
Codecademy export
// Foursquare API Info
const clientId = 'P1YCEZPMUWG02HQ5C0G2V41D0WGIAOC20XKRO421IXAKXUIK';
const clientSecret = 'Z0YSPAYTKAJU5LNKMDR25QM5B3H0YF0FEREQT2GUSUVR3P54';
const url = 'https://api.foursquare.com/v2/venues/explore? near=';
// OpenWeather Info
const openWeatherKey = '4c4314a134e3152cd66086ecf737981a';
const weatherUrl = 'https://api.openwathermap.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();
console.log(jsonResponse);
}
}catch {
console.log(error);
}
}
const getForecast = () => {
}
// Render functions
const renderVenues = (venues) => {
$venueDivs.forEach(($venue, index) => {
// Add your code here:
let venueContent = '';
$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()
getForecast()
return false;
}
$submit.click(executeSearch)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment