-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathscore.js
82 lines (69 loc) · 2.96 KB
/
score.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
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
//Récupérer les éléments du DOM
var elapsedTime = document.querySelector("#elapsed");
var homeTeamImage = document.querySelector("#homeLogo");
var homeTeamName = document.querySelector("#homeName");
var awayTeamImage = document.querySelector("#awayLogo");
var awayTeamName = document.querySelector("#awayName");
var lastMatchGoal = document.querySelector("#goals");
var matchTable = document.querySelector("#matchTable");
//Les fonctions pour créer un élément
function addMatchTile(data) {
//Création de la tile div
var matchtile = document.createElement('div');
matchtile.classList.add("match-tile");
//Création de la home match box
var homeTeam = document.createElement('div');
homeTeam.classList.add("team");
//Création de l'image et du texte
var homeTileTeamName = document.createElement('p');
homeTileTeamName.innerHTML = data['teams']['home']['name'];
var homeTileTeamLogo = document.createElement('img');
homeTileTeamLogo.src = data['teams']['home']['logo'];
homeTeam.appendChild(homeTileTeamLogo);
homeTeam.appendChild(homeTileTeamName);
var awayTeam = document.createElement('div');
awayTeam.classList.add("team");
//création de l'image et du texte
var awayTileTeamName = document.createElement('p');
awayTileTeamName.innerHTML = data['teams']['away']['name'];
var awayTileTeamLogo = document.createElement('img');
awayTileTeamLogo.src = data['teams']['away']['logo'];
awayTeam.appendChild(awayTileTeamLogo);
awayTeam.appendChild(awayTileTeamName);
//Création du score
var score = document.createElement('p');
score.innerHTML = data['goals']['home'] + " - " + data['goals']['away'];
//Appliquer tous les éléments au parent
matchtile.appendChild(homeTeam);
matchtile.appendChild(score);
matchtile.appendChild(awayTeam);
matchTable.appendChild(matchtile);
}
//Récupération des données de l'API
fetch("https://v3.football.api-sports.io/fixtures?live=all", {
"method": "GET",
"headers": {
"x-rapidapi-host": "v3.football.api-sports.io",
"x-rapidapi-key": "6fb8f9469c604bbbc2f195e76e020e92"
}
})
.then(response => response.json().then(data => {
var matchesList = data['response'];
var fixture = matchesList[0]['fixture'];
var goals = matchesList[0]['goals'];
var teams = matchesList[0]['teams'];
console.log(matchesList.length);
//Maintenant, définissons notre premier match
elapsedTime.innerHTML = fixture['status']['elapsed'] + "'";
homeTeamImage.src = teams['home']['logo'];
homeTeamName.innerHTML = teams['home']['name'];
awayTeamImage.src = teams['away']['logo'];
awayTeamName.innerHTML = teams['away']['name'];
lastMatchGoal.innerHTML = goals['home'] + " - " + goals['away'];
for (var i = 1; i < matchesList.length; i++) {
addMatchTile(matchesList[i]);
}
}))
.catch(err => {
console.log(err);
});