Created game, something isn't right


#1


I created a game, but I am not getting what I want. This is part of the code, where the bad output is.


When I use console.log("Your HP is "+p.hp+"/"+p.fhp+"!"); the console says 'Your HP is NaN/400!'

Also:

p.fhp = 400;
p.hp = p.fhp;

var battle = function() {
    var m = new Object();
    m.lvl = p.lvl - Math.round(Math.random());
    if (m.lvl === 0) {m.lvl = 1;} else {}
    m.dam = m.lvl * 10;
    m.blo = m.lvl * 5;
    m.acc = m.lvl * 2;
    m.cchance = m.lvl * 1.25;
    m.fhp = m.lvl * 100;
    m.hp = m.fhp;
    console.log("A level "+m.lvl+" monster attacks you!");
    var death = false;
    while (!death) {
        missCheck(p.acc);
        if (!miss.check) {
            critCheck(p.cchance);
            if (crit.check) {
                m.hp -= ((p.dam * 2) - m.blo);
                console.log("You make a critical hit!");
                if (m.hp < 1) {
                    console.log("You killed the monster!")
                    death = true;
                } else {
                    console.log("The monster's HP is "+m.hp+"/"+m.fhp+"!");
                }
            } else if (!crit.check) {
                m.hp -= (p.dam - m.blo);
                console.log("You hit the monster!");
                if (m.hp < 1) {
                   console.log("You killed the monster!")
                   death = true;
                } else {
                console.log("The monster's HP is "+m.hp+"/"+m.fhp+"!");
                }
            } else {
                console.log("CRITICAL ERROR");
            }
        } else if (miss.check) {
            console.log("You miss!");
        } else {
            console.log("MISS ERROR");
        }
        missCheck(m.acc);
        if (!miss.check) {
            critCheck(m.cchance);
            if (crit.check) {
                p.hp -= ((m.dam * 2) - p.blo);
                console.log("The monster makes a critical hit!");
                if (p.hp < 1) {
                    console.log("YOU HAVE DIED!!! Reload the page to start over.");
                    death = true;
                } else {
                    console.log("Your HP is "+p.hp+"/"+p.fhp+"!");
                }
            } else if (!crit.check) {
                p.hp -= (m.dam - p.blo);
                console.log("The monster hits you!");
                if (p.hp < 1) {
                    console.log("YOU HAVE DIED!!! Reload the page to start over.");
                    var death = true;
                } else {
                    console.log("Your HP is "+p.hp+"/"+p.fhp+"!");
                }
            } else {
                console.log("CRITICAL ERROR");
            }
        } else if (miss.check) {
            console.log("The monster misses!");
        } else {
            console.log("MISS ERROR");
        }
    }
    exp(m.lvl * 10);
};


#2

Check what operations you did, probably division by zero or other nonsensical operation


#3

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.