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

code challenge

I am trying to complete the code challenge to change the stroke colors of 1973 and 1974 and it's giving me errors. Can someone help with debugging my code?

.style('stroke', function(d) {year = d.DATE.substring(0,4) if (year === '1973') { return 'blue'} else if (year === '1974') {return 'green'} else {return 'white'})

1 Answer

The challenge asks for a different color for 1973, the phrasing might have tricked you into adding the else if statement for 1974. Otherwise your code is fine.

        .style('stroke', function(d){
            year = d.DATE.substring(0,4) 
            if (year === "1973") {
                return "blue"
            }
            else {
                return "#ff00f5"
            }
        })
        .style('fill', function(d) {
            year = d.DATE.substring(0,4)
            if (year === "1973") {
                return "blue"
            }
            else {
                return "#ff00f5"
            }
        });

Hope this helps