JavaScript Callback Functions in JavaScript Callbacks with Timers Triggering an Animation

Reginald Golden
seal-mask
.a{fill-rule:evenodd;}techdegree
Reginald Golden
Front End Web Development Techdegree Student 9,234 Points

Code Challenge: Triggering an Animation

I keep getting the error "Remember a timeout is 1000 milliseconds for every second" and I'm uncertain of what the problem is or how to fix it. Can someone help please?

app.js
const section = document.getElementById("animateMe");

function startAnimation() {
  setTimeout(startAnimation, 2000); //Applies spinning animation to section element
  section.className = "spin";
}
index.html
<!DOCTYPE html>
<html lang="en">
    <head>
        <title></title>
        <link rel='stylesheet' href='styles.css'>
    </head>
    <body>
        <section id="animateMe">
            <p>Animate Me in 2 Seconds!</p>
        </section>
        <script src='app.js'></script>
    </body>
</html>

1 Answer

Peter Vann
MOD
Peter Vann
Treehouse Moderator 35,207 Points

Hi Reginald!

Your arrangement of the code is a little off.

startAnimation is the callback function that setTimeout should call.

Like this (it passes)

const section = document.getElementById("animateMe");

function startAnimation() {
  section.className = "spin";
}

setTimeout(startAnimation, 2000); //Applies spinning animation to section element

I hope that helps.

Stay safe and happy coding!