# Sequencing Animations Assessment -- Prompt #1 question

**URL:** https://discourse.mozilla.org/t/sequencing-animations-assessment-prompt-1-question/96925
**Category:** Learn
**Tags:** learning
**Created:** [May 5, 2022, 11:47pm UTC](https://discourse.mozilla.org/t/sequencing-animations-assessment-prompt-1-question/96925 "2022-05-05T23:47:49Z")
**Posts on this page:** 3
**Page:** 1

<div class="post-metadata">

### Author: ![bdfee](https://avatars.discourse-cdn.com/v4/letter/b/9dc877/32.png) [@bdfee](https://discourse.mozilla.org/u/bdfee)
#### Post date: [May 5, 2022, 11:47pm UTC](https://discourse.mozilla.org/t/sequencing-animations-assessment-prompt-1-question/96925/1 "2022-05-05T23:47:49Z")

</div>

Hey y’all!

I have a solution to the prompt… but also a couple questions that I haven’t been able to confidently resolve.

In [prompt 1](https://developer.mozilla.org/en-US/docs/Learn/JavaScript/Asynchronous/Sequencing_animations), we are asked the following:

> animate `alice2` when `alice1` has finished, and `alice3` when `alice2` has finished.

> Implement something that works, but has the promise version of the “callback hell” problem we saw in our [discussion of using callbacks](https://developer.mozilla.org/en-US/docs/Learn/JavaScript/Asynchronous/Introducing#callbacks).

**a solution**  
[a live solution is here](https://codepen.io/bdurf590/pen/abqvpKd)

**code in question from solution:**

```
alice1.animate(aliceTumbling, aliceTiming);
const promise1 = alice1.animate(aliceTumbling, aliceTiming).finished;

promise1.then(() => {
  const promise2 = alice2.animate(aliceTumbling, aliceTiming).finished;
  promise2.then(() => {
alice3.animate(aliceTumbling, aliceTiming)
  });
});

```

**questions**

- Can the functionality of this code be accomplished using nested callbacks but _without_ the promise variables & `.then()`? (or setTimeout 🙂 )

- If not redundant to your first answer, what might have been an implementation for this (just generally speaking) that pre-dates promises?

hope this makes sense… many thanks for your time here and elsewhere on the forum!

---

<div class="post-metadata">

### Author: ![justsomeone](https://sea1.discourse-cdn.com/flex001/user_avatar/discourse.mozilla.org/justsomeone/32/67787_2.png) [@justsomeone](https://discourse.mozilla.org/u/justsomeone)
#### Post date: [May 7, 2022, 10:07am UTC](https://discourse.mozilla.org/t/sequencing-animations-assessment-prompt-1-question/96925/2 "2022-05-07T10:07:33Z")

</div>

Hello @bdfee

you doing great well done

by the way your email is displayed you can hide it from your profile page

> [@bdfee](#):
>
> Can the functionality of this code be accomplished using nested callbacks but _without_ the promise variables & `.then()` ? (or setTimeout 🙂 )

i am not sure of that cause how i know if the animate finish it’s work or if i did not used setTimeout based on my setting for the animations

let me ask @mikoMK and @schalkneethling if they have any way for that

and have a nice day all of you 🙂

---

<div class="post-metadata">

### Author: ![mikoMK](https://sea1.discourse-cdn.com/flex001/user_avatar/discourse.mozilla.org/mikomk/32/50456_2.png) [@mikoMK](https://discourse.mozilla.org/u/mikoMK)
#### Post date: [May 8, 2022, 7:39am UTC](https://discourse.mozilla.org/t/sequencing-animations-assessment-prompt-1-question/96925/3 "2022-05-08T07:39:23Z")

</div>

Hi @bdfee

I’m not an expert on animations, but here are my thoughts.  
I don’t think you can give a callback function to `animate()`. You could use the [`finish` event](https://developer.mozilla.org/en-US/docs/Web/API/Animation/finish_event) of an animation to then call the next animation from there. I think we agree that using the promise approach in this example is easier. 😁

Before the Web Animation API was created you would use [`setInterval()`](https://developer.mozilla.org/en-US/docs/Web/API/setInterval) to repeatedly call a function that manipulates the [`style` attribute](https://developer.mozilla.org/en-US/docs/Web/API/HTMLElement/style) of an element or adds/removes classes from the element. You could for example change the width of an element by setting different values to `elem.style.width` every call.  
Later came the [`requestAnimationFrame()` function](https://developer.mozilla.org/en-US/docs/Web/API/window/requestAnimationFrame) to optimize the animation work of the browser while you still had to manually change the styles in the function.

I hope this gives you a little insight into this topic. 😃

Have a nice day,  
Michael
