44 < meta charset ="UTF-8 ">
55 < meta http-equiv ="X-UA-Compatible " content ="IE=edge ">
66 < meta name ="viewport " content ="width=device-width, initial-scale=1.0 ">
7- < title > Document</ title >
7+ < link rel ="stylesheet " href ="style.css ">
8+ <!-- link fonts robot api-->
9+ < link href ="https://fonts.googleapis.com/css2?family=Roboto:wght@300;400;500;700&display=swap " rel ="stylesheet ">
10+ < title > Weather info</ title >
811</ head >
912< body >
10-
13+ < div class ="container ">
14+ < div class ="container-data ">
15+ < input type ="text " id ="city " placeholder ="Enter city name ">
16+ < input id ="get-city " type ="button " value ="Get weather info " disabled >
17+ < span id ="city-name "> </ span >
18+ < span id ="city-date "> </ span >
19+ < span id ="city-temp "> </ span >
20+ < span id ="city-weather "> </ span >
21+ < span id ="city-temp-min "> </ span >
22+ </ div >
23+ </ div >
24+ < script type ="text/javascript " src ="app.js ">
25+ </ script >
26+ < script >
27+ const title = document . getElementById ( "city-name" ) ;
28+ const button = document . getElementById ( "get-city" ) ;
29+ document . getElementById ( 'city-date' ) . innerHTML = new Date ( ) . toLocaleString ( 'en-US' , { weekday : 'long' , year : 'numeric' , month : 'long' , day : 'numeric' } ) ;
30+ document . getElementById ( 'city' ) . addEventListener ( 'keyup' , function ( ) {
31+ if ( document . getElementById ( 'city' ) . value . length > 0 ) {
32+ button . disabled = false ;
33+ } else {
34+ button . disabled = true ;
35+ }
36+ } ) ;
37+ button . addEventListener ( "click" , ( ) => {
38+ const city = document . getElementById ( "city" ) . value ;
39+ getCityData ( city )
40+ . then ( ( data ) => {
41+ if ( data . message ) {
42+ return document . getElementById ( 'city-weather' ) . innerHTML = data . message
43+ }
44+ document . getElementById ( 'city-temp' ) . innerHTML = `${ data . main . temp } °C` ;
45+ document . getElementById ( 'city-weather' ) . innerHTML = data . weather [ 0 ] . main ;
46+ document . getElementById ( 'city-temp-min' ) . innerHTML = `${ data . main . temp_min } °C / ${ data . main . temp_max } °C` ;
47+ title . innerHTML = `${ city } , ${ data . sys . country } ` ;
48+ } )
49+ . catch ( ( error ) => {
50+ alert . apply ( "City not found" ) ;
51+ } ) ;
52+ } ) ;
53+ </ script >
1154</ body >
1255</ html >
0 commit comments