Skip to content

Instantly share code, notes, and snippets.

@albertcoder
Created February 8, 2018 01:48
Show Gist options
  • Save albertcoder/76b5a2953e4a18efb521e966c992ba73 to your computer and use it in GitHub Desktop.
Save albertcoder/76b5a2953e4a18efb521e966c992ba73 to your computer and use it in GitHub Desktop.
Check your balance at the ATM
/*
* Programming Quiz - Checking Your Balance (3-5)
*/
// change the values of `balance`, `checkBalance`, and `isActive` to test your code
var balance = 0;
var checkBalance = false;
var isActive = true;
if (checkBalance === true) {
if (balance > 0 && isActive === true) {
console.log("Your balance is $" + balance + ".");
} else {
if (isActive === false) {
console.log("Your account is no longer active.");
} else if (isActive === true) {
if (balance === 0) {
console.log("Your account is empty");
} else if (balance < 0) {
console.log("Your balance is negative. Please contact bank.");
}
}
}
} else if (checkBalance === false) {
console.log("Thank you. Have a nice day!");
}
@JFlics
Copy link

JFlics commented Jul 12, 2018

this is what I have. I've tested it a bunch of times and I'm still told I have it wrong; It might not be pretty but it runs fine.

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment