title: Javascript function returns undefined
body: <p>First off I am new to javascript and this is my first 'project' in this language, so I apologize for my noobiness in advance.</p>
  
  <p>I am using leaflet and D3 in this project and I can't seem to get this function to return anything except for 'Undefined'. At first I though I wasn't returning from the function properly so I tried to duplicate the error on a smaller scale here:</p>
  
  <p><a href="http://jsfiddle.net/KhqwR/" rel="nofollow">http://jsfiddle.net/KhqwR/</a></p>
  
  <p>However, that worked for me so now I am a little lost on what to do.</p>
  
  <p>Here is a simple version of my code, I tried to remove everything that didn't seem relevant and changed the names to make it easier to understand:</p>
  
  <pre><code>$(function () {
    ...  
    function getThings(code) {    
      d3.csv("data.csv", function(data){
        for (var i = 0, len = data.length; i &lt; len; i++){        
          if (data[i].code == code){                     
            alert("return 5!")
            return 5;
          }
          else{
            return 0;
          }
        }
      })
    }
  
    L.geoJson( features,  {
      style: function (feature) {
        return { opacity: 0, fillOpacity: 0.5, fillColor: "#0f0" };
      },
      onEachFeature: function(feature, layer){ 
        var test = getThings(5);      
        alert(test);
        ...
  </code></pre>
  
  <p>I consistently get to the "return 5!" alert and then at the alert(test) I just get "Undefined".</p>
  
  <p>Does anybody know where I went wrong? 
  Thanks in advance!</p>