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 trial

JavaScript DOM Scripting By Example Editing and Filtering Names Fix DOM Manipulation Code

I don't really understand the format of the question?

So i maybe being stupid here. But because there is a space below the first if statement, am I meant to alter the (law == index) and add in code below in the {}? The empty space has really confused me. Also, I know i'm probably going about the answer wrongly, but I guess this question is asking to bold the list item which is typed into the input? I'm really struggling on this one. I feel like the question could of been explained better!

app.js
const laws = document.getElementsByTagName('li');
const indexText = document.getElementById('boldIndex');
const button = document.getElementById('embolden');

button.addEventListener('click', (e) => {
    const index = parseInt(indexText.value, 10);

    for (let i = 0; i < laws.length; i += 1) {
       let law = laws[i];

       // replace 'false' with a correct test condition on the line below
       if (law == index) {

           law.style.fontWeight = 'bold';
       } else {
           law.style.fontWeight = 'normal';
       }
    }
});
index.html
<!DOCTYPE html>
<html>
<head>
  <title>Newton's Laws</title>
</head>
<body>
  <h1>Newton's Laws of Motion</h1>
  <ul>
    <li>An object in motion tends to stay in motion, unless acted on by an outside force.</li>
    <li>Acceleration is dependent on the forces acting upon an object and the mass of the object.</li>
    <li>For every action, there is an equal and opposite reaction.</li>
  </ul>
  <input type="text" id="boldIndex">
  <button id="embolden">Embolden</button>
  <script src="app.js"></script>
</body>
</html>

1 Answer

Steven Parker
Steven Parker
231,269 Points

The space is not significant. The "if" line along with the comment above it are probably just set off with extra space to call your attention to them.

You had the right idea to change the condition code for the "if", but you won't want to compare an element (law) with a number (index). Think about which two numbers you could compare that would make it work.

Hello Steven,

Thanks for the reply! I didn't realise how close I was :)

Steven Parker
Steven Parker
231,269 Points

Daniel Martin — Glad to help. You can mark a question solved by choosing a "best answer".
And happy coding!