-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.js
31 lines (24 loc) · 804 Bytes
/
index.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
function appendImageElement (keyword, index) {
const imageElement = document.createElement('img')
imageElement.src = `https://source.unsplash.com/400x225/?${keyword}&sig=${index}`
const galleryElement = document.querySelector('.gallery')
galleryElement.appendChild(imageElement)
}
function removePhoto() {
const galleryElement = document.querySelector('.gallery')
galleryElement.innerHTML = ''
}
function searchPhoto(event) {
const keyword = event.target.value
if (event.key === 'Enter' && keyword) {
removePhoto()
for(let i = 1; i <= 9; i++) {
appendImageElement(keyword, i)
}
}
}
function run() {
const inputElement = document.querySelector('input')
inputElement.addEventListener('keydown', searchPhoto)
}
run()