mirror of
https://github.com/sergeyyarkov/openweather-api.git
synced 2026-10-11 02:18:51 +03:00
added проверка на пустую строку
This commit is contained in:
parent
ebe715640d
commit
01f8197b22
18
js/app.js
18
js/app.js
@ -1,9 +1,11 @@
|
||||
'use strict';
|
||||
function weatherInfo() {
|
||||
document.querySelector('#search-btn').onclick = () => {
|
||||
// запрос
|
||||
const searchValue = document.querySelector('#search-area').value;
|
||||
const request = `http://api.openweathermap.org/data/2.5/weather?q=${searchValue}&appid=32dda4a23cf5093afca2f2f086c16833`;
|
||||
|
||||
if (searchValue.trim() != '') {
|
||||
// обработчик
|
||||
function showData(data) {
|
||||
const weatherCard = document.querySelector('.weather-card'),
|
||||
@ -18,19 +20,19 @@ function weatherInfo() {
|
||||
// перевод слов на русский
|
||||
switch (data.weather[0].description) {
|
||||
case 'light rain':
|
||||
data.weather[0].description = 'легкий дождь'
|
||||
data.weather[0].description = 'легкий дождь';
|
||||
break;
|
||||
case 'clear sky':
|
||||
data.weather[0].description = 'чистое небо'
|
||||
data.weather[0].description = 'чистое небо';
|
||||
break;
|
||||
case 'scattered clouds':
|
||||
data.weather[0].description = 'рассеянные облака'
|
||||
data.weather[0].description = 'рассеянные облака';
|
||||
break;
|
||||
case 'broken clouds':
|
||||
data.weather[0].description = 'облачность'
|
||||
data.weather[0].description = 'облачность';
|
||||
break;
|
||||
case 'haze':
|
||||
data.weather[0].description = 'туман'
|
||||
data.weather[0].description = 'туман';
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
@ -56,7 +58,11 @@ function weatherInfo() {
|
||||
})
|
||||
.catch(function () {
|
||||
alert('Город не найден!');
|
||||
})
|
||||
});
|
||||
} else {
|
||||
alert('Введите город!');
|
||||
}
|
||||
};
|
||||
|
||||
}
|
||||
weatherInfo();
|
||||
Loading…
x
Reference in New Issue
Block a user