Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

369
Views
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 answers
Answer question

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 Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!