使用 JS 进行故障排除

Troubleshoot with JS

本文关键字:故障 排除 JS 使用      更新时间:2023-09-26

我一直在为我的朋友寻找JS和HTML,因为它不起作用,我已经花了5个小时,我找不到错误...

当你在jsfiddle中测试代码时,尝试点击"Bountie",它应该从你那里拿走HP,但它没有,它什么都不做......

我很抱歉代码很长。

演示

/*
Variables
Started at 10:57 1/2-16
Finished at unknown
*/
//Level variables
var level = 1;
var gon = 0;
var xp = 0;
var sp = 3;
//Item variables
var items = 0;
var key = 0;
var gem = 0;
var stone = 0;
//Token system
var token = 0;
var heatf = 0;
var heltf = 0;
//Quest system
var bountieqp = 0;
var mapqp = 10;
var hellqp = 10;
var heavenqp = 10;
var underworldqp = 10;
//Quest tracker
var bountieqtracker = 0;
var mapqtracker = 0;
var hellqtracker = 0;
var heavenqtracker = 0;
var underworldqtracker = 0;
//Predium varables
var giftbox = 1;
//Combats variables
var str = 0;
var dex = 0;
var intt = 0;
var armor = 4;
var dmg = 5;
var hp = 300;
var hpren = 3;
var mana = 60;
var manaren = 1;
//Addon variables
var xpbonus = 1;
var xponkill = 0;
var mf = 1;
var souls = 0;
//Prestige system
var prelevel = 1;
var ppiece = 0;
//Map tracker variables
var bountietracker = 0;
var maptracker = 0;
var gmaptracker = 0;
var helltracker = 0;
var heaventracker = 0;
var underworldtracker = 0;
//Quest system updates
document.getElementById('hellqp').innerHTML = hellqp;
document.getElementById('heavenqp').innerHTML = heavenqp;
document.getElementById('bountieqp').innerHTML = bountieqp;
document.getElementById('mapqp').innerHTML = mapqp;
document.getElementById('underworldqp').innerHTML = underworldqp;
//Tracker system updates
document.getElementById('maptracker').innerHTML = maptracker;
document.getElementById('underworldtracker').innerHTML = underworldtracker;
document.getElementById('gmaptracker').innerHTML = gmaptracker;
document.getElementById('bountietracker').innerHTML = bountietracker;
document.getElementById('helltracker').innerHTML = helltracker;
document.getElementById('heaventracker').innerHTML = heaventracker;
//Quest tracker system updates
document.getElementById('mapqtracker').innerHTML = mapqtracker;
document.getElementById('underworldqtracker').innerHTML = underworldqtracker;
document.getElementById('bountieqtracker').innerHTML = bountieqtracker;
document.getElementById('hellqtracker').innerHTML = hellqtracker;
document.getElementById('heavenqtracker').innerHTML = heavenqtracker;
//Stats system updates
document.getElementById('sp').innerHTML = sp;
document.getElementById('dex').innerHTML = dex;
document.getElementById('str').innerHTML = str;
document.getElementById('intt').innerHTML = intt;
document.getElementById('dmg').innerHTML = dmg;
document.getElementById('hp').innerHTML = hp;
document.getElementById('mana').innerHTML = mana;
document.getElementById('armor').innerHTML = armor;
document.getElementById('hpren').innerHTML = hpren;
document.getElementById('manaren').innerHTML = manaren;
//Addon system updates
document.getElementById('giftbox').innerHTML = giftbox;
document.getElementById('souls').innerHTML = souls;
document.getElementById('xponkill').innerHTML = xponkill;
document.getElementById('xpbonus').innerHTML = xpbonus;
document.getElementById('mf').innerHTML = mf;
//Items system updates
document.getElementById('key').innerHTML = key;
document.getElementById('stone').innerHTML = stone;
document.getElementById('gem').innerHTML = gem;
document.getElementById('items').innerHTML = items;
document.getElementById('token').innerHTML = token;
document.getElementById('heatf').innerHTML = heatf;
document.getElementById('heltf').innerHTML = heltf;
//Level system updates
document.getElementById('level').innerHTML = level;
document.getElementById('gon').innerHTML = gon;
document.getElementById('xp').innerHTML = xp;
/*
Test selection
*/

