Repository navigation
Expand file tree
/
Copy pathone.js
More file actions
58 lines (51 loc) · 1.71 KB
/
Copy pathone.js
File metadata and controls
58 lines (51 loc) · 1.71 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
49
50
51
52
53
54
55
56
57
58
// make banking app
// if checking accts eremainingBalanceceeds balance remove from savings or credit card
// data set
// const dataSet = {
// name: 'smith',
// account: 'savings:5000,checking:1000,credit:2000',
// }
// const data = dataSet.account
// const regEremainingBalance1 = /:(.*)/g
// console.log(data.match(regEremainingBalance1))
// let remainingBalance = data.match(regEremainingBalance1)
// console.log('remainingBalance', remainingBalance)
// const regEremainingBalance2 = /,(.*)/
// console.log(remainingBalance.match(regEremainingBalance2))
const dataSet = {
name: 'smith',
savings: 5000,
checking: 1000,
credit: 2000,
}
const name = dataSet.name
var savings = dataSet.savings
console.log('savings', savings)
var checking = dataSet.checking
var credit = dataSet.credit
var checkingSavings = checking + savings
var checkingSavingsCredit = checking + savings + credit
console.log('checkingSavings', checking + savings)
function spend(dollars) {
if (checking >= dollars) {
checking -= dollars
console.log('checking:', checking)
} else if (checkingSavings >= dollars) {
var remainingBalance = checkingSavings - dollars
// console.log('remainingBalance', remainingBalance)
checking = 0
savings = (Math.round(remainingBalance * 100) / 100).toFixed(2)
} else if (checkingSavingsCredit >= dollars) {
var remainingBalance = checking + savings + credit - dollars
// console.log('remainingBalance', remainingBalance)
credit = 0
checking = 0
savings = (Math.round(remainingBalance * 100) / 100).toFixed(2)
} else {
console.log('transaction declined')
}
console.log(
`${name} has in savings: ${savings} in checking: ${checking} in credit: ${credit}`
)
}
spend(3000.9)