-
-
Save codecademydev/ea84059eb5dddd6b94f202251432f8ec 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 = 'SBVCAWT31Q2KFUVFYNHRNWTZE1NPNKWMZK3UP3G5BJPN1GRH'; | |
const clientSecret = 'OFCFFNYVNSJMAN0XAB5SEE3HBJVEIAMXKJ32CA1OKSZOWRSO'; | |
const url = 'https://api.foursquare.com/v2/venues/explore?near='; | |
// APIXU Info | |
const apiKey = 'c226f81bbb924750b9b224121190901'; | |
const forecastUrl = 'http://api.apixu.com/v1/forecast.json?key='; | |
// Page Elements | |
const $input = $('#city'); | |
const $submit = $('#button'); | |
const $destination = $('#destination'); | |
const $container = $('.container'); | |
const $venueDivs = [$("#venue1"), $("#venue2"), $("#venue3"), $("#venue4")]; | |
const $weatherDivs = [$("#weather1"), $("#weather2"), $("#weather3"), $("#weather4")]; | |
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) { | |
console.log(response) | |
const jsonResponse = await response.json | |
console.log(jsonResponse) | |
} else { | |
throw new Error('Request Failed!') | |
} | |
} catch (error) { | |
console.log(error.message) | |
} | |
}; | |
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 = (days) => { | |
$weatherDivs.forEach(($day, index) => { | |
// Add your code here: | |
let weatherContent = ''; | |
$day.append(weatherContent); | |
}); | |
} | |
const executeSearch = () => { | |
$venueDivs.forEach(venue => venue.empty()); | |
$weatherDivs.forEach(day => day.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