-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathscript.js
More file actions
34 lines (31 loc) · 1.35 KB
/
script.js
File metadata and controls
34 lines (31 loc) · 1.35 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
let city = ''
let input = document.querySelector('#location')
let cityName = document.querySelector('#cityName')
let countryName = document.querySelector('#countryName')
let temp = document.querySelector('#temperature')
let condition = document.querySelector('#condition')
let icon = document.querySelector('#weather-icon')
let response;
let data;
async function London() {
response = await fetch(`https://api.weatherapi.com/v1/current.json?key=704e4be1ec21428ab30100713252108&q=London`)
data = await response.json();
cityName.innerHTML = data.location.name
countryName.innerHTML = data.location.country
temp.innerHTML = data.current.temp_c + ' °C'
condition.innerHTML = data.current.condition.text
icon.setAttribute('src' , data.current.condition.icon)
}
London()
input.addEventListener('keydown' , async (e)=>{
if(e.key == 'Enter'){
city = input.value;
response = await fetch(`https://api.weatherapi.com/v1/current.json?key=704e4be1ec21428ab30100713252108&q=${city}`)
data = await response.json();
cityName.innerHTML = data.location.name
countryName.innerHTML = data.location.country
temp.innerHTML = data.current.temp_c + ' °C'
condition.innerHTML = data.current.condition.text
icon.setAttribute('src' , data.current.condition.icon)
}
})