-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathweatherApp.js
44 lines (40 loc) · 1.56 KB
/
weatherApp.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
const conferfmBtn = document.querySelector("#confirm-city-button");
const cityInput = document.querySelector("#city-name-input");
const body = document.querySelector("body");
let nameOfCity = document.querySelector(".name-of-city");
let temprature = document.querySelector(".temprature");
let windSpeed = document.querySelector(".wind-speed");
let clouds = document.querySelector(".clouds");
let warningParagraph = document.querySelector(".warning-paragraph");
async function weatherApp() {
const response = await fetch(
`https://api.openweathermap.org/data/2.5/weather?q=${cityInput.value}&appid=33eb251a59e70a4762c2ce771ec0f0ec`
);
const data = await response.json();
nameOfCity.textContent += data.name;
let degreesCelcius = String.fromCodePoint(8451);
temprature.textContent += `max ${(data.main.temp_max - 273.15).toFixed(
2
)}${degreesCelcius},
min ${(data.main.temp_min - 273.15).toFixed(2)}${degreesCelcius},
and it feels like ${(data.main.feels_like - 273.15).toFixed(
2
)}${degreesCelcius}`;
windSpeed.textContent += `${data.wind.speed}`;
clouds.textContent += `${data.weather[0].description}`;
}
conferfmBtn.addEventListener("click", () => {
if (cityInput.value == "") {
warningParagraph.innerHTML = "Please enter a city name";
} else {
weatherApp();
cityInput.value = "";
}
});
cityInput.addEventListener("click", () => {
clouds.innerHTML = "Clouds status: ";
nameOfCity.innerHTML = "Location: ";
warningParagraph.innerHTML = "";
windSpeed.innerHTML = "Wind speed: ";
temprature.innerHTML = "Temprature: ";
});