0
使用數字屬性時出現什麼問題?我試圖做一個涉及數字的簡單計算,它返回NaN。使用數字屬性時操作不起作用(返回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
爲什麼percentUsersCount
NaN?
編輯:https://www.youtube.com/watch?v=yI6VXlNRrI0
尼斯抓,謝謝。 https://www.youtube.com/watch?v=yI6VXlNRrI0 – jSmith
你的JavaScript控制檯應該拋出一個錯誤,下次檢查它! :-) –
我已經在我的控制檯中,查看我放入的console.logs,但沒有拋出任何錯誤 – jSmith