File tree Expand file tree Collapse file tree 2 files changed +23
-1
lines changed
Expand file tree Collapse file tree 2 files changed +23
-1
lines changed Original file line number Diff line number Diff line change 1+ var button = document . querySelector ( '.button' )
2+ var inputValue = document . querySelector ( '.inputValue' )
3+ var desc = document . querySelector ( '.desc' ) ;
4+ var name = document . querySelector ( '.name' ) ;
5+ var temp = document . querySelector ( '.temp' ) ;
6+
7+ button . addEventListener ( 'click' , function ( ) {
8+ fetch ( 'https://api.openweathermap.org/data/2.5/weather?q=' + inputValue . value + '&appid=c983aed69b497603ff80d72814dbadd1' )
9+ . then ( response => response . json ( ) )
10+ . then ( data => {
11+ var nameValue = data [ 'name' ] ;
12+ var tempValue = data [ 'main' ] [ 'temp' ] ;
13+ var descValue = data [ 'weather' ] [ 0 ] [ 'description' ] ;
14+
15+ name . innerHTML = nameValue ;
16+ temp . innerHTML = tempValue ;
17+ desc . innerHTML = descValue ;
18+ } )
19+
20+
21+ . catch ( err => alert ( "Wrong city name!" ) )
22+ } )
Original file line number Diff line number Diff line change 99< body >
1010 < div class ="input ">
1111 < input type ="text " class ="inputValue " placeholder ="Enter a city ">
12- < input type ="submit " value ="submit ">
12+ < input type ="submit " value ="submit " class =" button " >
1313 </ div >
1414
1515 < div class ="display ">
You can’t perform that action at this time.
0 commit comments