-
Notifications
You must be signed in to change notification settings - Fork 0
/
test.js
65 lines (57 loc) · 2.19 KB
/
test.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
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
// function randomRace() {
// const firstYear = 1950;
// const currentYear = new Date().getFullYear();
// const randomYear = Math.floor(Math.random() * (currentYear - firstYear + 1) + firstYear)
// return fetch(`http://ergast.com/api/f1/${randomYear}.json`)
// .then((response) => {
// if (!response.ok) {
// const error = new Error(response.status);
// throw error;
// }
// else {
// return response.json();
// }
// })
// .then((data) => {
// let racesLength = data["MRData"]["RaceTable"]["Races"].length;
// return Math.floor(Math.random() * (racesLength))
// })
// .then((round) => {
// return fetch(`https://ergast.com/api/f1/${randomYear}/${round}/results.json`)
// .then((response) => {
// if (!response.ok) {
// const error = new Error(response.status);
// throw error;
// }
// else {
// return response.json();
// }
// })
// .then((data) => {
// console.log(data);
// return data;
// })
// })
// }
// function getDrivers() {
// randomRace().then((data) => {
// const raceInfo = data["MRData"]["RaceTable"]["Races"][0]
// console.log(raceInfo.season);
// console.log(raceInfo.raceName);
// const [P1, P2, P3, P4] = raceInfo["Results"];
// const driversInfo = [P1, P2, P3, P4].map((driver) => {
// let driverObject = {
// constructor: driver["Constructor"]["name"],
// driverName: `${driver["Driver"]["givenName"]} ${driver["Driver"]["familyName"]}`,
// position: driver["position"],
// timeMillis: driver["Time"]["millis"],
// time: driver["Time"]["time"]
// };
// return driverObject;
// })
// console.log(driversInfo);
// return driversInfo;
// })
// }
// randomRace()
// getDrivers()