javascript 中的 If / if else 逻辑

If / if else logic in javascript

var h = game.ship.hull.hullIntegrity(); //returns int from 0-100
var hstr = h.toString()+"%";
gcp.hullIntegrity.text = hstr;
gcp.hullHealth.text = game.ship.hull.health;
//colorize data
console.log(h);
if (h === 100) {
    gcp.hullIntegrity.addColor("#05AA0D",0);
} else if (75 <= h < 100) {
    console.log("yellow: ", h + " >= 75.");
    gcp.hullIntegrity.addColor("#FFEC0D",0);
} else if (25 <= h < 75) {
    console.log("red:", h + " < 75.");
    gcp.hullIntegrity.addColor("red",0);
} else if (h < 25) {
    console.log("grey");
    gcp.hullIntegrity.addColor("grey",0);
}

我正在尝试根据其值为 canvas 文本对象的显示着色。出于某种原因,前面的代码具有以下行为:

Console.log 显示:

    70
    yellow:  70 >= 75.

但是70明显小于75,为什么控制台不显示"red"?

为什么?

如果这样的话试试

(h >= 75 && h < 100)
(h >= 25 && h < 75)

将代码更改为

var h = game.ship.hull.hullIntegrity(); //returns int from 0-100
var hstr = h.toString()+"%";
gcp.hullIntegrity.text = hstr;
gcp.hullHealth.text = game.ship.hull.health;
//colorize data
console.log(h);
if (h === 100) {
   gcp.hullIntegrity.addColor("#05AA0D",0);
} else if (h >= 75 && h < 100) {
   console.log("yellow: ", h + " >= 75.");
   gcp.hullIntegrity.addColor("#FFEC0D",0);
} else if (h >= 75 && h < 100) {
   console.log("red:", h + " < 75.");
   gcp.hullIntegrity.addColor("red",0);
} else if (h < 25) {
   console.log("grey");
   gcp.hullIntegrity.addColor("grey",0);
}