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! While you're at it, check out some resources Treehouse students have shared here.
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 trialzkb
Front End Web Development Techdegree Graduate 13,636 PointsWhere am I going wrong with my code???
I don't get this at all. I've checked everything and the useless hint only asks me if I've applied the event listener to btn1, which doesn't help one bit. Does anybody know what I did wrong? I'm totally lost here.
const btn1 = document.getElementById("button1");
const btn2 = document.getElementById("button2");
const btn3 = document.getElementById("button3");
function spinElement(event) {
//Applies spinning animation to button element
event.target.className = "spin";
}
btn1.addEventListener = ('click', event => {
spinElement(event)
});
btn2.addEventListener = ('click', event => {
spinElement(event)
});
btn3.addEventListener = ('click', event => {
spinElement(event)
});
<!DOCTYPE html>
<html lang="en">
<head>
<title></title>
<link rel='stylesheet' href='styles.css'>
</head>
<body>
<section >
<button id='button1'>Button 1</button>
<button id='button2'>Button 2</button>
<button id='button3'>Button 3</button>
</section>
<script src='app.js'></script>
</body>
</html>
1 Answer
Bella Bradbury
Front End Web Development Techdegree Graduate 32,790 PointsYou're so close! The only thing that you need to modify for each event listener is to take out the =
between addEventListner
and ('click'...
. Remember that you're using a method on variables that have already been assigned at the top of the code.
Here is a link to the relevant w3schools page if you're interested in reading more about the syntax of addEventListner. Happy coding!
zkb
Front End Web Development Techdegree Graduate 13,636 Pointszkb
Front End Web Development Techdegree Graduate 13,636 PointsThank you! I can't believe I didn't notice that after all the times I looked over it.