Changing styles based on data (d3.js)

Tell us what’s happening:
Describe your issue in detail here.
Whenever I run the code below, all the tests fail despite that the resulting conditional styling of h2 elements meets the requirements of the problem. I am not sure why aren’t the tests passing?

  **Your code so far**

<body>
<script>
  const dataset = [12, 31, 22, 17, 25, 18, 29, 14, 9];

  d3.select("body").selectAll("h2")
    .data(dataset)
    .enter()
    .append("h2")
    .text((d) => (d + " USD"))
    // Add your code below this line
      .style("color", (d) => {
      if (d < 20){
        return 'red'
      }
      else {
        return 'green'
      }
    })
    // Add your code above this line
</script>
</body>
  **Your browser information:**

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

Challenge: Change Styles Based on Data

Link to the challenge:

Nvm, I re-ran the test like 20 times and eventually it let me go to the next problem.

This topic was automatically closed 182 days after the last reply. New replies are no longer allowed.