Test doesn't seem to work on D3/28

Hello, I’m working on the D3 Lessons 28th one and it seems like that the test doesn’t work properly.

I believe I am getting the right numbers for the x and y values (should be approximately), but given that it has a range of decimals it’s either going beyond the range that it’s checking, or something might be wrong with the code though I did compare and it should be all good.

Here’s the code:

<body>
  <script>
    const dataset = [
                  [ 34,     78 ],
                  [ 109,   280 ],
                  [ 310,   120 ],
                  [ 79,   411 ],
                  [ 420,   220 ],
                  [ 233,   145 ],
                  [ 333,   96 ],
                  [ 222,    333 ],
                  [ 78,    320 ],
                  [ 21,   123 ]
                ];

    const w = 500;
    const h = 500;
    const padding = 60;

    const xScale = d3.scaleLinear()
                     .domain([0, d3.max(dataset, (d) => d[0])])
                     .range([padding, w - padding]);

    const yScale = d3.scaleLinear()
                     .domain([0, d3.max(dataset, (d) => d[1])])
                     .range([h - padding, padding]);

    const svg = d3.select("body")
                  .append("svg")
                  .attr("width", w)
                  .attr("height", h);

    svg.selectAll("circle")
       .data(dataset)
       .enter()
       .append("circle")
       // Add your code below this line
       .attr("cx", (d) => xScale(d[0]))
       .attr("cy", (d) => yScale(d[1]))
       .attr("r", 5);

       // Add your code above this line

    svg.selectAll("text")
       .data(dataset)
       .enter()
       .append("text")
       .text((d) =>  (d[0] + ", "
 + d[1]))
       // Add your code below this line
       .attr("x", (d) => xScale(d[0])+10)
       .attr("y", (d) => yScale(d[1]))


       // Add your code above this line
  </script>
</body>

Hi @dinokukic ,

The brief for the x value of text is - add 10 units to the x data value before
passing it to the xScale

.attr("x", (d) => xScale(d[0])+10) ← 10 is added after d[0] is passed to the xScale

Hope this helps

Ah, can’t believe it :see_no_evil: - it did work! thanks a lot!

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