-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.js
43 lines (37 loc) · 1 KB
/
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
32
33
34
35
36
37
38
39
40
41
42
'use strict';
function getDogImage(inputNumber) {
console.log(inputNumber);
fetch(`https://dog.ceo/api/breeds/image/random/${inputNumber}`)
.then(response => response.json())
.then(responseJson =>
displayResults(responseJson))
.catch(error => alert(error));
}
function displayResults(responseJson) {
console.log(responseJson);
let pictures = responseJson.message;
let img_list = document.getElementById("img-list");
img_list.innerHTML = '';
for (let i = 0; i < pictures.length; i++ ) {
var li = document.createElement('LI');
var img = document.createElement('IMG');
img.src = pictures[i];
li.appendChild(img);
img_list.append(li);
}
}
function watchForm() {
$('form').submit(event => {
event.preventDefault();
const inputNumber = $('#input-number').val();
if (!inputNumber) {
getDogImage("3");
} else {
getDogImage(inputNumber);
}
});
}
$(function() {
console.log('App loaded! Waiting for submit!');
watchForm();
});