D3 BarChart Tooltip test 2

I am having trouble getting the data-date attribute of the tooltip to match that the of the hovered rect. I know I am using a newer version of d3 than when this challenge was created. I also realize that as an anonymous function, d3 does not know the idex of what I’ve hovering over. However each of these rects hava a data-date property than I just ned copy over to the tooltip. Surely theres an easy way to do this.


// You may add additional external JS and CSS as needed to complete the project, however the current external resource MUST remain in place for the tests to work. BABEL must also be left in place. 

  - Select the project you would 
    like to complete from the dropdown 
  - Click the "RUN TESTS" button to
    run the tests against the blank 
  - Click the "TESTS" button to see 
    the individual test cases. 
    (should all be failing at first)
  - Start coding! As you fulfill each
    test case, you will see them go   
    from red to green.
  - As you start to build out your 
    project, when tests are failing, 
    you should get helpful errors 
    along the way!

// PLEASE NOTE: Adding global style rules using the * selector, or by adding rules to body {..} or html {..}, or to all elements within body or html, i.e. h1 {..}, has the potential to pollute the test suite's CSS. Try adding: * { color: red }, for a quick example!

d3.json('https://raw.githubusercontent.com/freeCodeCamp/ProjectReferenceData/master/GDP-data.json').then((data) => {
  var dataset = data.data;
  var dataGDP = dataset.map((item) => item[1]);
  var dataYears = dataset.map((item) => item[0]);
  const w = 800;
  const h = 600
  var tooltip = d3.select("body")
  .style('visibility', 'invisible');
  var gdpMax = d3.max(dataGDP);
  var linearScale =  d3.scaleLinear().domain([0, gdpMax]).range([0, h]);
  var scaledGDP = dataGDP.map(function(item) {
    return linearScale(item);
var result =  scaledGDP.reduce(function(result, field, index) {
  result[dataYears[index]] = field;
  return result;
}, {})
  const svg = d3.select("body")
                  .attr("width", w)
                  .attr("height", h);

       .attr("x", (d, i) => (i * 2.55))
       .attr("y", (d, i) => (h - d))
       .attr("width", 2)
       .attr("height", (d, i) => (d))
       .attr('data-date', (d, i) => dataset[i][0])
       .attr('data-gdp', (d, i) => dataset[i][1])
       .on('mouseover', function (event, d) {
       .style('visibility', 'visible')
         document.querySelector('#tooltip').setAttribute('data-date', d)
      document.querySelector('#tooltip').textContent = d
         }).on('mouseout', d => {
                .style('visibility', 'invisible')
                .style('display', 'none');

  var dataYearsDate = dataYears.map(x => new Date(x));
  const xScale = d3.scaleTime().domain([d3.min(dataYearsDate),d3.max(dataYearsDate)]).range([0,700]);
  const xAxis = d3.axisBottom(xScale).ticks(5);

   .attr("id", "x-axis")
  const yScale = d3.scaleLinear().domain([0,d3.max(dataGDP)]).range([h, 0]);
  const yAxis = d3.axisRight(yScale).ticks(10);

   .attr("id", "y-axis")

Just figured it out!