diff --git a/assets/src/index.js b/assets/src/index.js new file mode 100644 index 0000000..43421f7 --- /dev/null +++ b/assets/src/index.js @@ -0,0 +1,43 @@ +function submitHandler(event){ + event.preventDefault(); + + const searchBar = document.querySelector("#search-tf"); + const city = searchBar.value; + + fetch(`http://api.openweathermap.org/data/2.5/weather?q=${city}&APPID=98c20025c94e54346cce38d0c653d966`) + .then(function(response){ + return response.json(); + }).then(function(jsonData){ + const weatherDescription = jsonData.weather[0].description; + + return fetch(`https://api.unsplash.com/search/photos?query=${weatherDescription}&client_id=f3dc3b6bb3462a90c7969a62d83c8e3dd552b928cc31041850388e8616e977a6`) + + + }).then(function(response){ + return response.json(); + }).then(function(data){ + images = data.results.map(image => + `` + ) + thumbs.innerHTML = images; + console.log(data); + + }).catch(function(error){ + alert('I don\'t work'); + }); +} + +const getSearch = document.querySelector("#search"); + +const figure = document.querySelector('#photo'); + +const thumbs = document.querySelector('#thumbs'); + +let images; +getSearch.addEventListener("submit", submitHandler); + +function clickHandler(event){ + figure.innerHTML= ``; +} + +thumbs.addEventListener("click", clickHandler); diff --git a/index.html b/index.html index 664d55a..c0e7bf8 100644 --- a/index.html +++ b/index.html @@ -38,12 +38,14 @@

+ - \ No newline at end of file +