Welcome to the Treehouse Community

Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community!

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.

Start your free trial

JavaScript Callback Functions in JavaScript Callbacks with Timers Triggering an Animation

Samuel Kleos
Samuel Kleos
Front End Web Development Techdegree Student 11,860 Points

I used an anonymous function and an arrow function but neither worked


See my code for this challenge. It asked me to apply a timer to this function. I.e. turn the function into a callback.

I don't know why it says: "The callback is not the startAnimation function"

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

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

1 Answer

Rachel Johnson
.a{fill-rule:evenodd;}techdegree seal-36
Rachel Johnson
Treehouse Project Reviewer

Hey Samuel Kleos ! You'll just need to call setTimeout() at the end of the file

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

function startAnimation() {
  //Applies spinning animation to section element
  section.className = "spin";

setTimeout(startAnimation, 2000)