Skip to content
Permalink
Browse files

added function to display images using DOM manipulation

  • Loading branch information...
equk committed Jul 31, 2018
1 parent 3b4106e commit cdaf1410aaae60bfb56028cd8fa0a676eb1f438c
Showing with 15 additions and 1 deletion.
  1. +15 −1 public/js/app.js
@@ -10,14 +10,28 @@ function formSubmitted(event) {
event.preventDefault();
let searchTerm = input.value;

searchStart();
search(searchTerm)
.then(displayImages)
}

function searchStart() {
imageSection.innerHTML = '';
}

function search(searchTerm) {
let url = `${API_URL}&query=${searchTerm}`;
return fetch(url)
.then(response => response.json())
.then(result => {
console.log(result.results);
return result.results;
});
}

function displayImages(images) {
images.forEach(image => {
let imageElement = document.createElement('img');
imageElement.src = image.urls.regular;
imageSection.appendChild(imageElement);
});
}

0 comments on commit cdaf141

Please sign in to comment.
You can’t perform that action at this time.