-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.js
32 lines (25 loc) · 1.03 KB
/
main.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
//server api data
const apiKey = '8eb6e8a7d5ae405db06145440211909'
const baseURL = `http://api.weatherapi.com/v1/current.json?key=${apiKey}&q=`
//get user location preference
const button = document.querySelector(".send-location")
button.addEventListener("click",(event)=>{
event.preventDefault()
let location = document.querySelector(".location").value
getWeatherData (location)
})
//get api data from user location
async function getWeatherData (location) {
let result = await fetch (`${baseURL}${location}`)
.then(result => result.json())
console.log(result)
//format report to insert html
let statusHtml = `<h1>${result.current.temp_c} °C</h1>
<h1>${result.current.condition.text}</h1>
<h2>${result.current.wind_kph} km/h</h2>
<h2>${result.current.humidity} %</h2>
<h2>${result.current.pressure_mb} hPa</h2>
<h4>${result.location.name}, ${result.location.tz_id}</h4>`
let statusToHTML = document.querySelector(".status")
statusToHTML.innerHTML = statusHtml
}