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

andres ponton
andres ponton
10,350 Points

I need help to solve this challenge

what goes in the if statement pls

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 (index) {

  = 'bold';
       } else {
  = '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>

2 Answers

Steven Parker
Steven Parker
203,151 Points

You've got part of it — now you need to compare the user's "index" with the current loop index to see if they match.

andres ponton
andres ponton
10,350 Points

I cant get it right this is what I have if (index==law)

Steven Parker
Steven Parker
203,151 Points

The "law" variable holds a reference to a list item element. But "index" is just an integer value.

What you want to compare "index" to is the integer value that was used to obtain "law".