Skip to content

Instantly share code, notes, and snippets.

@codecademydev codecademydev/main.js Secret
Created Dec 21, 2018

Embed
What would you like to do?
Codecademy export
// Foursquare API Info
const clientId = 'XJ4BJV4MPQYKDGPN5XXHOR1WICFWGKEOF0HNAJ4SUDAYA1OR';
const clientSecret = 'RLIJLGUNOXGA0HJCO0XDJUYCTIE5HDNM4QL3MUJ4RNTY3JNZ';
const url = 'https://api.foursquare.com/v2/venues/explore?near=';
// APIXU Info
const apiKey = '2a6798059cde41be9f1213203182112';
const forecastUrl = 'http://api.apixu.com/v1/current.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=20181221`
try {
const response = await fetch(urlToFetch);
if (response.ok) {
console.log(response);
}
else {
throw new Error ('This is an error!');
}
}
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
You can’t perform that action at this time.