我正在比较同一个对象的两个属性,以确定哪一个更大,如果一个更大,则将另一个属性设置为True ..否则将其设置为false。
这是我的功能:
country.prototype.cure = function(){
for (var i = 0; i<this.diseases.length; i++)
{
console.log(this.health);
console.log(this.diseases[i].cureLevel);
if (this.heatlh >= this.diseases[i].cureLevel)
{
this.diseases[i].cured = true;
createDiseaseTable();
}
else
{
this.diseases[i].cured = false;
}
}
}
注意:this.health = 39000000和this.diseases [i] .cureLevel = 2500000
问题在于,每当我运行该功能时,尽管如此。健康状况越大,它总会错过if并直接进入其他...
答案 0 :(得分:0)
试试这个:
country.prototype.cure = function(){
for (var i = 0; i<this.diseases.length; i++)
{
var a=parseInt(this.health);
var b=parseInt(this.diseases[i].cureLevel);
if (a >= b)
{
this.diseases[i].cured = true;
createDiseaseTable();
}
else
{
this.diseases[i].cured = false;
}
}
}