JavaScript JavaScript and the DOM Responding to User Interaction Event Delegation

Not sure why this code isn't working.

I can't seem to figure out why the input element isn't being targeted properly.

let section = document.getElementsByTagName('section')[0];

section.addEventListener('click', (e) => {
  if ( = 'INPUT') { = 'rgb(255, 255, 0)';
<!DOCTYPE html>
        <title>JavaScript and the DOM</title>
    <link rel="stylesheet" href="style.css" />
            <h1>Making a Webpage Interactive</h1>
            <p>JavaScript is an exciting language that you can use to power web servers, create desktop programs, and even control robots. But JavaScript got its start in the browser way back in 1995.</p>
            <p>Things to Learn</p>
                <li>Item One: <input type="text"></li>
                <li>Item Two: <input type="text"></li>
                <li>Item Three: <input type="text"></li>
                <li>Item Four: <input type="text"></li>
        <script src="app.js"></script>

2 Answers

Some hints:

  • The property you are looking for is tagName
  • You are using an assignment operator in your if condition. To make a comparison use ==.
Juan Lopez
.a{fill-rule:evenodd;}techdegree seal-36
Juan Lopez
Treehouse Project Reviewer

Hey Sarah good job on writing your if statement. So there are a couple of minor details that need changing to pass the challenge.

if ( = 'INPUT') {

So starting off it seems as though there might be a small mistake as to the property you were trying to access from the looks as though you might have meant tagName instead of targetName.

If you do a console.dir( and open your Chrome Dev Tools you'll be able to see what properties are accessible from

Secondly, keep in mind the = will try and assign a value rather than check a value. With that being said you'll want to use the === to check if the is equal to INPUT like so

section.addEventListener('click', (e) => {
  if ( === 'INPUT') { = 'rgb(255, 255, 0)';