Last active
September 17, 2019 06:21
-
-
Save harrisonmalone/d49037024e5fe147f1e7dfdca7395536 to your computer and use it in GitHub Desktop.
code from promise.all lecture
This file contains hidden or 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
| <!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>Document</title> | |
| </head> | |
| <body> | |
| <script src="./index.js"></script> | |
| </body> | |
| </html> |
This file contains hidden or 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
| const myData = [] | |
| const getUser = async () => { | |
| const response = await fetch('https://randomuser.me/api/'); | |
| const data = await response.json(); | |
| return data | |
| } | |
| const getPokemon = async () => { | |
| const response = await fetch('https://pokeapi.co/api/v2/pokemon'); | |
| const data = await response.json(); | |
| return data | |
| } | |
| const accessData = () => { | |
| // TODO create 3 random users | |
| try { | |
| const randomUserOne = getUser(); | |
| const randomUserTwo = getUser(); | |
| const randomUserThree = getUser(); | |
| const pokemonData = getPokemon(); | |
| const allUsersAndPokemon = await Promise.all([randomUserOne, randomUserTwo, randomUserThree, pokemonData]) | |
| // console.log(allUsersAndPokemon) | |
| // .then((response) => [ | |
| // console.log(response) | |
| // ]) | |
| // .catch((err) => { | |
| // console.log(err) | |
| // }) | |
| // console.log('wassup!!!!') | |
| // console.log(allUsersAndPokemon) | |
| // myData.push(allUsersAndPokemon) | |
| // console.log(myData) | |
| } catch(err) { | |
| console.log(err) | |
| } | |
| } | |
| accessData(); | |
| console.log(myData) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment