Javascript Function always returns wrong value, although variable had correct values before
<p>I have a function that returns the highest value of an attribute in an xml file</p>

<p>The Value returned is always 0, so I think the value under the JQuery function doesnt know what happens inside of it. Here is the function:</p>

<pre><code>function findHighestValue(url,attr){
var highestValue = 0;
$.ajax({
    type: "GET",
    url: url,
    dataType: "xml",
    success: function(xml) {
        $(xml).find("achievement").each(function(){
             var value = $(this).find(attr).text();
             value = value*1;//typecast
             console.log("value: "+value);//shows correct value
             console.log("highestValue in ajax: "+highestValue);//shows correct value
             if (value &gt;= highestValue){
                 highestValue = value;
                 console.log("Value higher highesValue detected!");//works as intended
             }

        });
    }
});
console.log("Highest Value: "+highestValue);// is 0 again
return highestValue;//always returns 0
}
</code></pre>
