-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.js
42 lines (37 loc) · 1.37 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
const perroActualELement = document.getElementById("perroActual");
const API = "https://dog.ceo/api/breeds/image/random";
const spinner = document.getElementById("spinner");
const contenedorLikePerros = document.getElementById("contenedorLikePerros");
const contenedorDisLikePerros = document.getElementById(
"contenedorDisLikePerros"
);
contenedorLikePerros.classList.add("escondido");
contenedorLikePerros.classList.add("escondido");
perroActualELement.addEventListener("load", () => {
perroActualELement.classList.toggle("escondido", false);
spinner.classList.toggle("escondido", true);
});
async function nuevoPerro() {
spinner.classList.toggle("escondido", false);
perroActualELement.classList.toggle("escondido", true);
const res = await fetch(API);
const resJson = await res.json();
console.log(resJson);
perroActualELement.src = resJson.message;
perroActualELement.classList.toggle("escondido", false);
}
function rankingPerros(ranking) {
console.log(ranking);
const nuevaImagen = document.createElement("img");
nuevaImagen.src = perroActualELement.src;
if (ranking === "+") {
contenedorLikePerros.appendChild(nuevaImagen);
} else {
contenedorDisLikePerros.appendChild(nuevaImagen);
}
contenedorDisLikePerros.classList.toggle("escondido", false);
contenedorLikePerros.classList.toggle("escondido", false);
nuevoPerro();
}
//Ejecucion
nuevoPerro();