Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <!DOCTYPE html>
- <html lang="en">
- <head>
- <meta charset="UTF-8">
- <meta name="viewport" content="width=device-width, initial-scale=1.0">
- <meta http-equiv="X-UA-Compatible" content="ie=edge">
- <title>Asynchronous JavaScript</title>
- </head>
- <body>
- <h1>Asynchronous JavaScript</h1>
- <script>
- /*
- async function getRecipesAW() {
- const IDs = await getIDs;
- console.log(IDs);
- const recipe = await getRecipes(IDs[2]);
- console.log(recipe);
- const related = await getRelated('Jay DeGraaf');
- console.log(related);
- return recipe;
- }
- getRecipesAW().then.(result => console.log(`${result}` is the best recipe ever!));
- */
- function getWeather(woeid) {
- // cross origin allows you to access a site that is unaccessible.
- fetch ('https://cors-anywhere.herokuapp.com/https://www.metaweather.com/api/location/${woeid}/')
- .then(result => {
- console.log(result);
- return result.json();
- })
- .then(data => {
- const today =data.consolidated_weather[0];
- console.log(`Temperatures in ${data.title} stay between ${today.min_temp} and ${today.max_temp}.`)
- })
- .catch(error => console.log(error));
- }
- getWeather(2487956);
- getWeather(44418);
- async function getWeatherAW (woeid) {
- try {
- const result = await fetch ('https://cors-anywhere.herokuapp.com/https://www.metaweather.com/api/location/${woeid}/')
- const data = await result.json();
- const tomorrow =data.consolidated_weather[1];
- console.log(`Temperatures tomorrow in ${data.title} stay between ${tomorrow.min_temp} and ${today.max_temp}.`);
- return data;
- } catch (error) {
- console.log(error);
- }
- }
- getWeather(2487956);
- let dataLondon;
- getWeather(44418).then(data => {
- dataLondon = data;
- console.log(dataLondon);
- });
- </script>
- </body>
- </html>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement