FAQ: Async Await - Await Promise.all()

This community-built FAQ covers the “Await Promise.all()” exercise from the lesson “Async Await”.

Paths and Courses
This exercise can be found in the following Codecademy content:

Web Development

Asynchronous JavaScript

FAQs on the exercise Await Promise.all()

There are currently no frequently asked questions associated with this exercise – that’s where you come in! You can contribute to this section by offering your own questions, answers, or clarifications on this exercise. Ask or answer a question by clicking reply (reply) below.

If you’ve had an “aha” moment about the concepts, formatting, syntax, or anything else with this exercise, consider sharing those insights! Teaching others and answering their questions is one of the best ways to learn and stay sharp.

Join the Discussion. Help a fellow learner on their journey.

Ask or answer a question about this exercise by clicking reply (reply) below!

Agree with a comment or answer? Like (like) to up-vote the contribution!

Need broader help or resources? Head here.

Looking for motivation to keep learning? Join our wider discussions.

Learn more about how to use this guide.

Found a bug? Report it!

Have a question about your account or billing? Reach out to our customer support team!

None of the above? Find out where to ask other questions here!

Got up to the 3rd challenge in this exercise and even after copying and pasting the hint itself, i get the following:

You’ll need to use string interpolation and the values from the array returned from await -ing Promise.all() to construct the string in the exact format expected. Check your spelling and punctuation. And see the hint for more help.

I tested both my and the hints solution in repl.it and both returned the correct answer so at this point i suspect there’s a bug and just wanted to see if anyone else has experienced this.

7 Likes

Are you sure you’ve placed the promises in the right order? I got this error by copying the function calls from exercise 1 distribution.

Dinner is served. We’re having beans, broccoli, rice, and chicken. :x:
Dinner is served. We’re having broccoli, rice, chicken, and beans. :white_check_mark:

4 Likes

I’m having the same issue as @balotelli9 and I am sure I did not copy the function call from exercise 1.

It’s more likely that I am overlooking a small mistake, however when looking over and over my code and the solution I see nothing different.

My code :x:

async function serveDinnerAgain(){
  let foodArray = await Promise.all([steamBroccoli(), cookRice(), bakeChicken(), cookBeans()]);
  
  console.log(`Dinner is served. We’re having ${foodArray[0]}, ${foodArray[1]}, ${foodArray[2]}, and ${foodArray[3]}.`)
}

The Solution’s code :white_check_mark: :

async function serveDinnerAgain(){
  let foodArray = await Promise.all([steamBroccoli(), cookRice(), bakeChicken(), cookBeans()]); 
  
  console.log(`Dinner is served. We're having ${foodArray[0]}, ${foodArray[1]}, ${foodArray[2]}, and ${foodArray[3]}.`)
}
7 Likes

I have the same problem mentioned by @sasquiche

2 Likes

There’s your problem. U+2019 (Right Single Quotation Mark) is the wrong Unicode character. That’s what happens when copying over strings from the HTML.
U+0027 (Apostrophe) is what you need. Delete it and retype it to get the correct character.

9 Likes

I have the same problem,

i used apostrophe

2 Likes

You did not use an apostrophe. You Typed “Were” instead of “We’re”. Fix that and you should be good. :+1:

5 Likes

Yes i changed we’re and its fine now, thanks!

3 Likes

Really poor lesson for async Promise.all. There is no mention of fast fail and how that would ultimately ruin the loop over an array that does not exist.

4 Likes

yes but if u removed the ( ) from functions inside the log console it ll be correct

Hey!
What is a good way to test this feature about failing fast ? - Promise.all() also has the benefit of failing fast .

2 Likes

I think the hint they shows how to log all items in array can be tedious if is a large list . If anyone wonder, this is a better way to log every items in array.

let concat = ‘’;
for( let i = 0; i < foodArray.length; i ++){
if(i === foodArray.length - 1){
concat += ‘and ’ + foodArray[i] +’.’;
} else{
concat += foodArray[i]+’, ';
}
}
console.log(Dinner is served. We're having ${concat});
}

2 Likes

This is the second exercise (7/9 and 8/9) where I do EXACTLY the same code as the one in the ‘view solution’ but it doesn’t work!

i.eg. : this is my code for the 8/9

async function serveDinnerAgain(){
let foodArray = await Promise.all([steamBroccoli(), cookRice(), bakeChicken(), cookBeans()]);
console.log(Dinner is served. We’re having ${foodArray[0]}, ${foodArray[1]}, ${foodArray[2]}, and ${foodArray[3]}.)
}

Can somebody help please?

There is a fault in the lesson. If you change the ’ in we’re to a ’ like this we're it should work with your code.
It really shouldn’t make a difference though.
Please update this Codecademy

2 Likes

Hello,
I tried this code for the exercice, and I don’t understand why it’s not working.
Must be doing something wrong (I guess the ${foodArray[i]}), can anyone explain please?

async function serveDinnerAgain(){
const foodArray = await Promise.all([steamBroccoli(), cookRice(), bakeChicken(), cookBeans()]);
for (let i = 0; i<foodArray.length; i++){
console.log(Dinner is served. We’re having ${foodArray[i]}.);
}
}

Thank you so much!

It suppose to show
Dinner is served. We’re having broccoli, rice, chicken, and beans.

But when you put it into a look, it will show 4 time: something like this

Dinner is served. We’re having broccoli.
Dinner is served. We’re having rice.
Dinner is served. We’re having chicken,.
Dinner is served. We’re having beans.

You can try to access the array without looping them.

1 Like

Couldn’t you do that in a single line with a .forEach and .push?

In exercise 4 of lesson 2 on async functions, I changed the library code to use async to return a promise instead of a new Promise constructor. However, I’m getting the following output. It seems that my code is not waiting for the promise to resolve before executing the then block. As per my understanding, .then() block only executes once the promise is resolved. Am I missing something?

Output:

  1. Heading to the store to buy beans…
  2. Great! I’m making undefined beans for dinner tonight!
  3. I bought kidney beans because they were on sale.

Code:

 async function shopForBeans() {
	const beanTypes = ['kidney', 'fava', 'pinto', 'black', 'garbanzo'];
  setTimeout(()=>{
    let randomIndex = Math.floor(Math.random() * 5)
    let beanType = beanTypes[randomIndex];
    console.log(`2. I bought ${beanType} beans because they were on sale.`)
   return beanType;
  }, 1000)
}

function getBeans() {
  console.log(`1. Heading to the store to buy beans...`);
  shopForBeans().then((value) =>{
  console.log(`3. Great! I'm making ${value} beans for dinner tonight!`);
})}

getBeans();```

You did some great mistakes… it seems like you have poor understanding of promises … pls watch some youtube vid