Note that there are some explanatory texts on larger screens.

plurals
  1. POCall function with javascript
    text
    copied!<p>Here I have two functions: <code>updateTooltipContent</code> and <code>distance</code>.</p> <p>When I try to call <code>distance(latt)</code> in <code>updateTooltipContent</code> it does not return any value. I cannot see why not</p> <p>CODE:</p> <pre><code>function updateTooltipContent() { var fullt = $(this).width(); var startt = $(this).position().left + 200; var endt = fullt + startt; var latt = $(this).attr("lat"); return "Spending: " + formatTime(fullt) + "&lt;/br&gt; Between:(" + formatTime(startt) + " and " + formatTime(endt) + ") &lt;/br&gt;" + distance(latt) + "km"; } }); function distance(latt) { var bigArray = nArray(); var dis = 0.00; for (var x = 0; x &lt; bigArray.length; x++) { if (bigArray[x].lat == latt) { dis = bigArray[x].DISTANCE_FROM_PREVIOUS_OBJECT_LOCATION; break; // no point doing anymore loops as we've found the answer } return dis; } } </code></pre> <p>This code work great but when I try to put some of code in function then wont to work: WORKING CODE WITHOUT FUNCTION DISTANCE()</p> <pre><code>function updateTooltipContent() { var fullt = $(this).width(); var startt = $( this ).position().left + 200; var endt = fullt + startt; var latt = $(this).attr("lat"); var bigArray = nArray(); var distance = 0.00; for(var x = 0; x &lt; bigArray.length; x++) { if(bigArray[x].lat == latt) { distance = bigArray[x].DISTANCE_FROM_PREVIOUS_OBJECT_LOCATION; break; // no point doing anymore loops as we've found the answer } } return "Spending: "+formatTime(fullt) + "&lt;/br&gt; Between:("+formatTime(startt) + " and " +formatTime(endt)+") &lt;/br&gt;" + distance.toFixed(2) + "km"; } }); </code></pre>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload