here I wrote the code

var whil = n3.children('.trade_item'); 
var all = 0; var one = [], two = [];

for(var i = 0; i < whil.size(); i++) {
    $('.primary:last', data).children('.tradeoffer_item_list').children('.trade_item').each(function(i){
        one.push($(this).attr("data-economy-item").split('/')[2]);
        two.push($(this).attr("data-economy-item").split('/')[3]);
    });

    var ad = Price("http://steamcommunity.com/economy/itemhover/730/2/" + one[i] + "?o=" + two[i]);

    all += ad;                  
}

$('#w').html(all);

I must say that the Price function is working. It returns just a number.

But for some reason $ ('# w'). Html (all); returns the code of the Price function (namely, the js code of the fi), so the code of the Price:

function Price(url) {

    xhr = new XMLHttpRequest();
    xhr.open("POST", url, true);
    xhr.send();

    return xhr.onreadystatechange = function() {
        if (xhr.readyState == 4) 
        {
            if (xhr.responseText) 
            {
                var data = xhr.responseText;

                    var pattern = /"market_hash_name":"(.*?)"/;

                    var match = data.match(pattern);

                    var name = match[1];

                    //$('#wrapper').html('name = ' + encodeURIComponent(name));

                if (name) {
                    var url2 = 'http://steamcommunity.com/market/priceoverview/?currency=5&appid=730&market_hash_name=' + encodeURIComponent(name);                 

                    $.get(url2, function(data){

                        var pattern = /"lowest_price":"(.*?)"/;

                        var match = data.match(pattern);

                        var name = match[1].split('p')[0];

                        //$('#w').html(name);

                    }, "html");

                }   

            }

        } 
      return name;
    }
}

Here's a look at the code output

Output screen ![WxbgC.png](/attachments/large/4/0c2ec5a6975800a6353c90aadf6eb898.png) What have I done wrong and how to fix it?

Our aggressive spam bot automatically flagged your post because there was what it detected to be a spammy link in the post. I've accepted the post and unbanned you but removed the actual link, just in case it was spam. I was not able to find any of the javascript you posted at the link.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of 1.18 million developers, IT pros, digital marketers, and technology enthusiasts learning and sharing knowledge.