Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

387
Visualizações
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 Respostas
Responde à pergunta

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 Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda