-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathapp.js
More file actions
125 lines (94 loc) · 3.01 KB
/
app.js
File metadata and controls
125 lines (94 loc) · 3.01 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
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
let now = new Date()
let hour = now.getHours()
if(hour<10){
hour=`0${hour}`
}
let minutes = now.getMinutes()
if(minutes<10){
minutes=`0${minutes}`
}
let fullTime= (`${hour}:${minutes}`)
let showTime = document.querySelector("#time")
showTime.innerHTML=`${fullTime}`
let days = [
"Sunday",
"Monday",
"Tuesday",
"Wednesday",
"Thursday",
"Friday",
"Saturday",
];
let day = days[now.getDay()];
let showDay= document.querySelector("#weekDay")
showDay.innerHTML=`${day}`
let year=now.getFullYear()
let months = [
"Jan",
"Feb",
"March",
"Apr",
"May",
"Jun",
"Jul",
"Augu",
"Sep",
"Oct",
"Nov",
"Dec",
];
let month = months[now.getMonth()];
let numberDate=now.getDate()
let showFullDate=document.querySelector("#date")
showFullDate.innerHTML=`${numberDate}. ${month} ${year}`
function currentForecast(response){
let temperature = Math.round(response.data.main.temp)
let showTemp = document.querySelector("#celsium")
showTemp.innerHTML=`${temperature}°C`
let headline = response.data.name
let head=document.querySelector("h1")
head.innerHTML=`${headline}`
let description = response.data.weather[0].main
let showDescription=document.querySelector("#description")
showDescription.innerHTML=`${description}`
let humidity=response.data.main.humidity
let showHumidity=document.querySelector("#humidity")
showHumidity.innerHTML=` ${humidity}`
let wind= Math.round(response.data.wind.speed)
let showWind=document.querySelector("#wind")
showWind.innerHTML=` ${wind}`
let country=response.data.sys.country
let showCountry=document.querySelector("#country")
showCountry.innerHTML=` ${country}`
let icon=response.data.weather[0].icon
let showIcon=document.querySelector("#icon")
showIcon.innerHTML=`<img src="http://openweathermap.org/img/w/${icon}.png"/src>`;
}
function searchCity(city){
let apiUrl = `${mainUpi}q=${city}&appid=${apiKey}&units=${unit}`;
axios.get(apiUrl).then(currentForecast);
}
function showCity(event){
event.preventDefault()
let input= document.querySelector("#searchCity")
let city = input.value
searchCity(city);
}
let form=document.querySelector("#enterCity")
form.addEventListener("submit",showCity)
function handlePosition(position){
let lat = position.coords.latitude
let lon=position.coords.longitude
let apiUrlLocation = `${mainUpi}lat=${lat}&lon=${lon}&appid=${apiKey}&units=${unit}`;
axios.get(apiUrlLocation).then(currentForecast)
}
function currentLocation(event){
event.preventDefault()
navigator.geolocation.getCurrentPosition(handlePosition)
}
let button=document.querySelector("#location")
button.addEventListener("click",currentLocation)
let unit = "metric";
let apiKey = "78fc98c085614cc01c7a0b894f6604c6";
let mainUpi = "https://api.openweathermap.org/data/2.5/weather?"
searchCity("Prague")