-
Notifications
You must be signed in to change notification settings - Fork 0
/
app.js
53 lines (45 loc) · 1.4 KB
/
app.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
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
const template_card = document.getElementById('template').content
const fragment = document.createDocumentFragment()
const main = document.getElementById('main')
const btn_one = document.getElementById('btn_one')
const btn_two = document.getElementById('btn_two')
const btn_three = document.getElementById('btn_three')
const btn_four = document.getElementById('btn-four')
const input = document.getElementById('input')
let amount;
btn_one.addEventListener('click', function() {
amount=btn_one.textContent
conection(amount)
})
btn_two.addEventListener('click', function() {
amount=btn_two.textContent
conection(amount)
})
btn_three.addEventListener('click', function() {
amount=btn_three.textContent
conection(amount)
})
btn_four.addEventListener('click', function() {
amount=btn_four.textContent
conection(amount)
})
input.addEventListener('keydown', (e) => {
if (e.key === 'Enter') {
amount = input.value
conection(amount)
}
})
function renderCard(image) {
let clone = document.importNode(template_card, true)
clone.querySelector('#img').src = image
fragment.appendChild(clone)
main.appendChild(fragment)
}
function conection(index) {
for (let i = 0; i < index ; i++) {
fetch("https://dog.ceo/api/breeds/image/random")
.then(response => response.json())
.then(data => renderCard(data.message));
}
main.innerHTML=""
}