-1

I'm just learning JS and trying to make a classic wow XP per hour calculator, I set variables of each classes that have attributs [KT(KillTime), KPH(KillsPerHour),XPR(EXP Per Hour).

I can't figure out how to log the solution of the functions I have, and when i try to log warrior.KPH it gives be NaN which i know means not number

var EXP = 278;

var warrior = {
    KT: 5.7,
    calcKPH: function() {
        this.KPH = 3600 / this.KT;
        return this.KPH;
    },
    calcXPR: function() {
        this.XPR = this.KPH * EXP;
        return this.XPR;
    }
}

console.log(warrior);

I expect to be able to add individual attributes to each variable and have a function that calculates the EXP per hour & Kills Per Hour (Sorry i'm still learning the JS grammar)

R.J. Dunnill
  • 2,049
  • 3
  • 10
  • 21
TD3
  • 1
  • 2

1 Answers1

0

I can't figure out how to log the solution of the functions I have

You have to call them:

 console.log(
   "these are the return values of the methods:",
   warrior.calcKPH(), 
   warrior.calcXPR(),
   "now the object got additional properties set:",
   warrior
 );
Jonas Wilms
  • 132,000
  • 20
  • 149
  • 151