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

Ian Olson
Ian Olson
2,204 Points

not sure if I wanna keep using i or e variable

seems like any number I input will make bold the text, not sure if I should be using the event variable over the i?

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 (i.textInput === 0,1,2 ) {

  = '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>

1 Answer

william griffin
william griffin
11,869 Points

Your best bet is to be as descriptive as possible, I personally use event as just using a single letter gets lost in translation over long code. Same goes for using a letter as a variable anywhere on any code