forked from Code-Platoon-Assignments/API-Integration
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathapp.js
More file actions
31 lines (27 loc) · 894 Bytes
/
app.js
File metadata and controls
31 lines (27 loc) · 894 Bytes
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
const displayDuck = (imgURL) => {
console.log(imgURL)
const duckContain = document.getElementById('duck-container')
const newImg = document.createElement('img')
newImg.src = imgURL
newImg.classList.add('duck-image');
duckContain.appendChild(newImg)
}
const getDuck = async () => {
try {
const response = await fetch('https://cors-anywhere.herokuapp.com/https://random-d.uk/api/v2/random');;
const data = await response.json();
//console.log(data);
imgURL = data.url
displayDuck(imgURL)
} catch (error) {
console.log('Error: ', error);
}
};
const handleSubmit = (event) => {
event.preventDefault();
let userInput = document.getElementById('input')
//console.log(userInput.value);
getDuck();
};
const myForm = document.getElementById('form');
myForm.addEventListener('submit', handleSubmit);