diff --git a/js/index.html b/js/index.html
index 317ff26..b7da253 100644
--- a/js/index.html
+++ b/js/index.html
@@ -26,6 +26,10 @@
+
+
+
+
diff --git a/js/js/weather.js b/js/js/weather.js
index ee3ee44..b2ce01a 100644
--- a/js/js/weather.js
+++ b/js/js/weather.js
@@ -1,10 +1,19 @@
+const weather = document.querySelector("#weather span:first-child");
+const city = document.querySelector("#weather span:last-child");
+const API_KEY = "241051bf13976dd3ddf8b8d9f247255e";
+
function onGeoOk(position) {
const lat = position.coords.latitude;
- const lng = position.coords.longitude;
- console.log("You live in", lat, lng);
+ const lon = position.coords.longitude;
+ const url = `https://api.openweathermap.org/data/2.5/weather?lat=${lat}&lon=${lon}&appid=${API_KEY}&units=metric`;
+ fetch(url)
+ .then((response) => response.json())
+ .then((data) => {
+ city.innerText = data.name;
+ weather.innerText = `${data.weather[0].main} / ${data.main.temp}`;
+ });
}
function onGeoError() {
alert("Can't find you. No weather for you.");
}
-
navigator.geolocation.getCurrentPosition(onGeoOk, onGeoError);