Skip to content

Instantly share code, notes, and snippets.

@harrisonmalone
Last active September 17, 2019 06:21
Show Gist options
  • Select an option

  • Save harrisonmalone/d49037024e5fe147f1e7dfdca7395536 to your computer and use it in GitHub Desktop.

Select an option

Save harrisonmalone/d49037024e5fe147f1e7dfdca7395536 to your computer and use it in GitHub Desktop.
code from promise.all lecture
<!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>
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