-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathscripts.js
More file actions
26 lines (17 loc) · 904 Bytes
/
scripts.js
File metadata and controls
26 lines (17 loc) · 904 Bytes
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
const key = "1e6dc3bb19083c3f24ae661f2d3b922e"
function colocarDadosNaTela(dados){
console.log(dados)
document.querySelector(".city").innerHTML = "Tempo em " + dados.name
document.querySelector(".temp").innerHTML = Math.floor(dados.main.temp) + " °C "
document.querySelector(".text-prevision").innerHTML = dados.weather[0].description
document.querySelector(".humidity").innerHTML = "Umidade: " + dados.main.humidity + "%"
document.querySelector(".img-prevision").src = `https://openweathermap.org/img/wn/${dados.weather[0].icon}.png`
}
async function buscarCidade(cidade){
const dados = await fetch(`https://api.openweathermap.org/data/2.5/weather?q=${cidade}&appid=${key}&lang=pt_br&units=metric`).then(resposta => resposta.json())
colocarDadosNaTela(dados)
}
function cliqueiNoBotao(){
const cidade = document.querySelector(".input-city").value
buscarCidade(cidade)
}