Skip to content

Commit 67049b3

Browse files
committed
#21 - JavaScript
1 parent fa9418d commit 67049b3

File tree

1 file changed

+52
-0
lines changed

1 file changed

+52
-0
lines changed
Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
// ** EJERCICIO
2+
3+
const readline = require('node:readline');
4+
5+
function numeroAnos(callback) {
6+
const rl = readline.createInterface({
7+
input: process.stdin,
8+
output: process.stdout
9+
});
10+
11+
rl.question('Por favor ingresa tu edad: ', (edad) => {
12+
callback(edad);
13+
rl.close();
14+
});
15+
}
16+
17+
function cuandoNaciste(edad) {
18+
let actual = new Date();
19+
let anoNacimiento = actual.getFullYear() - edad;
20+
console.log('Naciste en el: ' + anoNacimiento + ' o ' + (anoNacimiento - 1));
21+
}
22+
23+
// numeroAnos(cuandoNaciste)
24+
25+
26+
// ** DIFICULTAD EXTRA ** ------------------------------------------------------------------------------------------------------------------------------------------------
27+
28+
function procesaPedido(nombrePlato, callbackConfirmacion, callbackListo, callbackEntrega) {
29+
console.log(`Iniciando pedido para ${nombrePlato}`);
30+
setTimeout(() => {
31+
callbackConfirmacion(nombrePlato);
32+
setTimeout(() => {
33+
callbackListo(nombrePlato);
34+
setTimeout(() => {
35+
callbackEntrega(nombrePlato);
36+
}, Math.random() * 9000 + 1000);
37+
}, Math.random() * 9000 + 1000);
38+
}, Math.random() * 9000 + 1000);
39+
}
40+
41+
procesaPedido(
42+
'Pizza Margarita',
43+
(plato) => {
44+
console.log(`Confirmación recibida para ${plato}.`);
45+
},
46+
(plato) => {
47+
console.log(`${plato} está listo para ser entregado.`);
48+
},
49+
(plato) => {
50+
console.log(`${plato} ha sido entregado al cliente.`);
51+
}
52+
);

0 commit comments

Comments
 (0)