这是遵循此流程图的正确方法吗?

时间:2019-06-26 17:15:40

标签: javascript

我想知道下面的代码片段是否完全符合我的流程图。

//necessary variables for my code
var balance = -1;  this one check the balance of the bank account
var checkBalance = true; //asking if i want to checkBalance
var isActive = true;     //if my bank account is active or not


//  this is the code that checks the variables 

if(checkBalance){ // if true then keep going to check the others


    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{
        console.log("Your balance is negative. please contact the                 bank.");
    }
}else{ // if check balance = false
    console.log("Thank you. Have a nice day!")
}

1 个答案:

答案 0 :(得分:0)

var balance =  -1;
var checkBalance = true;
var isActive = true;

if (checkBalance === true && isActive === false) {console.log("Your account is no longer active.");}
else if (checkBalance === true && isActive === true && balance > 0) {console.log("Your balance is $ " + balance.toFixed(2) +".");}
else if (checkBalance === true && isActive === true && balance === 0) {console.log("Your account is empty.");}
else if (checkBalance === true && isActive === true && balance < 0) {console.log("Your balance is negative. Please contact the bank.");}
else {console.log("Thank you have a nice day!");}