/*
Predium Addons
Started at 14:10 1/2-16
Finished at
*/
function openBox() {
    var boxrand = Math.floor(Math.random() * (13 - 1 + 1)) + 1;
    var gembrand = Math.floor(Math.random() * (5 - 1 + 1)) + 1;
    var itemsbrand = Math.floor(Math.random() * (100 - 1 + 1)) + 1;
    var keybrand = Math.floor(Math.random() * (20 - 1 + 1)) + 1;
    var stonebrand = Math.floor(Math.random() * (10 - 1 + 1)) + 1;
    var bountieqpbrand = Math.floor(Math.random() * (9 - 1 + 1)) + 1;
    var mapqpbrand = Math.floor(Math.random() * (9 - 1 + 1)) + 1;
    var hellqpbrand = Math.floor(Math.random() * (9 - 1 + 1)) + 1;
    var heavenqpbrand = Math.floor(Math.random() * (9 - 1 + 1)) + 1;
    var underworldqpbrand = Math.floor(Math.random() * (9 - 1 + 1)) + 1;
    var heltfrand = Math.floor(Math.random() * (3 - 1 + 1)) + 1;
    var heabrand = Math.floor(Math.random() * (3 - 1 + 1)) + 1;
    var xpbrand = Math.floor(Math.random() * (500000 - 1 + 1)) + 1;
    if (boxrand == 1) {
        gem = gem + gembrand;
        document.getElementById('gem').innerHTML = gem;
    } else if (boxrand == 2) {
        items = items + itemsbrand;
        document.getElementById('items').innerHTML = items;
    }else if (boxrand == 3) {
        key = key + keybrand;
        document.getElementById('key').innerHTML = key;
    }else if (boxrand == 4) {
        stone = stone + stonebrand;
        document.getElementById('stone').innerHTML = stone;
    }else if (boxrand == 5) {
        bountieqp = bountieqp + bountieqpbrand;
        document.getElementById('bountieqp').innerHTML = bountieqp;
    }else if (boxrand == 6) {
        mapqp = mapqp + mapqpbrand;
        document.getElementById('mapqp').innerHTML = mapqp;
    }else if (boxrand == 7) {
        hellqp = hellqp + hellqpbrand;
        document.getElementById('hellqp').innerHTML = hellqp;
    } else if (boxrand == 8) {
        heavenqp = heavenqp + heavenqpbrand;
        document.getElementById('heavenqp').innerHTML = heavenqp;
    } else if (boxrand == 9) {
        underworldqp = underworldqp + underworldqpbrand;
        document.getElementById('underworldqp').innerHTML = underworldqp;
    } else if(boxrand == 10) {
        heltf = heltf + heltfbrand;
        document.getElementById('heltf').innerHTML = heltf;
    } else if(boxrand == 11) {
        heatf = heatf + heatfbrand;
        document.getElementById('heatf').innerHTML = heatf;
    } else if(boxrand == 12) {
        xp = xp + xpbrand;
        document.getElementById('xp').innerHTML = xp;
    } else if (boxrand == 13) {
        ppiece = ppiece + ppiecebrand;
        document.getElementById('ppiece').innerHTML = ppiece;
    }
}
function gbChecker() {
    if (giftbox >= 1) {
        openBox();
        giftbox = giftbox - 1;
        document.getElementById('giftbox').innerHTML = giftbox;
    } else {
        alert('You dont have a Mystery Box!');
    }
}
/*
Level 
Started at 11:46 1/2-16
Finished at
*/
function levelUp() {
    var levelCost = Math.floor(200 * Math.pow(1.1,level));
    if (xp >= levelCost){                                  
        level = level + 1;
        xp = xp - levelCost;                        
        sp = sp + 3;                              
        document.getElementById('level').innerHTML = level;  
        document.getElementById('xp').innerHTML = xp; 
        document.getElementById('sp').innerHTML = sp;  
    }
    var nextlevelCost = Math.floor(200 * Math.pow(1.1,level));      
    document.getElementById('levelCost').innerHTML = nextlevelCost; 
}
function gonUp() {
    var gonCost = Math.floor(200 * Math.pow(1.1,gon));    
    if (xp >= gonCost) {                                   
        gon = gon + 1;                                   
        xp = xp - gonCost;
        sp = sp + 1;                                  
        document.getElementById('gon').innerHTML = gon; 
        document.getElementById('xp').innerHTML = xp;  
        document.getElementById('sp').innerHTML = sp;  
    }
    var nextgonCost = Math.floor(200 * Math.pow(1.1,gon));       
    document.getElementById('gonCost').innerHTML = nextgonCost;  
}
function levelChecker() {
    if (level == 120) {
        gonUp();
    } else {
        levelUp();
    }
}
/*
Addon Makers
Started at 11:34 1/2-16
Finished at 12:42 1/2-16
*/
function pp256Maker() {
    var pp256rand = Math.floor(Math.random() * (256 - 1 + 1)) + 1;
    if (pp256rand == 1) {
        ppiece = ppiece + (1 * mf);
        document.getElementById('ppiece').innerHTML = ppiece;
    }
}
function gb256Maker() {
    var gb256rand = Math.floor(Math.random() * (256 - 1 + 1)) + 1;
    if (gb256rand == 1) {
        giftbox = giftbox + 1;
        document.getElementById('giftbox').innerHTML = giftbox;
    }
}
function pp128Maker() {
    var pp128rand = Math.floor(Math.random() * (128 - 1 + 1)) + 1;
    if (pp128rand == 1) {
        ppiece = ppiece + (1 * mf);
        document.getElementById('ppiece').innerHTML = ppiece;
    }
}
function gb128Maker() {
    var gb128rand = Math.floor(Math.random() * (128 - 1 + 1)) + 1;
    if (gb128rand == 1) {
        giftbox = giftbox + 1;
        document.getElementById('giftbox').innerHTML = giftbox;
    }
}
function pp25Maker() {
    var pp25rand = Math.floor(Math.random() * (25 - 1 + 1)) + 1;
    if (pp25rand == 1) {
        ppiece = ppiece + (1 * mf);
        document.getElementById('ppiece').innerHTML = ppiece;
    }
}
function gb64Maker() {
    var gb64rand = Math.floor(Math.random() * (64 - 1 + 1)) + 1;
    if (gb64rand == 1) {
        giftbox = giftbox + 1;
        document.getElementById('giftbox').innerHTML = giftbox;
    }
}
function pp17Maker() {
    var pp17rand = Math.floor(Math.random() * (17 - 1 + 1)) + 1;
    if (pp17rand == 1) {
        ppiece = ppiece + (1 * mf);
        document.getElementById('ppiece').innerHTML = ppiece;
    }
}
function gb32Maker() {
    var gb32rand = Math.floor(Math.random() * (32 - 1 + 1)) + 1;
    if (gb32rand == 1) {
        giftbox = giftbox + 1;
        document.getElementById('giftbox').innerHTML = giftbox;
    }
}
function pp5Maker() {
    var pp5rand = Math.floor(Math.random() * (5 - 1 + 1)) + 1;
    if (pp5rand == 1) {
        ppiece = ppiece + (1 * mf);
        document.getElementById('ppiece').innerHTML = ppiece;
    }
}
function gb10Maker() {
    var gb10rand = Math.floor(Math.random() * (10 - 1 + 1)) + 1;
    if (gb10rand == 1) {
        giftbox = giftbox + 1;
        document.getElementById('giftbox').innerHTML = giftbox;
    }
}
function gb16Maker() {
    var gb16rand = Math.floor(Math.random() * (16 - 1 + 1)) + 1;
    if (gb16rand == 1) {
        giftbox = giftbox + 1;
        document.getElementById('giftbox').innerHTML = giftbox;
    }
}
function gb5Maker() {
    var gb5rand = Math.floor(Math.random() * (5 - 1 + 1)) + 1;
    if (gb5rand == 1) {
        giftbox = giftbox + 1;
        document.getElementById('giftbox').innerHTML = giftbox;
    }
}
/*
Quest Makers
Started at 12:43 1/2-16
Finished at 12:47 1/2-16
*/
function bountieqpMaker() {
    var bountieqprand = Math.floor(Math.random() * (10 - 1 + 1)) + 1;
    if (bountieqprand == 1) {
        bountieqp = bountieqp + (1 * mf);
        document.getElementById('bountieqp').innerHTML = bountieqp;
    }
}
function mapqpMaker() {
    var mapqprand = Math.floor(Math.random() * (10 - 1 + 1)) + 1;
    if (mapqprand == 1) {
        map = map + (1 * mf);
        document.getElementById('mapqp').innerHTML = mapqp;
    }
}
function hellqpMaker() {
    var bountieqprand = Math.floor(Math.random() * (10 - 1 + 1)) + 1;
    if (hellqprand == 1) {
        hell = hell + (1 * mf);
        document.getElementById('hellqp').innerHTML = hellqp;
    }
}
function heavenqpMaker() {
    var heavenqprand = Math.floor(Math.random() * (10 - 1 + 1)) + 1;
    if (heavenqprand == 1) {
        heavenqp = heavenqp + (1 * mf);
        document.getElementById('heavenqp').innerHTML = heavenqp;
    }
}
function underworldqpMaker() {
    var underworldqprand = Math.floor(Math.random() * (10 - 1 + 1)) + 1;
    if (underworldqprand == 1) {
        underworldqp = underworldqp + (1 * mf);
        document.getElementById('underworldqp').innerHTML = underworldqp;
    }
}
/*
Req items Maker
Started at 12:44 1/2-16
Finished at 13:17 1/2-16
*/
function keyMaker() {
    var keyrand = Math.floor(Math.random() * (10 - 1 + 1)) + 1;
    if (keyrand == 1) {
        key = key + (1 * mf);
        document.getElementById('key').innerHTML = key;
    }
}
function stoneMaker(){
    var stonerand = Math.floor(Math.random() * (5 - 1 + 1)) + 1;
    if (stonerand == 1) {
        stone = stone + (1 * mf);
        document.getElementById('stone').innerHTML = stone;
    }
}
/*
Quest completing
Started at 13:17 1/2-16
Finished at 13:45 1/2-16
*/
function bouqChecker(){
    if (bountieqp >= 10) {
        bouQuest();
    } else {
        alert('You dont have 10 Bountie quest pieces!. You only have ' + bountieqp + '!');
    }
}
function mapqChecker(){
    if (mapqp >= 10) {
        mapQuest();
    } else {
        alert('You dont have 10 Map quest pieces!. You only have ' + mapqp + '!');
    }
}
function hellqChecker(){
    if (hellqp >= 10) {
        hellQuest();
    } else {
        alert('You dont have 10 Hell quest pieces!. You only have ' + hellqp + '!');
    }
}
function heavenqChecker(){
    if(heavenqp >= 10){
        heavenQuest();
    }else{
        alert('You dont have 10 Heaven quest pieces!. You only have ' + heavenqp + '!');
    }
}
function underworldqChecker(){
    if(underworldqp >= 10){
        underworldQuest();
    }else{
        alert('You dont have 10 Underworld quest pieces!. You only have ' + underworldqp + '!');
    }
}
function bouQuest(){
    var bouqxprand = Math.floor(Math.random() * (1000 - 200 + 200)) + 1;
    xp = xp + ((bouqxprand * xpbonus) * prelevel);
    bountieqp = bountieqp - 10;
    gb128Maker();
    document.getElementById('xp').innerHTML = xp;
    document.getElementById('bountieqp').innerHTML = bountieqp; 
}
function mapQuest(){
    var mapqxprand = Math.floor(Math.random() * (4500 - 850 + 850)) + 1;
    xp = xp + ((mapqxprand * xpbonus) * prelevel);
    mapqp = mapqp - 10;
    gb64Maker();
    document.getElementById('xp').innerHTML = xp;
    document.getElementById('mapqp').innerHTML = mapqp; 
}
function hellQuest(){
    var hellqxprand = Math.floor(Math.random() * (250000 - 50000 + 50000)) + 1;
    xp = xp + ((hellqxprand * xpbonus) * prelevel);
    hellqp = hellqp - 10;
    gb16Maker();
    document.getElementById('xp').innerHTML = xp;
    document.getElementById('hellqp').innerHTML = hellqp; 
}
function heavenQuest(){
    var heavenqxprand = Math.floor(Math.random() * (250000 - 50000 + 50000)) + 1;
    xp = xp + ((heavenqxprand * xpbonus) * prelevel);
    heavenqp = heavenqp - 10;
    gb16Maker();
    document.getElementById('xp').innerHTML = xp;
    document.getElementById('heavenqp').innerHTML = heavenqp; 
}
function underworldQuest(){
    var underworldqxprand = Math.floor(Math.random() * (1250000 - 500000 + 500000)) + 1;
    xp = xp + ((underworldqxprand * xpbonus) * prelevel);
    underworldqp = underworldqp - 10;
    gb5Maker();
    document.getElementById('xp').innerHTML = xp;
    document.getElementById('underworldqp').innerHTML = underworldqp;
}
/*
Bountie Map
Started at 11:27 1/2-16
Finished at 13:18 1/2-16
*/
function doBountie() {
    var bountieCost = Math.floor(50 * Math.pow(1.006,bountietracker));
    var bouxprand = Math.floor(Math.random() * (200 - 20 + 20)) + 1;
    var bouitemrand = Math.floor(Math.random() * (5 - 1 + 1)) + 1;
    if (dmg + armor >= bountieCost) {
        hp = hp - 1;
        xp = xp + (((bouxprand + xponkill) * xpbonus) * prelevel);
        items = items + (bouitemrand * mf);
        bountietracker = bountietracker + 1;
        keyMaker();
        bountieqpMaker();
        pp256Maker();
        gb256Maker();
        document.getElementById('hp').innerHTML = hp;
        document.getElementById('hp2').innerHTML = hp;
        document.getElementById('xp').innerHTML = xp;
        document.getElementById('items').innerHTML = items;
    } else if (hp >= bountieCost) {
        hp = hp - (bountieCost - (armor + dmg));
        xp = xp + (((bouxprand + xponkill) * xpbonus) * prelevel);
        items = items + (bouitemrand* mf);
        bountietracker = bountietracker + 1;
        keyMaker();
        bountieqpMaker();
        pp256Maker();
        gb256Maker();
        document.getElementById('hp').innerHTML = hp;
        document.getElementById('xp').innerHTML = xp;
        document.getElementById('hp2').innerHTML = hp;
        document.getElementById('items').innerHTML = items;
    }else{
        alert('You dont have enough HP to complete a bountie. Bountie costs ' + bountieCost + ' and you only have ' + hp + '!');
    }
    var nextbountieCost = Math.floor(50 * Math.pow(1.006,bountietracker));
    document.getElementById('bountieCost').innerHTML = nextbountieCost;
}
/*
Map Map
Started at 12:37 1/2-16
Finished at 
*/
function doMap(){
    var mapCost = Math.floor(300 * Math.pow(1.006,maptracker));
    var mapxprand = Math.floor(Math.random() * (850 - 200 + 200)) + 1;
    var mapitemrand = Math.floor(Math.random() * (12 - 4 + 4)) + 1;
    if(dmg + armor >= mapCost){
        hp = hp - 1;
        xp = xp + (((mapxprand + xponkill) * xpbonus) * prelevel);
        items = items + (mapitemrand * mf);
        keyMaker();
        gb128Maker();
        mapqpMaker();
        document.getElementById('hp').innerHTML = hp;
        document.getElementById('xp').innerHTML = xp;
        document.getElementById('hp2').innerHTML = hp;
        document.getElementById('items').innerHTML = items;
    }else if(hp >= mapCost){
        hp = hp - (mapCost - (armor + dmg));
        xp = xp + (((mapxprand + xponkill) * xpbonus) * prelevel);
        items = items + (mapitemrand * mf);
        keyMaker();
        gb128Maker();
        mapqpMaker();
        document.getElementById('hp').innerHTML = hp;
        document.getElementById('xp').innerHTML = xp;
        document.getElementById('hp2').innerHTML = hp;
        document.getElementById('items').innerHTML = items;
    }else if(hp =< mapCost){
        alert('You dont have enough HP to complete a Map. Map costs ' + mapCost + ' and you only have ' + hp + '!');
    }else{
        alert('You dont have a key to open a Map!');
    }
    var nextmapCost = Math.floor(300 * Math.pow(1.006,maptracker));
    document.getElementById('mapCost').innerHTML = nextmapCost;
}

当我单击赏金按钮时,我得到错误Uncaught ReferenceError: levelChecker is not defined.

另外,在线#582

Uncaught SyntaxError: Unexpected token <

if(hp =< mapCost)应该if(hp <= mapCost)

看起来你的脚本中有一些Javascript错误。我建议使用Google Chrome的检查工具来逐步浏览Javascript,使用断点来查看数据和错误。