File tree Expand file tree Collapse file tree 3 files changed +19
-2
lines changed Expand file tree Collapse file tree 3 files changed +19
-2
lines changed Original file line number Diff line number Diff line change @@ -33,7 +33,8 @@ <h5>Write the location to get the weather</h5>
3333 < form id ="searching " action ="javascript:void(0); ">
3434 < input class ="form-class w-50 " type ="text " id ="search " placeholder ="Input your search keyword " name ="search ">
3535 < br > < br >
36- < input type ="submit " class ="btn btn-warning " id ="submit " value ="Search! ">
36+ < input type ="submit " class ="btn btn-warning " id ="submit " value ="Weather ">
37+ < input type ="submit " class ="btn btn-warning " id ="submit2 " value ="Forecast! ">
3738 </ form >
3839 </ div >
3940 </ main >
Original file line number Diff line number Diff line change @@ -10,6 +10,9 @@ let help = helpers();
1010const submit = document . getElementById ( 'submit' ) ;
1111submit . addEventListener ( 'click' , event . getSearch . bind ( this , 'search' ) ) ;
1212
13+ const submit2 = document . getElementById ( 'submit2' ) ;
14+ submit2 . addEventListener ( 'click' , event . getForecast ) ;
15+
1316const search2 = document . getElementById ( 'search2' ) ;
1417search2 . addEventListener ( 'click' , event . getSearch . bind ( this , 'searchBar' ) ) ;
1518
Original file line number Diff line number Diff line change @@ -18,13 +18,26 @@ const events = function () {
1818 }
1919 } ;
2020
21+ async function getForecast ( searchBar ) {
22+ try {
23+ const value = ( document . getElementById ( 'search' ) . value ) . toLowerCase ( ) ;
24+ const url = `https://api.openweathermap.org/data/2.5/forecast?q=${ value } &units=metric&appid=903507f17d707fecd352d38301efba77` ;
25+ const response = await fetch ( url , { mode : 'cors' } ) ;
26+ const cityData = await response . json ( ) ;
27+ showFlow ( cityData ) ;
28+ } catch ( error ) {
29+ console . error ( 'Error:' , error ) ;
30+ alert ( 'Could not find the location' ) ;
31+ }
32+ } ;
33+
2134 function showFlow ( data ) {
2235 dom ( ) . fillCard ( data ) ;
2336 dom ( ) . imageSwitch ( data ) ;
2437 dom ( ) . show ( ) ;
2538 } ;
2639
27- return { getSearch, showFlow, }
40+ return { getSearch, showFlow, getForecast , }
2841} ;
2942
3043export { events }
You can’t perform that action at this time.
0 commit comments