File tree Expand file tree Collapse file tree 1 file changed +52
-0
lines changed
Roadmap/21 - CALLBACKS/javascript Expand file tree Collapse file tree 1 file changed +52
-0
lines changed Original file line number Diff line number Diff line change 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+ ) ;
You can’t perform that action at this time.
0 commit comments