-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathscript.js
More file actions
45 lines (32 loc) · 1.6 KB
/
script.js
File metadata and controls
45 lines (32 loc) · 1.6 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
let weather= {
apiKey: '89e8665ccbea04476b6dd1e50c6a80fc',
fetchweather: function (city){
fetch(`http://api.openweathermap.org/data/2.5/weather?q=${city}&units=metric&appid=89e8665ccbea04476b6dd1e50c6a80fc`)
.then((response)=> response.json())
.then((data) => this.displayWeather(data));
},
displayWeather: function(data){
const {name} = data
const { icon , description} = data.weather[0]
const {temp, humidity} = data.main
const {speed } = data.wind
// console.log(name, description, icon, temp, humidity, speed);
// console.log('icon = ', icon);
let imgurl = `https://source.unsplash.com/1600x900/?${name}`
document.querySelector('.city').innerHTML = `<h2> Weather in ${name} </h2> `
document.querySelector('.temp').innerHTML = `<h1>${temp}ºC</h1>`
document.querySelector('.weather-type').innerText = description
document.querySelector('.icon').src = `https://openweathermap.org/img/wn/${icon}@2x.png`
document.querySelector('.humid').innerText = 'Humidity: ' + humidity + '%'
document.querySelector('.wind').innerText = 'Wind Speed: '+ speed + ' Kmph'
document.querySelector('.weather').classList.remove('loading');
// document.body.style.backgroundImage = `url(${imgurl})`
},
search: function(){
this.fetchweather(document.querySelector('.search-bar').value)
}
}
document.querySelector('.search-btn').addEventListener('click', function (){
weather.search()
})
// Enter key event pending