-Dynamically Set the Coordinates for Each Bar-

Tell us what’s happening:
Where is my wrong??Can you help me?

Your code so far

    const dataset = [12, 31, 22, 17, 25, 18, 29, 14, 9];
    const w = 500;
    const h = 100;
    const svg = d3.select("body")
                  .attr("width", w)
                  .attr("height", h);
       .attr("x", (d, i) => {
         // Add your code below this line
            i = 0;          
            i += 30;       
         // Add your code above this line
       .attr("y", 0)
       .attr("width", 25)
       .attr("height", 100);

Your browser information:

User Agent is: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/69.0.3497.100 Safari/537.36.

Link to the challenge:


Check your code, you are initializing i as 0 every time it runs, also think about this if you add i+30 where “i” is the index of your array, you will end up with if i =0, i+30=30, then i=1, i+30=31 and so on, so you must use a different operator than +. I think you should try a few more times on this to understand logic and then you will have your solution. Goodluck!

Sorry but I can’t understand something.Can you explain me more easily?

Compare your above code to below one, and it was a callback function so you had to use “return” to send a value back and “i” represents index of arrays so you had to muliply it by 30.


Ohh yes now i got it thank you for the explain!