简体   繁体   中英

Console error: Unexpected Identifier?

In the following code, it should make iframes with certain attributes based on what you enter in the input boxes, then "scan" them every .1 seconds, clicking a button if certain requirements are met in each scan. The code keeps giving me the error SyntaxError: Unexpected identifier and I have no idea how to fix it; I can't find any typos or anything

Thanks; here is my code

$(function() {
$("html").html("");
$("<input placeholder='ID...'><input placeholder='Price...' ><input type='button' value='Add'>").prependTo("body");
$("input[type='button']").click(function() {    
    var scanId = parseInt($("input").first().val());
    var scanPrice = parseInt($("input").first().next().val());
    $("<br /><p>Scanning Item "+scanId+" for "+scanPrice+" coins</p><br /><iframe src='http://meepcity.com/item.php?id="+scanId+"' height='250px' width='500px' price='"+scanPrice+"' scan='"+scanId+"'></iframe>").appendTo("body");
    $("input").first().val("");
    $("input").first().next().val("");
    var current = $("iframe").last();
    $(current).load(function() { 
        var currentId = parseInt($(this).attr("scan"));
        var currentPrice = parseInt($(this).attr("price"));
        var x = $(this).contents().find(".item-information-buySellerAsset:first"); 
        var y = $(this).contents().find(".purchase-asset:first");
        var z = parseInt($(this).contents().find("#price:first").text());
        if (scanningPrice >= z && x.length>0 and y.length>0) { 
            x[0].click();
            console.log("Attempted to buy");
            y[0].click();
        }
    });
});
setInterval(function() {
    $("iframe").each(function() {
        $(this).load(function() { 
            var scanningId = parseInt($(this).attr("scan"));
            var scanningPrice = parseInt($(this).attr("price"));
            var x2 = $(this).contents().find(".item-information-buySellerAsset:first"); 
            var y2 = $(this).contents().find(".purchase-asset:first");
            var z2 = parseInt($(this).contents().find("#price:first").text());
            if (scanningPrice >= z2 && x2.length>0 and y2.length>0) { 
                x2[0].click();
                console.log("Attempted to buy");
                y2[0].click();
            }
            var src = $(this).attr("src");
            $(this).attr("src", src);
        });
    });
}, 100);
});

You have the literal and in your if statements. Replace them with && and it should solve your problem:

$(function() {
    $("html").html("");
    $("<input placeholder='ID...'><input placeholder='Price...' ><input type='button' value='Add'>").prependTo("body");
    $("input[type='button']").click(function() {    
        var scanId = parseInt($("input").first().val());
        var scanPrice = parseInt($("input").first().next().val());
        $("<br /><p>Scanning Item "+scanId+" for "+scanPrice+" coins</p><br /><iframe src='http://meepcity.com/item.php?id="+scanId+"' height='250px' width='500px' price='"+scanPrice+"' scan='"+scanId+"'></iframe>").appendTo("body");
        $("input").first().val("");
        $("input").first().next().val("");
        var current = $("iframe").last();
        $(current).load(function() { 
            var currentId = parseInt($(this).attr("scan"));
            var currentPrice = parseInt($(this).attr("price"));
            var x = $(this).contents().find(".item-information-buySellerAsset:first"); 
            var y = $(this).contents().find(".purchase-asset:first");
            var z = parseInt($(this).contents().find("#price:first").text());
            if (scanningPrice >= z && x.length>0 && y.length>0) { // replaced "and"
                x[0].click();
                console.log("Attempted to buy");
                y[0].click();
            }
        });
    });
    setInterval(function() {
        $("iframe").each(function() {
            $(this).load(function() { 
                var scanningId = parseInt($(this).attr("scan"));
                var scanningPrice = parseInt($(this).attr("price"));
                var x2 = $(this).contents().find(".item-information-buySellerAsset:first"); 
                var y2 = $(this).contents().find(".purchase-asset:first");
                var z2 = parseInt($(this).contents().find("#price:first").text());
                if (scanningPrice >= z2 && x2.length>0 && y2.length>0) { // replaced "and"
                    x2[0].click();
                    console.log("Attempted to buy");
                    y2[0].click();
                }
                var src = $(this).attr("src");
                $(this).attr("src", src);
            });
        });
    }, 100);
});

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM