-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathscript.js
More file actions
44 lines (38 loc) · 1.12 KB
/
script.js
File metadata and controls
44 lines (38 loc) · 1.12 KB
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
//P2: func asyn con url en var
async function moviesApi(){
//var con url
const url = "https://jsonplaceholder.typicode.com/photos";
//P3:metodo fetch
try{
//solicitud a la url
const resultado = await fetch(url);
//var para convertir formato json
const data = await resultado.json(); //correcion nombre
//P4: metodo each solicitado (1eros 20 titulos)
data.forEach(element => {
if (element.id <21) {
console.log(`id: ${+element.id}, título: ${element.title}`);
}
});
//atrapando el error
}catch(error){ //correción, faltaba el parametro
//imp el msj
console.log(error.message);
}
}
moviesApi();
//P5: func. retorno de promesa en 3 seg:
function retornoMensaje() {
return new Promise ((resolve, reject) => {
setTimeout(() => {
resolve("Información Enviada");
}, 3000);
});
}
//P6: func asyn
async function mensajePromesa(){
//almaceno la promesa:
const resultado = await retornoMensaje();
console.log(resultado);
}
mensajePromesa();