Need assistance in work-with-dynamic-data-in-d3

Challenge Name

work-with-dynamic-data-in-d3 has an issue.

Issue Description

Appears to be a bug when running the tests.

Correct code returns this in console:

“Identified ‘dataset’ has already been declared”

I’ve tested the challenge in JS Fiddle and the code is correct.

Browser Information

User Agent is: Mozilla/5.0 (Macintosh; Intel Mac OS X 10_12_3) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/62.0.3202.62 Safari/537.36.

Screenshot

Your Code



<body>
  <script>
    const dataset = [12, 31, 22, 17, 25, 18, 29, 14, 9];
    
    d3.select("body").selectAll("h2")
      .data(dataset)
      .enter()
      .append("h2")
      // Add your code below this line
      
       .text((d) => d);
      
      // Add your code above this line
  </script>
</body>

You can try wrapping the JS code in braces so the dataset constant is not bound to the global environment:

{
    const dataset = [12, 31, 22, 17, 25, 18, 29, 14, 9];
    
    d3.select("body").selectAll("h2")
      .data(dataset)
      .enter()
      .append("h2")
      // Add your code below this line
      
       .text((d) => d);
      
      // Add your code above this line
}

It doesn’t seem to work for every challenge though.

Interestingly, I don’t get that error in Firefox.