当我运行此代码时,它总是给我相同的结果“你的余额是$ 250.00。” 我改变了变量以获得不同的答案,但我认为有些错误我不知道。 附件是描述代码和流程的流程图。enter image description here
enter code here
**// change the values of `balance`, `checkBalance`, and `isActive` to test
your code
var balance = 250;
var checkBalance = false;
var isActive = true;
// your code goes here
if (checkBalance = false){
console.log("thank you! Have a nice day.");
}
else if (isActive = true && balance > 0){
console.log("your balance is $ " + balance.toFixed(2) + ".");
}
else if (isActive = false){
console.log("Your account is no longer active.");
}
else if (balance = 0){
console.log("Your account is empty.");
}
else if (balance < 0) {
console.log("Your account is negative. Please, contact bank.");
}**
答案 0 :(得分:2)
您需要在语句中使用比较(===
或==
),而不是分配=
。使用boolean
类型,您可以发出===
部分,并使用带或不带!
的值。每个值都将转换为boolean
类型,因此checkBalance === true
仅相当于checkBalance
,而checkBalance === false
仅相当于!checkBalance
。
var balance = 250;
var checkBalance = false;
var isActive = true;
if (!checkBalance){
console.log("thank you! Have a nice day.");
}
else if (isActive && balance > 0){
console.log("your balance is $ " + balance.toFixed(2) + ".");
}
else if (!isActive){
console.log("Your account is no longer active.");
}
else if (balance === 0){
console.log("Your account is empty.");
}
else if (balance < 0) {
console.log("Your account is negative. Please, contact bank.");
}
&#13;