Select a Group of Elements with D3

Tell us what’s happening:
Hello! I can not pass the test, please tell me what I am doing wrong, I tried other code variants, the test does not pass

Your code so far


<body>
  <ul>
    <li>Example</li>
    <li>Example</li>
    <li>Example</li>
  </ul>
  <script>
    // Add your code below this line
   d3.select("ul").selectAll ("li").append ("li").text ("list item");
    
    // Add your code above this line
  </script>
</body>

Your browser information:

User Agent is: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/68.0.3440.106 Safari/537.36.

Link to the challenge:


image

Тема закрыта , код протестирован правильно, ошибка нашлась

You are chaining too many methods:

  • d3.select("ul") : select the first ul in the code;
  • selectAll ("li") : select all the li in the actual selection ( inside the selected ul);
  • .append ("li"): append an li element to each element of the actual selection (all the li elements);
  • .text ("list item"); set the text of the actual selection (the appended elements) to ‘list item’;

Now, the challenge says:

Select all of the li tags in the document, and change their text to “list item” by chaining the .text() method.

Just choose two methods among the above list and you’re done! :slight_smile:

Test passed, thanks)

1 Like