-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathscript.js
57 lines (41 loc) · 1.42 KB
/
script.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
54
55
56
57
const url = "https://api.nasa.gov/planetary/apod?api_key=9qtqguVABT4wE6YB2RmkoQvcwA8828bzibbhppdS&count=54" //substituya la DEMO_KEY por tu llave personal(API Key)
async function listaImagenes() {
try{
let fetchImagen = await fetch(url)
let datosImagenes = await fetchImagen.json()
console.log(datosImagenes)
const card = document.querySelector("[data-ul]")
datosImagenes.forEach( elemento => {
const contenido =
`<li class="card">
<img class="card__image" src="${elemento.url}" alt="imagen">
<h3 class="card__title">${elemento.title}</h3>
</li>
`
card.innerHTML = card.innerHTML + contenido
})
}
catch(error){
console.log(error)
}
}
listaImagenes()
// then y catch
/* function listaImagenes(){
fetch(url)
.then( response => response.json())
.then( datosImagenes => {
console.log(datosImagenes)
const card = document.querySelector("[data-ul]")
datosImagenes.forEach( elemento => {
const contenido =`<li class="card">
<img class="card__image" src="${elemento.url}" alt="imagen">
<h3 class="card__title">${elemento.title}</h3>
</li>
`
card.innerHTML = card.innerHTML + contenido
})
})
.catch( error => console.log(error))
}
listaImagenes() */