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 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!

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';
<!DOCTYPE html>
  <title>Newton's Laws</title>
  <h1>Newton's Laws of Motion</h1>
    <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>
  <input type="text" id="boldIndex">
  <button id="embolden">Embolden</button>
  <script src="app.js"></script>

1 Answer

Steven Parker
Steven Parker
218,487 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
218,487 Points

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