the variable g's value is supposed to be passed to the percentage property BUT if I don't alert(g) before passing to percentage, it gives g's value as undefined. Gives an "Error in parsing value". language is js/jquery.
var g;     
function refreshCounts() {
    var url = 'https://graph.facebook.com/v2.8/?ids=' + postID + '&fields=' + reactions + '&access_token=' + access_token;
    $.getJSON(url, function(res){
        g = (defaultCount + res[postID].reactions_like.summary.total_count);
    });
}
$(document).ready(function(){
    setInterval(refreshCounts, refreshTime * 1000);
    refreshCounts();  
   alert(g);
    $('#jq').LineProgressbar({
        percentage:g,
        radius: '3px',
        height: '20px',
        });
});
 
    