Assessment wanted for Sequencing animations by JC

My code: https://jsfiddle.net/eur8om4x/1/

Hi all! I am extremely new to programming (less than a month) and I have been enjoying this JS guide.
I got the async assessment to work, however, I have a feeling that this could be written better. Could someone let me know how to make this more concise/better written?

And if someone could explain how I might use these functions on a simple e-commerce website, I would appreciate it! I am trying to do the research on my own but it seems like the options are endless!

Thank you!

Hi @jordanmichele61 and welcome to the community :wave:

Congratulations! You correctly solved the exercise. We could make the code a bit simpler because we don’t need the return value of the await calls. A minimal solution looks like this:

async function animateAlices() {
  try {
    await alice1.animate(aliceTumbling, aliceTiming).finished;
    await alice2.animate(aliceTumbling, aliceTiming).finished;
    await alice3.animate(aliceTumbling, aliceTiming).finished;
  }
  catch (error) {
    console.error(`Error animating Alices: ${error}`);
  }
}

animateAlices();

This question feels a bit too broad to be clearly answered. In general you’ll use async calls to fetch or send data from/to a server. That’s an operation that could take some time and you don’t want the rest of your application being blocked unit the response from the server arrives. The perfect use case for such non-blocking async functions.

For example this is a async function in my current code that gets some “types” from the server and if the operation was successful returns those types in an array or in the case of an error returns null. While the application waits for an answer from the server other stuff in the app can still happen.

  async getTypes () {
    try {
      const response = await http.get('adminModule.cfc?method=getTypes')
      return response.data.types
    } catch (error) {
      return null
    }
  }

I hope that makes it a bit clearer.

See you,
Michael