Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit b23b61b

Browse files
committed
done with all the challenges
1 parent 665d2f4 commit b23b61b

File tree

2 files changed

+30
-3
lines changed

2 files changed

+30
-3
lines changed

Week3/challenges/3-password-validation.js

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,4 +20,15 @@ const passwordList = [
2020
{ times: '1-3', letter: 'a', password: 'abcde'},
2121
{ times: '1-3', letter: 'b', password: 'cdefg'},
2222
{ times: '2-9', letter: 'c', password: 'ccccccccc'}
23-
];
23+
];
24+
25+
passwordList.forEach(passwordData => {
26+
const occurrence = passwordData.password.split(passwordData.letter).length - 1;
27+
const [min, max] = passwordData.times.split('-').map(Number);
28+
if (min <= occurrence && occurrence <= max) {
29+
console.log(`${passwordData.password} is VALID, ${passwordData.letter} is present ${occurrence} times and should have been present at least ${min} and at most ${max}`);
30+
}
31+
else {
32+
console.log(`${passwordData.password} is INVALID, ${passwordData.letter} is present ${occurrence} times and should have been present at least ${min} and at most ${max}`);
33+
}
34+
})

Week3/challenges/4-bank-account.js

Lines changed: 18 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,10 +28,26 @@ const bankAccount = {
2828
};
2929

3030
const donateMoney = (amount, onSuccess, onFail) => {
31-
// TODO complete this function
31+
const obj = bankAccount.transactions[0];
32+
if ((bankAccount.currentBalance - amount) < 0) {
33+
onFail()
34+
}
35+
else {
36+
onSuccess()
37+
bankAccount.transactions.push({...obj, prevAmount: bankAccount.currentBalance, newAmount: (bankAccount.currentBalance - amount), reason: "Donation"});
38+
bankAccount.currentBalance = bankAccount.currentBalance - amount;
39+
}
3240
};
3341
const payRent = (amount, onSuccess, onFail) => {
34-
// TODO complete this function
42+
const obj = bankAccount.transactions[0];
43+
if ((bankAccount.currentBalance - amount) < 0) {
44+
onFail()
45+
}
46+
else {
47+
onSuccess()
48+
bankAccount.transactions.push({...obj, prevAmount: bankAccount.currentBalance, newAmount: (bankAccount.currentBalance - amount), reason: "Rent"});
49+
bankAccount.currentBalance = bankAccount.currentBalance - amount;
50+
}
3551
};
3652

3753
/**

0 commit comments

Comments
 (0)