Welcome to the Treehouse Community

Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.

Start your free trial

JavaScript D3.js Data Binding with D3.js Data Binding

D3: Task 1 Not Passing

I believe I wrote the code right to change the strokes according to the parsed date, but the module is not letting me pass because "Task 1 is no longer passing" but I haven't even touched the line of code where task 1 is (line 19).

js/app.js
// height and width of the svg
var height = 800, width = 500;

var padding = 50;

var viz = d3.select("#viz-wrapper")
    .append('svg')
    .attr('id', 'viz')
    .attr('height', height)
    .attr('width', width);

d3.csv('app/climate_data_truncated.csv', function(data) {

    dots = viz.selectAll('circle')
        .data(data)
        .enter()
        .append('circle');

    dots.attr('r', function(d) {return Math.abs(d.TMIN) / 10})
        .attr('cx', function(d) {return Math.max(0 + padding, Math.random() * width - padding)})
        .attr('cy', function(d) {return Math.max(0 + padding, Math.random() * height - padding )})
        .style('stroke', function(d){
            year = d.DATE.substring(0,4)
            if (year === "1973"){
              return "green"
            }
            else {
              return "blue"
            }
               });
        .style('fill', function(d) {
            year = d.DATE.substring(0,4)
            if (year === "1973") {
                return "blue"
            }
            else {
                return "#ff00f5"
            }
        });
});
index.html
<!DOCTYPE html>
<html>
  <head>
    <meta charset="UTF-8">
    <title>Requests</title>
  </head>
  <body>
    <div id="viz-wrapper">
    </div>
  </body>
  <script src="js/d3.min.js" charset="utf-8"></script>
  <script src="js/app.js" charset="utf-8"></script>
</html>

Can you post the instructions of what task 1 and 2 are asking for?

Yea, Task 1 just asks for me to change the radius attribute from TMAX to TMIN divided by 10. It's already done with

dots.attr('r', function(d) {return Math.abs(d.TMIN) / 10})

This task (Task 2) asks me to change the stroke of the circles from the year 1973 to be different than the circles from 1974. Thanks!

Hi Chyno,

Usually a forum question relating to a video, quiz, or challenge will be linked to over in the right column under the "Related content" section.

If that's there then you can click on it and go directly to the piece of content this section is about. Then you can review or test code if needed.

2 Answers

Hi Minh,

You put a semicolon at the end of your call to the .style method which prevents the next call to .style(for fill) from being chained to the end of it.

.style('stroke', function(d){
            year = d.DATE.substring(0,4)
            if (year === "1973"){
              return "green"
            }
            else {
              return "blue"
            }
               }); // no semicolon here

Thanks! What a silly mistake!

This worked for me:

// height and width of the svg
var height = 800, width = 500;

var padding = 50;

var viz = d3.select("#viz-wrapper")
    .append('svg')
    .attr('id', 'viz')
    .attr('height', height)
    .attr('width', width);

d3.csv('app/climate_data_truncated.csv', function(data) {

    dots = viz.selectAll('circle')
        .data(data)
        .enter()
        .append('circle');

    dots.attr('r', function(d) {return Math.abs(d.TMIN) / 10})
        .attr('cx', function(d) {return Math.max(0 + padding, Math.random() * width - padding)})
        .attr('cy', function(d) {return Math.max(0 + padding, Math.random() * height - padding )})
        .style('stroke', function(d){
            year = d.DATE.substring(0,4)
            if (year === "1973"){
              return "blue"
            }
            else {
              return "#ff00f5"
            }
    });
});

Cheers!