-
Notifications
You must be signed in to change notification settings - Fork 0
/
scripts.js
31 lines (24 loc) · 941 Bytes
/
scripts.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
let chave = "b302484a99e82fec0dc0214b5bbebcd2"
function colocarNaTela(dados){
console.log(dados)
document.querySelector(".cidade").innerHTML = "Tempo em " + dados.name
document.querySelector(".temp").innerHTML = Math.floor(dados.main.temp) + "°C"
document.querySelector(".descricao").innerHTML = dados.weather[0].description
document.querySelector(".icone").src = "https://openweathermap.org/img/wn/" + dados.weather[0].icon + ".png"
document.querySelector(".umidade").innerHTML = "Umidade: " + dados.main.humidity
}
async function buscarCidade(cidade){
let dados = await fetch("https://api.openweathermap.org/data/2.5/weather?q=" +
cidade +
"&appid=" +
chave +
"&lang=pt_br" +
"&units=metric"
)
.then(resposta => resposta.json())
colocarNaTela(dados)
}
function cliqueiNoBotao(){
let cidade = document.querySelector(".input-cidade").value
buscarCidade(cidade)
}