Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

374
Vistas
How to show value from 2 promises in a single line?

I have a class with static methods returning promises. I am able to print in console the values returned by these promises in seperate lines. But I want to print in console in one line the weather and currency for a given city (say London). The output should be like this:

 The weather of London is cloudy. The local currency of London is GBP.

I am unable to do it with nested promises too. How it should be done?

Here is the code:

    class Provider{
            static getWeather(city){
            return Promise.resolve(`The weather of ${city} is cloudy.`);
            }
            static getLocalCurrency(city){
            return Promise.resolve(`The local currency of ${city} is GBP`)
            }
         };

    Provider.getWeather(value).then((value)=> console.log(value));
    Provider.getLocalCurrency("London").then((value)=> console.log(value));   


    
about 4 years ago · Juan Pablo Isaza
1 Respuestas
Responde la pregunta

0

You can use Promise.all.

class Provider {
  static getWeather(city) {
    return Promise.resolve(`The weather of ${city} is cloudy.`);
  }
  static getLocalCurrency(city) {
    return Promise.resolve(`The local currency of ${city} is GBP`);
  }
}

Promise.all([
  Provider.getWeather("london"),
  Provider.getLocalCurrency("London")
]).then(([weather, currency]) => {
  console.log(`${weather} ${currency}`);
});

about 4 years ago · Juan Pablo Isaza Denunciar
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda