Reputation: 275
What's the problem in using number properties? I'm trying to do a simple calculation involving numbers and it returns NaN.
function test () {
var that = this;
this.usersCount = 2;
this.totalSeeds = 10;
this.test2 = function () {
console.log(2/10*100); // 20
console.log(that.usersCount * that.totalSeeds); // 20
var percentUsersCount = that.usersCount / that.totalseeds * 100; // also tried parseInt() and Number()
console.log(percentUsersCount); // NaN -- WHY !?!
}
}
var test = new test();
test.test2();
var test1 = 2;
var test2 = 10;
var percent = test1 / test2 * 100;
console.log(percent); // 20
Why is percentUsersCount
NaN?
Edit: https://www.youtube.com/watch?v=yI6VXlNRrI0
Upvotes: 0
Views: 38
Reputation: 22158
You have a typo:
var percentUsersCount = that.usersCount / that.totalseeds * 100;
Change to
var percentUsersCount = that.usersCount / that.totalSeeds * 100;
Upvotes: 0
Reputation: 4406
You misspelled the name of your variable. Use that.totalSeeds
instead of that.totalseeds
.
Upvotes: 4