How would you use attr() here?

Tell us what’s happening:

Hello,

I personally used style() to solve this assignment, however, I was just wondering how could one use attr() here instead since height and width are not stored in the svg style element and instead they are stored as constants?

Your code so far


<style>
svg {
  background-color: pink;
}
</style>
<body>
<script>
  const dataset = [12, 31, 22, 17, 25, 18, 29, 14, 9];

  const w = 500;
  const h = 100;

  const svg = d3.select("body")
  // Add your code below this line
                .append("svg")
                .style("width", w)
                .style("height", h)
  // 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/80.0.3987.149 Safari/537.36.

Challenge: Learn About SVG in D3

Link to the challenge: