-
-
Save codecademydev/a4430b3b9357131903fc742274e01d9b to your computer and use it in GitHub Desktop.
Codecademy export
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Foursquare API Info | |
const clientId = 'MZ2MINSLQR5VVSXKEYID5IR11I2ZWGGZIKFVAHA5NJL1M51Y'; | |
const clientSecret = 'NS0RHB1R51GSAABLG3MMY0D355Z4WDQA143PTK2X0VPRQFWG'; | |
const url = 'https://api.foursquare.com/v2/venues/explore?near='; | |
// OpenWeather Info | |
const openWeatherKey = '9f1d31dc9935fd2fdfc5d1802da57b21'; | |
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}${$input}&limit=10&client_id=${clientId}&client_secret=${clientSecret}&v=20200602`; | |
try { fetch(urlToFetch); | |
const jsonResponse = await response.json(); | |
console.log(jsonResponse); | |
} catch (error) { | |
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