diff --git a/.vscode/settings.json b/.vscode/settings.json new file mode 100644 index 0000000..6f3a291 --- /dev/null +++ b/.vscode/settings.json @@ -0,0 +1,3 @@ +{ + "liveServer.settings.port": 5501 +} \ No newline at end of file diff --git a/app.js b/app.js index eb3d2f1..27964e4 100644 --- a/app.js +++ b/app.js @@ -8,6 +8,14 @@ const descElement = document.querySelector(".temperature-description p"); const locationElement = document.querySelector(".location p"); const notificationElement = document.querySelector(".notification"); + +var searchButton = document.querySelector('.search-btn'); +var cityInput = document.querySelector('.city-input'); +var currentCity = document.getElementById('city-name'); + + + + // App data const weather = {}; @@ -63,6 +71,34 @@ function getWeather(latitude, longitude){ }); } + + + + + var getCityCoordinates = function() { + var cityName = cityInput.value.trim(); + if (!cityName) return; + var queryURL = "http://api.openweathermap.org/geo/1.0/direct?q=" + cityName + "&limit=1&appid=" + APIKey; + + + fetch(queryURL) + .then(function(response) { + return response.json(); + }) + .then(function(data){ + // console.log(data); + if(!data.length) return alert("No coordinates found for " + cityName + "!"); + var { name, lat, lon} = data[0]; + get5DayWeather(name, lat, lon); + currentCity.innerHTML = data[0].name + getCurrentWeather(name, lat, lon); + }).catch(function() { + alert("Can not get corridnates!") + }); + } + searchButton.addEventListener('click', getCityCoordinates); + + // DISPLAY WEATHER TO UI function displayWeather(){ iconElement.innerHTML = ``; @@ -76,19 +112,14 @@ function celsiusToFahrenheit(temperature){ return (temperature * 9/5) + 32; } -// WHEN THE USER CLICKS ON THE TEMPERATURE ELEMENET -tempElement.addEventListener("click", function(){ - if(weather.temperature.value === undefined) return; - - if(weather.temperature.unit == "celsius"){ - let fahrenheit = celsiusToFahrenheit(weather.temperature.value); + +function Tempretureconverter(){ + let fahrenheit = celsiusToFahrenheit(weather.temperature.value); fahrenheit = Math.floor(fahrenheit); tempElement.innerHTML = `${fahrenheit}°F`; - weather.temperature.unit = "fahrenheit"; - }else{ - tempElement.innerHTML = `${weather.temperature.value}°C`; - weather.temperature.unit = "celsius" - } -}); + +} + + diff --git a/index.html b/index.html index f9a9f82..1fdf600 100644 --- a/index.html +++ b/index.html @@ -9,26 +9,33 @@
-
-

Weather

-
-
-
-
- -
-
-

- °C

+
+
+

Weather

-
-

-

-
-
-

-

+ +
+
+ +
+
+

- °C

+
+
+

-

+
+
+

-

+
+ +
-
+ + + + diff --git a/package-lock.json b/package-lock.json new file mode 100644 index 0000000..6165900 --- /dev/null +++ b/package-lock.json @@ -0,0 +1,6 @@ +{ + "name": "Weather-App-JavaScript-1", + "lockfileVersion": 3, + "requires": true, + "packages": {} +} diff --git a/package.json b/package.json new file mode 100644 index 0000000..0084c11 --- /dev/null +++ b/package.json @@ -0,0 +1,11 @@ +{ + "name": "c", + "version": "1.0.0", + "description": "Hi Everyone!", + "main": "app.js", + "scripts": { + "test": "echo \"Error: no test specified\" && exit 1" + }, + "author": "", + "license": "ISC" +} diff --git a/style.css b/style.css index 4190124..45acab0 100644 --- a/style.css +++ b/style.css @@ -3,14 +3,16 @@ } body{ - background-color: #293251; + background-color:skyblue; + margin: auto; } .container{ - width: 300px; + width: 800px; background-color: #FFF; - display: block; + /* display: block; */ + margin: 0 auto; border-radius: 10px; @@ -21,6 +23,7 @@ body{ width: 300px; height: 50px; border-radius: 10px 10px 0 0; + margin: auto; } .app-title p{ @@ -47,6 +50,7 @@ body{ .weather-container{ width: 300px; height: 260px; + margin: auto; background-color: #F4F9FF; } @@ -73,7 +77,20 @@ body{ text-align: center; cursor: pointer; } - +.ctofbutton{ + margin: 10px auto; + display: flex; + width: 200px; + height: 40px; + align-items: center; + justify-content: center; + font-size: 16px; + background-color: lightgreen; + border-style: none; +} +.ctofbutton:hover{ + background-color:lightseagreen; +} .temperature-value p:hover{ }