-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathscript.js
More file actions
65 lines (56 loc) · 2.22 KB
/
Copy pathscript.js
File metadata and controls
65 lines (56 loc) · 2.22 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
// const cityName = document.querySelector('.js-place-name');
// const search =document.getElementById('.js-search');
// const apiKey ="265c1dddf084100b37a9a6c7dabebf33";
// const apiUrl = "https://api.openweathermap.org/data/2.5/weather?units=metric&q=";
// const weatherimage=document.querySelector('.js-weather-image');
// const temperature = document.querySelector('.js-temp');
// const place = document.querySelector('.js-place');
// const humidity = document.querySelector('.js-humidity-percentage');
// const wind =document.querySelector('.js-wind')
// //fetching
// async function checkWeather(city) {
// const response = await fetch(apiUrl + city + `&appid=${apiKey}`);
// var data = await response.json();
// place.innerText = data.name;
// temperature.innerText = data.main.temp;
// humidity.innerText = data.main.humidity;
// wind.innerText = data.wind.speed;
// console.log(data);
// }
// checkWeather(cityName);
// function searchForWeather (){
// search.addEventListener('click' ,() =>{
// checkWeather(cityName.value);
// });
// }
// searchForWeather();
const cityName = document.querySelector('.js-place-name');
const search = document.querySelector('.js-search');
const weatherImage = document.querySelector('.js-weather-image');
const temperature = document.querySelector('.js-temp');
const place = document.querySelector('.js-place');
const humidity = document.querySelector('.js-humidity-percentage');
const wind = document.querySelector('.js-wind');
const apiKey = "265c1dddf084100b37a9a6c7dabebf33";
const apiUrl = "https://api.openweathermap.org/data/2.5/weather?units=metric&q=";
// Fetch Weather
async function checkWeather(city) {
const response = await fetch(apiUrl + city + `&appid=${apiKey}`);
const data = await response.json();
console.log(data);
place.innerText = data.name;
temperature.innerText = data.main.temp + "°C";
humidity.innerText = data.main.humidity + "%";
wind.innerText = data.wind.speed + " km/h";
cityName.value ="";
}
// Search Button
search.addEventListener('click', () => {
checkWeather(cityName.value);
});
const clickSearch = document.querySelector('.js-place-name');
clickSearch.addEventListener('keydown',(event) =>{
if(event.key === "Enter"){
checkWeather(cityName.value);;
}
});