-
Notifications
You must be signed in to change notification settings - Fork 0
/
app.js
53 lines (48 loc) · 2 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
53
function fetchData() {
fetch("https://5e5932cd7777050014463360.mockapi.io/cats")
.then(response => {
if(!response.ok) {
throw Error("Error!");
}
return response.json();
})
.then(data => {
const html = data.map(cat => {
return `
<div class="cat">
<div class="img__parent">
<img class="cat__img" src="${cat.image}" alt="${cat.name}" />
</div>
<div class="cat__info">
<h2>${cat.name}</h2>
<p class="description">${cat.description}</p>
</div>
<div class="button__parent">
<button onClick="adopt()" class="take__button">TAKE ${cat.name.toUpperCase()} HOME</button>
</div>
</div>
`
}).join('');
document.querySelector('#app').innerHTML = html;
})
.catch(error => {
console.log(error);
alert('There is an error loading the data');
});
}
fetchData();
function adopt() {
var div = document.createElement('div');
div.id = 'adopt__details';
document.getElementsByTagName('body')[0].appendChild(div);
div.innerHTML += "<h2>Please enter your details</h2>";
div.innerHTML += "<div><h4 class='details__title'>Name:<h4><input/></div>";
div.innerHTML += "<div><h4 class='details__title'>Email<h4><input/></div>";
div.innerHTML += "<div><h4 class='details__title'>Phone Number<h4><input/></div>";
div.innerHTML += "<div><h4 class='details__title'>Address<h4><input/></div>";
div.innerHTML += "<div><button onClick='hide()' class='submit__button'>Submit Details</button></div>";
}
function hide() {
var elm = document.getElementById('adopt__details');
elm.parentNode.removeChild(elm);
}