First off I am new to javascript and this is my first 'project' in this language, so I apologize for my noobiness in advance.
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:
However, that worked for me so now I am a little lost on what to do.
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:
$(function () {
...
function getThings(code) {
d3.csv("data.csv", function(data){
for (var i = 0, len = data.length; i < 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);
...
I consistently get to the "return 5!" alert and then at the alert(test) I just get "Undefined".
Does anybody know where I went wrong? Thanks in advance!