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){

    var ad = Price("" + one[i] + "?o=" + two[i]);

    all += ad;                  


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();"POST", url, true);

    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 = '' + encodeURIComponent(name);                 

                    $.get(url2, function(data){

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

                        var match = data.match(pattern);

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


                    }, "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 developers, IT pros, digital marketers, and technology enthusiasts meeting, learning, and sharing knowledge.