File tree Expand file tree Collapse file tree 2 files changed +20
-2
lines changed
Expand file tree Collapse file tree 2 files changed +20
-2
lines changed Original file line number Diff line number Diff line change @@ -22,6 +22,7 @@ <h4 class="js-greetings greetings"></h4>
2222 </ form >
2323 < ul class ="js-toDoList ">
2424 </ ul >
25+ < span class ="js-weather "> </ span >
2526 < script src ="clock.js "> </ script >
2627 < script src ="gretting.js "> </ script >
2728 < script src ="todo.js "> </ script >
Original file line number Diff line number Diff line change 1+ const weather = document . querySelector ( ".js-weather" ) ;
2+
13const API_KEY = 'cfb3b9813c0b7484f3e348497ab68b28' ;
24const COORDS = 'coords' ;
35
6+ function getWeather ( lat , lon ) {
7+ fetch ( `https://api.openweathermap.org/data/2.5/weather?lat=${ lat } &lon=${ lon } &appid=${ API_KEY } &units=metric`
8+ ) . then ( function ( response ) {
9+ return response . json ( ) ;
10+ } ) . then ( function ( json ) {
11+ const temperature = json . main . temp ;
12+ const place = json . name ;
13+
14+ weather . innerText = `${ temperature } @ ${ place } ` ;
15+ } ) ;
16+ }
17+
418function saveCoords ( coordsObj ) {
519 localStorage . setItem ( COORDS , JSON . stringify ( coordsObj ) ) ;
620}
@@ -13,6 +27,7 @@ function handleGeoSuccess(position) {
1327 longitude,
1428 } ;
1529 saveCoords ( coordsObj ) ;
30+ getWeather ( latitude , longitude ) ;
1631}
1732
1833function handleGeoError ( ) {
@@ -28,9 +43,11 @@ function loadCoords() {
2843 const loadedCoords = localStorage . getItem ( COORDS ) ;
2944
3045 if ( loadedCoords === null ) {
31- askForCoords ( ) ;
46+ askForCoords ( ) ;
3247 } else {
33-
48+ const parseCoords = JSON . parse ( loadedCoords ) ;
49+ getWeather ( parseCoords . latitude , parseCoords . longitude ) ;
50+ console . log ( parseCoords ) ;
3451 }
3552}
3653
You can’t perform that action at this time.
0 commit comments