-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmeteo.js
More file actions
72 lines (56 loc) · 2.64 KB
/
meteo.js
File metadata and controls
72 lines (56 loc) · 2.64 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
const url ="https://www.prevision-meteo.ch/services/json/";
const btnSend = document.querySelector("form input[value = 'envoyer']");
btnSend.addEventListener("click", event => requestApi(event));
function requestApi(event) {
event.preventDefault();
const city = document.querySelector("form input[name = 'city']");
console.log(city.value);
fetch(`${url}${city.value}`)
.then(response => response.json())
.then(data => {
display.textContent = (city.value);
let date = document.createElement("div");
date.textContent = `${data.current_condition.date}`,`${data.current_condition.hour}`;
display.appendChild(date);
let condi = document.createElement("p");
condi.textContent = "Conditions actuelles";
display.appendChild(condi);
let img = document.createElement("img");
img.src = data.current_condition.icon;
display.appendChild(img);
let tmp = document.createElement("div");
tmp.textContent = `${data.current_condition.tmp}°C`;
display.appendChild(tmp);
let tab = [data.fcst_day_1,data.fcst_day_2,data.fcst_day_3,data.fcst_day_4]
for (i=0 ; i<=tab.length-1 ; i++){
let date1 = document.createElement("div");
date1.textContent = `${tab[i].date}`;
display.appendChild(date1);
let img1 = document.createElement("img");
img1.src = tab[i].icon;
display.appendChild(img1);
let condi1 = document.createElement("div");
condi1.textContent = tab[i].condition;
display.appendChild(condi1);
let tmp1 = document.createElement("div");
tmp1.textContent = `${tab[i].tmin}°C ${tab[i].tmax}°C`;
display.appendChild(tmp1);
//let tab2 = [tab[i].hourly_data[j]];
//for (j=1 ; j<=23 ; j++){
//let date2 = document.createElement("div");
//date2.textContent = `${tab[i].tab2[j]}`;
// display.appendChild(date2);
//let img2 = document.createElement("img");
//img2.src = tab[J].hourly_data['[j]H00'].icon;
//display.appendChild(img2);
//let condi2 = document.createElement("div");
//condi2.textContent = tab[j].condition;
//display.appendChild(condi2);
//}
}
console.log();('success:', data);
})
.catch((error) => {
console.error('Error:', error);
});
}