-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathindex.js
More file actions
26 lines (24 loc) · 840 Bytes
/
index.js
File metadata and controls
26 lines (24 loc) · 840 Bytes
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
var button = document.querySelector(".button");
var input = document.querySelector(".inputValue");
var names = document.querySelector(".names");
var des = document.querySelector(".des");
var temp = document.querySelector(".temp");
button.addEventListener("click", () => {
fetch(
"https://api.openweathermap.org/data/2.5/weather?q=" +
input.value +
"&appid=6f9d204a9f397da7a86985eca08c6020"
)
.then((response) => response.json())
.then((data) => {
console.log(data);
var nameValue = data["name"];
var tempValue = data["main"]["temp"];
var desValue = data["weather"][0]["description"];
var celsius = tempValue - 273.15;
names.innerHTML = nameValue;
temp.innerHTML = celsius.toPrecision(2);
des.innerHTML = desValue;
})
.catch((err) => alert("issue"));
});