Skip to content

Commit ce6fc44

Browse files
committed
commit
1 parent 6e176de commit ce6fc44

File tree

7 files changed

+68
-17
lines changed

7 files changed

+68
-17
lines changed

09-Data-Structures-Operators/starter/challenge-1.js

Lines changed: 0 additions & 8 deletions
This file was deleted.

11-Arrays-Bankist/.idea/.gitignore

Lines changed: 5 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

11-Arrays-Bankist/.idea/11-Arrays-Bankist.iml

Lines changed: 12 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

11-Arrays-Bankist/.idea/modules.xml

Lines changed: 8 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

11-Arrays-Bankist/.idea/vcs.xml

Lines changed: 6 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

11-Arrays-Bankist/starter/script.js

Lines changed: 36 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ const account4 = {
3636
const account5 = {
3737
owner: 'Genildo Cerqueira Souza',
3838
movements: [50, 350, 1700, 1150, 19090, -5000, -80, -2500, 1690],
39-
interestRate: 3,
39+
interestRate: 0.5,
4040
pin: 5555,
4141
};
4242

@@ -86,27 +86,32 @@ const displayMoviments = function(moviments){
8686

8787
};
8888

89-
displayMoviments(account5.movements)
90-
9189
const calcDisplayBalance = function(movements){
9290
const balance = movements.reduce((acc, mov)=> acc + mov , 0)
9391
labelBalance.textContent = `R$ ${balance}`
9492
}
95-
calcDisplayBalance(account5.movements)
9693

97-
const calcDisplaySummary = function(movements){
98-
const incomes = movements.
94+
95+
const calcDisplaySummary = function(acc){
96+
const incomes = acc.movements.
9997
filter(mov => mov > 0).
10098
reduce((acc, mov) => acc + mov, 0);
10199
labelSumIn.textContent = `R$ ${incomes}`;
102100

103-
const outcomes = movements.
101+
const outcomes = acc.movements.
104102
filter(mov => mov < 0).
105103
reduce((acc, mov)=> acc + mov, 0);
106104
labelSumOut.textContent = `R$ ${Math.abs(outcomes)}`
105+
106+
const interest = acc.movements.filter(mov => mov > 0)
107+
.map((deposit)=> deposit * acc.interestRate/100)
108+
.filter((int, i, arr)=> { return int >= 1})
109+
.reduce((acc, int)=> acc + int,0);
110+
labelSumInterest.textContent = `R$ ${interest}`;
111+
107112
}
108113

109-
calcDisplaySummary(account5.movements);
114+
110115

111116
const createUserNames = function(accs){
112117
accs.forEach((acc)=>{
@@ -120,7 +125,30 @@ const createUserNames = function(accs){
120125
};
121126
createUserNames(accounts)
122127

128+
//Event Handler
129+
let currentAccount;
130+
131+
btnLogin.addEventListener('click', function(e){
132+
e.preventDefault();
133+
134+
currentAccount = accounts.find( acc=> acc.username === inputLoginUsername.value);
123135

136+
if(currentAccount.pin === Number(inputLoginPin.value)){
137+
//Display UI and message
138+
labelWelcome.textContent = `Welcome back, ${currentAccount.owner.split(' ')[0]}`;
139+
}
140+
containerApp.style.opacity = 100;
141+
142+
//clear input fields
143+
inputLoginUsername.value = inputLoginPin.value = '';
144+
inputLoginPin.blur();
145+
//Display movements
146+
displayMoviments(currentAccount.movements);
147+
//Display balance
148+
calcDisplayBalance(currentAccount.movements);
149+
//Display summary
150+
calcDisplaySummary(currentAccount);
151+
})
124152

125153
/////////////////////////////////////////////////
126154
/////////////////////////////////////////////////

11-Arrays-Bankist/starter/style.css

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -94,7 +94,7 @@ nav {
9494
gap: 2rem;
9595

9696
/* NOTE This creates the fade in/out anumation */
97-
/* opacity: 0; */
97+
opacity: 0;
9898
transition: all 1s;
9999
}
100100

0 commit comments

Comments
 (0)