424,066 Members | 2,121 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 424,066 IT Pros & Developers. It's quick & easy.

check money at ATM program

P: 6
Directions:
Using the flowchart below, write the code to represent checking your balance at the ATM. The yellow diamonds represent conditional statements and the blue rectangles with rounded corners represent what should be printed to the console.

Flowchart for checking your balance at the ATM (Click the image to enlarge the flowchart).
Use the following variables in your solution:
balance - the account balance
isActive - if account is active
checkBalance - if you want to check balance
Hint: The variable balance could be a value less than, greater than, or equal to 0. The variables isActive and checkBalance are booleans that can be set to true or false.
TIP: To print out the account balance with decimal points (i.e. 325.00), use the .toFixed() method and pass it the number of decimal points you want to use. For example, balance.toFixed(2) returns 325.00.

TIP: Make sure to test your code with different values. For example,

If checkBalance equals true and isActive equals false, then Your account is no longer active. should be printed to the console.

My ANSWER was :

Expand|Select|Wrap|Line Numbers
  1. var balance = 7869000.00;
  2. var checkBalance = true;
  3. var isActive = true;
  4. if ( checkBalance === true && isActive === true && balance > 0.00) {
  5.  
  6.     console.log("Your balance is $" +  balance +".");
  7.     }
  8.     else if (checkBalance === false){
  9.         console.log("Thank you.Have a nice day!");
  10.     }
  11.  
  12.   else; if (checkBalance === true && isActive === false) {
  13.  
  14.      console.log("Your account is no longer active.") ; }
  15.  
  16.   else if (checkBalance === true && isActive === true && balance === 0.00)
  17. {
  18.      console.log("Your account is empty.");
  19.      }
  20.  
  21.      else if ( checkBalance === true && isActive === true && balance < 0.00) {
  22.          console.log("Your account is negative.Please contact bank.")}
HOWEVER I AM TOLD THAT THE ANSWER IS INCORRECT> Please do help.
Regards
2 Weeks Ago #1

✓ answered by gits

well - in your line 12 is a useless semicolon - which basically only ends the first chain of if-else-if conditions. the next block still runs as the semicolon before just marks an empty instruction after the else there. So its not really 'incorrect' but its a thing that should be fixed for the sake of not looking pointless there. Another thing is that you didnt use the hint with the toFixed method - which could be seen as something missing. since there obviously is a chart that shows exactly how the conditions should work - and we dont see that chart here - its guesswork if something is not implemented as it should be - besides the 2 things i could see and mentioned so far.

Share this Question
Share on Google+
2 Replies


gits
Expert Mod 5K+
P: 5,192
well - in your line 12 is a useless semicolon - which basically only ends the first chain of if-else-if conditions. the next block still runs as the semicolon before just marks an empty instruction after the else there. So its not really 'incorrect' but its a thing that should be fixed for the sake of not looking pointless there. Another thing is that you didnt use the hint with the toFixed method - which could be seen as something missing. since there obviously is a chart that shows exactly how the conditions should work - and we dont see that chart here - its guesswork if something is not implemented as it should be - besides the 2 things i could see and mentioned so far.
1 Week Ago #2

P: 6
Thanks Gits! you were right. Regards
1 Week Ago #3

Post your reply

Sign in to post your reply or Sign up for a free account.