-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathscript.js
28 lines (24 loc) · 906 Bytes
/
script.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
window.onload = function() {
var lat;
var long;
var temperatureValue = document.querySelector("#temperature-value");
var locationTimezone = document.querySelector("#location-timezone");
if(navigator.geolocation){
navigator.geolocation.getCurrentPosition(position => {
lat = position.coords.latitude;
long = position.coords.longitude;
var api = `https://fcc-weather-api.glitch.me/api/current?lat=${lat}&lon=${long}`;
fetch(api)
.then(response => {
return response.json();
})
.then(data => {
console.log(data);
var temp = data.main['temp'];
var location = data.name;
temperatureValue.innerHTML = temp + '°C';
locationTimezone.textContent = location;
})
})
}
}