-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathanimal.js
32 lines (25 loc) · 899 Bytes
/
animal.js
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
const animal = {
animals : ['dog', 'cat', 'panda', 'red_panda', 'fox'],
numberofImages : 3,
}
async function GetAnimalImage(name) {
const response = await fetch('https://some-random-api.com/img/' + name).catch((error) => {
console.error('Error:', error);
}).then((response) => {
return response.json()
})
return response.link
}
async function GetRandomAnimal(){
for (let i = 0; i < animal.animals.length; i++){
const animalName = animal.animals[i]
console.log("Animal Name: " + animalName)
for (let j = 0; j < animal.numberofImages; j++){
const image = await GetAnimalImage(animalName)
console.log(image)
}
}
}
GetRandomAnimal().then((data) => {
console.log(":Done")
})