Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

#21 - JavaScript "Extra" #3905

Merged
merged 6 commits into from
May 27, 2024
53 changes: 50 additions & 3 deletions Roadmap/21 - CALLBACKS/javascript/JesusAntonioEEscamilla.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ function fetchData(name ,callback) {
}

// Aquí solo llamamos el CALLBACK
fetchData('Jesus Antonio', saludar);
// fetchData('Jesus Antonio', saludar);


// También podemos crear primero el Callback con una suma de números
Expand All @@ -38,12 +38,59 @@ function printSum(resultado) {
}

// Aquí solo llamamos el CALLBACK
sum(3,6,printSum);
// sum(3,6,printSum);



/**-----DIFICULTAD EXTRA-----*/

//Pendientes
// Una función que represente los tiempo aleatorio
function getRandomTime() {
return Math.floor(Math.random() * 10000) + 1000;
}

// La función del Callback donde tiene los 3 segmentos de
function processOrder(namePlatillo, confirmCallback, readyCallback, deliveryCallback) {
console.log(`Procesando la orden: ${namePlatillo}\n`);

// Confirmación del pedido
setTimeout(() => {
console.log('Preparando orden');
confirmCallback(namePlatillo);

// Simula el tiempo de preparación del plato
setTimeout(() => {
console.log('Preparando orden para enviar');
readyCallback(namePlatillo);

// Simula el tiempo de entrega del plato
setTimeout(() => {
console.log('Preparando orden para entregar');
deliveryCallback(namePlatillo);

}, getRandomTime());
}, getRandomTime());
}, getRandomTime());
}

// Callback de confirmación
function orderConfirmed(namePlatillo) {
console.log(`Orden confirmado del pedido: ${namePlatillo}\n`);
}

// Callback de plato listo
function orderReady(namePlatillo) {
console.log(`Orden listo de: ${namePlatillo}\n`);
}

// Callback de entrega
function orderDelivered(namePlatillo) {
console.log(`Orden entregado: ${namePlatillo}\n`);
}

// Ejemplo de uso de pedidos de restaurante
processOrder('Pizza la Italiana', orderConfirmed, orderReady, orderDelivered);
processOrder('Patas boloñesa', orderConfirmed, orderReady, orderDelivered);
processOrder('Albóndigas con arroz', orderConfirmed, orderReady, orderDelivered);

/**-----DIFICULTAD EXTRA-----*/