-
Notifications
You must be signed in to change notification settings - Fork 447
Expand file tree
/
Copy pathhtml.js
More file actions
50 lines (42 loc) · 1.17 KB
/
html.js
File metadata and controls
50 lines (42 loc) · 1.17 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
var amountInAccount = 0;
var deposit = 0;
var withdraw = 0;
//check balance
function checkBalance() {
var amount = document.getElementById('amount'); //returns the <p> tag with id 'amount'
amount.innerText ="Your available balance is $" + amountInAccount;
}
$("#bank-actions").change(function(){
console.log($(this).val());
var selectboxVal = $(this).val();
switch (selectboxVal) {
case "check":
checkBalance();
break;
case "withdraw":
withdrawMoney();
break;
case "deposit":
depositMoney();
break;
default:
break;
}
});
//deposit money
function depositMoney() {
var deposit = prompt("how much are you depositing today?");
amountInAccount = amountInAccount + parseInt(deposit);
checkBalance();
}
//withdraw money
function withdrawMoney(){
var withdraw = prompt("how much are you taking out today?");
if(amountInAccount <= 0 || withdraw > amountInAccount){
alert("Please make a deposit. Your account does not have sufficient funds");
}
else{
amountInAccount = amountInAccount - parseInt(withdraw);
checkBalance();
}
}