Welcome to the Treehouse Community

The Treehouse Community is a meeting place for developers, designers, and programmers of all backgrounds and skill levels to get support. Collaborate here on code errors or bugs that you need feedback on, or asking for an extra set of eyes on your latest project. Join thousands of Treehouse students and alumni in the community today. (Note: Only Treehouse students can comment or ask questions, but non-students are welcome to browse our conversations.)

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and a supportive community. Start your free trial today.

JavaScript Interactive Web Pages with JavaScript Traversing and Manipulating the DOM with JavaScript Adding Multiple Event Listeners

Javier MARQUEZ
Javier MARQUEZ
11,877 Points

I think this code challenge has a bug please guys what am I doing wrong

I cannot pass this code challenge, I cant understand why. I am using the 'change' event on the <select> element.

app.js
//Select select box
var navigationSelect = document.getElementById("nav");

//Navigate to URL when select box is changed
var navigateToValue = function() {
  window.location = this.value;
}

//Send analytics data
var sendAnalytics = function() {
  //Placeholder  
}

navigationSelect.addEventListener('change', 'navigateToValue');
navigationSelect.addEventListener('change', 'sendAnalytics');
index.html
<!DOCTYPE html>
<html>
  <body>
    <select id="nav">
      <option value="index.html">Home</option>
      <option value="about.html">About</option>
    </select>
    <h1>Home</h1>
    <script src="app.js"></script>
  </body>
</html>
about.html
<!DOCTYPE html>
<html>
  <body>
    <select id="nav">
      <option value="index.html">Home</option>
      <option value="about.html">About</option>
    </select>
    <h1>About</h1>
    <script src="app.js"></script>
  </body>
</html>

2 Answers

Steven Parker
Steven Parker
216,012 Points

:point_right: You're passing the wrong type of argument.

The second argument to addEventListener should be a callback function, but you've enclosed the function name in quotes which makes it an ordinary string.

Remove the quotes to pass the callback function by name.

Javier MARQUEZ
Javier MARQUEZ
11,877 Points

You are right, the documentation says it also.

Thanks a lot