为什么另一个 else if 语句 运行 javascript
Why is another else if statment running javascript
所以我正在 JavaScript 开发贷款计算器。所以我一直运行关注这个问题,当用户输入一个高于 400 但低于 500 的数字时,它不会 运行 那个 if 语句,而是 运行 另一个 else if如果数字高于 500 且低于 640 的语句。我正在谈论的以下代码在下面。任何帮助将不胜感激。
else if (500 < getCredit < 640){
alert("This is it");
score += 6
console.log("The score is " + score);
}
else if (400 < getCredit < 500) {
score += 0 // The else if statement above is executed and not this one whenever conditions are met
}
下面是剩下的代码
js代码
function myFunction() {
score = 0;
var getCredit = parseInt(document.getElementById("credit").value);
if(getCredit > 640){
score += 12
console.log("The score is " + score);// This is working the right way
}
else if (500 < getCredit < 640){
alert("I learned something at Mathnasium");
score += 6
console.log("The score is " + score);
}
else if (400 < getCredit < 500) {
score += 0
}
}
function myFunction() {
score = 0;
var getCredit = parseInt(document.getElementById("credit").value);
if(getCredit > 640){
score += 12
console.log("The score is " + score);// This is working the right way
}
else if (getCredit > 500 && getCredit <= 640){
alert("I learned something at Mathnasium");
score += 6
console.log("The score is " + score);
}
else if (getCredit > 400 && getCredit <= 500) {
score += 0
}
}
if (getCredit >= 640) {
// credit is 640 or more
}
else if (getCredit >= 500) {
// credit is 500 or more, and less than 640 because of the "if (getCredit >= 640)" above
}
else if (getCredit >= 400) {
// credit is 400 or more, and less than 500
}
else if (500 < getCredit < 640){
从左到右计算为
else if ( (500 < getCredit) < 640) {
的计算结果为 (true < 640)
或 (false < 640)
, 但 它们的结果均为 true:
console.log(500 < 1 < 640) // true (false < 640)
console.log(true < 640) // true
console.log(false < 640) // true
console.log(true == 1) // true
console.log(false == 0) // true
所以我正在 JavaScript 开发贷款计算器。所以我一直运行关注这个问题,当用户输入一个高于 400 但低于 500 的数字时,它不会 运行 那个 if 语句,而是 运行 另一个 else if如果数字高于 500 且低于 640 的语句。我正在谈论的以下代码在下面。任何帮助将不胜感激。
else if (500 < getCredit < 640){
alert("This is it");
score += 6
console.log("The score is " + score);
}
else if (400 < getCredit < 500) {
score += 0 // The else if statement above is executed and not this one whenever conditions are met
}
下面是剩下的代码 js代码
function myFunction() {
score = 0;
var getCredit = parseInt(document.getElementById("credit").value);
if(getCredit > 640){
score += 12
console.log("The score is " + score);// This is working the right way
}
else if (500 < getCredit < 640){
alert("I learned something at Mathnasium");
score += 6
console.log("The score is " + score);
}
else if (400 < getCredit < 500) {
score += 0
}
}
function myFunction() {
score = 0;
var getCredit = parseInt(document.getElementById("credit").value);
if(getCredit > 640){
score += 12
console.log("The score is " + score);// This is working the right way
}
else if (getCredit > 500 && getCredit <= 640){
alert("I learned something at Mathnasium");
score += 6
console.log("The score is " + score);
}
else if (getCredit > 400 && getCredit <= 500) {
score += 0
}
}
if (getCredit >= 640) {
// credit is 640 or more
}
else if (getCredit >= 500) {
// credit is 500 or more, and less than 640 because of the "if (getCredit >= 640)" above
}
else if (getCredit >= 400) {
// credit is 400 or more, and less than 500
}
else if (500 < getCredit < 640){
从左到右计算为
else if ( (500 < getCredit) < 640) {
的计算结果为 (true < 640)
或 (false < 640)
, 但 它们的结果均为 true:
console.log(500 < 1 < 640) // true (false < 640)
console.log(true < 640) // true
console.log(false < 640) // true
console.log(true == 1) // true
console.log(false == 0) // true