-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.js
54 lines (46 loc) · 1.88 KB
/
index.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
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
let cityName
const weather = async function(){
let response = await fetch(`https://api.openweathermap.org/data/2.5/weather?q=${cityName}&APPID=4cc82568bdf18af4e44da217ca2e562a&units=metric`)
if(response.status === 200) {
const data = await response.json()
return data
}
else{
throw new Error("Unable to find")
}
}
const p = document.createElement("p")
document.getElementById("form").addEventListener("submit",(e)=>{
e.preventDefault()
cityName = document.getElementById("inputElement").value
weather(cityName).then((data)=>{
console.log(data)
if(data.main.temp >= 37){
document.getElementById("temp").textContent = `${data.main.temp}c so HOT`
}
else if(data.main.temp > 25){
document.getElementById("temp").textContent = `${data.main.temp}c HOT `
}
else if(data.main.temp > 21){
document.getElementById("temp").textContent = `${data.main.temp}c Room Temp`
}
else if(data.main.temp > 5){
document.getElementById("temp").textContent = `${data.main.temp}c Warm & Mild`
}
else if(data.main.temp > 0){
document.getElementById("temp").textContent = `${data.main.temp}c Cool`
}
else{
document.getElementById("temp").textContent = `${data.main.temp}c Very Cold`
}
document.getElementById("pressure").textContent = `${data.main.pressure}%`
document.getElementById("humidity").textContent = `${data.main.humidity}%`
document.getElementById("speed").textContent = `${ data.wind.speed} Km/h`
const time = new Date()
const timeStamp = time.getTime()
const myDate = new Date(timeStamp)
document.getElementById("time").textContent= `${myDate.getHours()}: 0${myDate.getMinutes()}`
}).catch((e)=>{
console.log(e.message)
})
})