diff --git a/bankApp.js b/bankApp.js new file mode 100644 index 0000000..ed393a2 --- /dev/null +++ b/bankApp.js @@ -0,0 +1,107 @@ +/** + * Application Name : SudoBank + * + */ +// 1 + +let cash = 100; // 100 +let loan = 0; // 0 +let customer = []; +var totalCustomer = customer.length; +let isBankrupt = false; + +// Add customer +function addCustomer(name, age, profession) { + customer.push({ + name, + profession, + age, + cash: 0, + }); + console.log("Customer added : ", customer[customer.length]); +} + +// Lend money +function lendMoney(customerId, cashAmount) { + // Checking bank balance and verifying customer + if (cash >= cashAmount) { + // Verifying customer identity + if (-1 < customerId && customerId < totalCustomer) { + // Reducing the lend amount from Bank's balance + cash -= cashAmount; + // Adding lend amount to customer cash amount + customer[customerId].cash += cashAmount; + console.log( + `${cashAmount} BDT lend successfully to ${customer[customerId].name}` + ); + } else { + console.log("Sorry ,Invalid customer id provided"); + } + } else { + console.log("Not enough cash in the bank"); + } +} + +// Get or Return money +function returnMoney(customerId, cashAmount) { + // Verifying customer + if (-1 < customerId && customerId < totalCustomer) { + // Adding the returned amount in Bank's balance + cash += cashAmount; + // Reducing return amount from customers cash amount + customer[customerId].cash -= cashAmount; + console.log( + `${customer[customerId].name} returned ${cashAmount} BDT. Left ${customer[customerId].cash} BDT` + ); + } else { + console.log("Sorry ,Invalid customer id provided"); + } +} + +// Bank operation +function operateBank() { + // Display bank status + console.log(`Bank Balance : ${cash} || Lend : ${loan}`); + console.log(customer); + + // Update customer count + totalCustomer = customer.length; + console.log("Total Customer : ", totalCustomer); + + // Action options + alert("Welcome SUDOBANK"); + let action = Number( + prompt( + "What do you want to do ? \n1. Add Customer \n2. Lend Money \n3. Return Money" + ) + ); + // Action + if (action == 1) { + let name = prompt("Customer name : "); + let age = prompt("Customer age : "); + let profession = prompt("Customer profession : "); + + addCustomer(name, age, profession); + } else if (action == 2) { + let customerId = Number(prompt("Customer id : ")); + let cashAmount = Number(prompt("Cash amount : ")); + lendMoney(customerId, cashAmount); + } else if (action == 3) { + let customerId = Number(prompt("Customer id : ")); + let cashAmount = Number(prompt("Cash amount : ")); + returnMoney(customerId, cashAmount); + } else { + console.log("Choose correct action"); + } + + // Checking bankruptcy + if (cash <= 0) { + console.log("We got bankrupt"); + isBankrupt = true; + } +} + +// Operating the bank +while (!isBankrupt) { + operateBank(); +} diff --git a/exercises/arraysorting.js b/exercises/arraysorting.js index d40d935..0a0cdab 100644 --- a/exercises/arraysorting.js +++ b/exercises/arraysorting.js @@ -1,12 +1,27 @@ -// Test you code by forking this repl: -// 👉 - +// Test you code by forking this repl: +// 👉 // Write a function that takes in an array and sort the numbers inside from least to greatest -function sortArray (array) { - +function sortArray(array) { + const nums = new Set(array); + sorted = []; + + nums.forEach(() => { + let max = 0; + for (const num of nums) { + if (max < num) { + max = num; + } + nums.delete(max); + sorted.unshift(max); + max = 0; + } + }); + + return sorted; } -// BONUS sort the array without using .sort() +console.log(sortArray([1, 2, 4, 10, 2, 200])); +// BONUS sort the array without using .sort() diff --git a/functions/sum/exercise/script.js b/functions/sum/exercise/script.js index 69d6b48..177ac99 100644 --- a/functions/sum/exercise/script.js +++ b/functions/sum/exercise/script.js @@ -8,23 +8,39 @@ ES6 Syntax (Arrow function): const add = () => {} */ -function add(){ - //Add function here +function add(n1, n2) { + return n1 + n2; } -function sub(){ - //Subtract function here +const add2 = (n1, n2) => n1 + n2; + +function sub(n1, n2) { + return n1 - n2; } -function div(){ - //Divide function here +const sub2 = (n1, n2) => n1 - n2; + +function div(n1, n2) { + return n1 / n2; } -function mul(){ - //Multiply function here +const div2 = (n1, n2) => n1 / n2; + +function mul(n1, n2) { + return n1 * n2; } -console.log('hello from the SUM exercise') +const mul2 = (n1, n2) => n1 * n2; + +console.log("hello from the SUM exercise"); /* TODO: create a function that console logs the result of any of the above operations. -*/ \ No newline at end of file +*/ +console.log(`Sum of 10 and 20 = ${add(10, 20)}`); +console.log(`Sum of 100 and 200 = ${add2(100, 200)}`); +console.log(`Sub of 10 and 20 = ${sub(10, 20)}`); +console.log(`Sub of 100 and 200 = ${sub2(100, 200)}`); +console.log(`Div of 10 and 20 = ${div(10, 20)}`); +console.log(`Div of 10 and 20 = ${div2(100, 200)}`); +console.log(`Mul of 10 and 20 = ${mul(10, 20)}`); +console.log(`Mul of 10 and 20 = ${mul2(100, 200)}`); diff --git a/index.html b/index.html index a0d6899..c2d4776 100644 --- a/index.html +++ b/index.html @@ -47,11 +47,11 @@