title: Why can I get console.log(variable) to give my value but not return variable?
body: <p>In my code I'm loading data from json using d3.json - and in order to get it working I call another function once the data is loaded and pass the json across there for processing. This seems to be working, but still refuses to return anything but "undefined". </p>
  
  <p>My code:</p>
  
  <pre><code>function GetDataFromJson() {
        var jsonData;
      d3.json("http://localhost:8000/pipeline.json", function(dataFromServer){
          jsonData = dataFromServer; 
            NewValue(jsonData);
       });
      }
  </code></pre>
  
  <p>and</p>
  
  <pre><code>function NewValue(data){
    var jsonData = data;
    headers = ["Won"];
    var myTotal = 0;
        chunks = (headers.map(function(priceRange) {
            return jsonData.map(function(d) {
              return {y: +d[priceRange]};
            });
        }));
        var myTarget = 10000000;
        chunks.forEach( function (arrayItem)
            {
              var l = 12;
              for(var i = 0; i &lt; l; i++) {
                myTotal += arrayItem[i].y;
              };
            });
        myTotal = myTotal/myTarget*100;
        return myTotal;
  }
  </code></pre>
  
  <p>I'm running this in Firefox Firebug using <code>GetDataFromJson()</code> and with the code above as-is I just get "undefined" in the console. If I add a line <code>console.log(myTotal)</code> before the return statement I get "undefined" and "37.5" returned as 2 separate lines - 37.5 being the correct value from the data I parsed in. </p>
  
  <p>Why isn't return giving my myTotal as the result of the function whereas console.log() is?</p>
  
  <p><strong>Adding Json data</strong></p>
  
  <pre><code>[
    {
      "Month": "Jan",
      "Prospecting": 0,
      "Qualifying": 0,
      "Demonstrating": 0,
      "Negotiating": 0,
      "Won": 1000000,
      "Lost": 350000
    },
    {
      "Month": "Feb",
      "Prospecting": 0,
      "Qualifying": 0,
      "Demonstrating": 0,
      "Negotiating": 0,
      "Won": 750000,
      "Lost": 2750775
    },
    {
      "Month": "Mar",
      "Prospecting": 0,
      "Qualifying": 0,
      "Demonstrating": 0,
      "Negotiating": 250000,
      "Won": 2000000,
      "Lost": 750000
    },
    {
      "Month": "Apr",
      "Prospecting": 0,
      "Qualifying": 0,
      "Demonstrating": 0,
      "Negotiating": 1375000,
      "Won": 0,
      "Lost": 0
    },
    {
      "Month": "May",
      "Prospecting": 0,
      "Qualifying": 0,
      "Demonstrating": 750000,
      "Negotiating": 0,
      "Won": 0,
      "Lost": 0
    },
    {
      "Month": "Jun",
      "Prospecting": 0,
      "Qualifying": 0,
      "Demonstrating": 325000,
      "Negotiating": 0,
      "Won": 0,
      "Lost": 0
    },
    {
      "Month": "Jul",
      "Prospecting": 0,
      "Qualifying": 50000,
      "Demonstrating": 1000000,
      "Negotiating": 0,
      "Won": 0,
      "Lost": 0
    },
    {
      "Month": "Aug",
      "Prospecting": 10000,
      "Qualifying": 35000,
      "Demonstrating": 0,
      "Negotiating": 0,
      "Won": 0,
      "Lost": 0
    },
    {
      "Month": "Sep",
      "Prospecting": 12250,
      "Qualifying": 22500,
      "Demonstrating": 0,
      "Negotiating": 0,
      "Won": 0,
      "Lost": 0
    },
    {
      "Month": "Oct",
      "Prospecting": 0,
      "Qualifying": 0,
      "Demonstrating": 0,
      "Negotiating": 0,
      "Won": 0,
      "Lost": 0
    },
    {
      "Month": "Nov",
      "Prospecting": 100000,
      "Qualifying": 325000,
      "Demonstrating": 750000,
      "Negotiating": 0,
      "Won": 0,
      "Lost": 0
    },
    {
      "Month": "Dec",
      "Prospecting": 120000,
      "Qualifying": 370500,
      "Demonstrating": 670000,
      "Negotiating": 0,
      "Won": 0,
      "Lost": 0
    }
  ]
  </code></pre>