-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmultiplepromises.js
More file actions
81 lines (52 loc) · 1.95 KB
/
multiplepromises.js
File metadata and controls
81 lines (52 loc) · 1.95 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
// JavaScript working with multiple promises
// const youTubePost = {id: 1, comment: 'You Rock!'};
// const hobbies = ['Skateborarding', 'Coding'];
// const post = new Promise((resolve, reject) => {
// setTimeout(() => {
// resolve(youTubePost);
// ), 4000);
// })
// const post = new Promise((resolve, reject) => {
// setTimeout(() => {
// resolve(hobbies);
// ), 1000);
// })
// Promise
// .all([post, hobby])
// .then((daa) => console.log(data));
***********************************************************
// const youTubePost = {id: 1, comment: 'You Rock!'};
// const hobbies = ['Skateborarding', 'Coding'];
// const post = new Promise((resolve, reject) => {
// setTimeout(() => {
// resolve(youTubePost);
// ), 4000);
// })
// const post = new Promise((resolve, reject) => {
// setTimeout(() => {
// resolve(hobbies);
// ), 1000);
// })
// Promise
// .all([post, hobby])
// .then((data) => {
// const [ytPost, myHobbies] = data;
// console.log(ytPost, myHobbies);
// });
***************************************************************
// You need to run on a server of some type wether that be the server service on VS code has.
const pokemon = fetch('http://pokeapi.co/api/v2/pokemon/pikachu);
const chuckNorris = fetch('https://api.chucknorris.io/jokes/random);
Promise
.all([pokemon, chucknorris])
.then((response) => {
return Promise.all(response.map((res) => res.json()));
})
.then((data) => {
const [poke, joke] = data;
console.log(poke.name, joke.value);
console.log(`
${poke.name}
${joke.value}
`)
});