-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.js
executable file
·31 lines (26 loc) · 967 Bytes
/
main.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
const RandomImage = {
container: document.querySelector('.container'),
input: document.querySelector('#rows'),
unsplashURL: 'https://source.unsplash.com/random/',
rows: 10,
getRandomSize: () => `${RandomImage.getRandomNumber()}x${RandomImage.getRandomNumber()}`,
getRandomNumber: () => Math.floor(Math.random() * 20) + 300,
changeRowsLength() {
RandomImage.rows = RandomImage.input.value
RandomImage.container.innerHTML = ''
RandomImage.createImages()
},
createImages() {
for(let i = 0; i < RandomImage.rows * 3; i++) {
const img = document.createElement('img')
img.src = `${RandomImage.unsplashURL}${RandomImage.getRandomSize()}`
img.alt = `Image ${i + 1}`
RandomImage.container.appendChild(img)
}
},
start() {
RandomImage.input.addEventListener('keydown', event => event.key === 'Enter' ? RandomImage.changeRowsLength() : '')
RandomImage.createImages()
}
}
RandomImage.start()