Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions 01week/datatypes.js
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Hello
1 change: 1 addition & 0 deletions Higher-Order-From-Scratch
Submodule Higher-Order-From-Scratch added at 70bc00
1 change: 1 addition & 0 deletions JS-Sorting-Practice
Submodule JS-Sorting-Practice added at 9c45ce
1 change: 1 addition & 0 deletions JS211_1st-Hackathon
Submodule JS211_1st-Hackathon added at 4cca89
1 change: 1 addition & 0 deletions JS211_ArrayPractice
Submodule JS211_ArrayPractice added at 7de740
17 changes: 17 additions & 0 deletions JS211_BankAccount/.eslintrc.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
{
"extends": "",
"rules": {
"indent": ["error", 2]
},
"env": {
"es6": true,
"mocha": true,
"node": true
},
"parserOptions": {
"ecmaFeatures": {
"jsx": true
}
}
}

11 changes: 11 additions & 0 deletions JS211_BankAccount/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
# Dependencies
node_modules
package-lock.json

# Logs
logs
*.log
npm-debug.log*

# OS artifacts
*.DS_Store
18 changes: 18 additions & 0 deletions JS211_BankAccount/.htmllintrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
{
// names of npm modules to load into htmllint
"plugins": [],
// https://github.com/htmllint/htmllint/wiki/Options
"indent-width": 2,
"line-end-style": false,
"indent-style": "spaces",
"doctype-first": "smart",
"head-req-title": false,
"attr-name-style": "dash",
"class-style": "dash",
"id-class-style": "dash",
"tag-bans": false,
"img-req-alt": false,
"attr-bans": false,
"tag-close": true,
"tag-name-match": true
}
5 changes: 5 additions & 0 deletions JS211_BankAccount/.stylelintrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
{
"rules": {
"indentation": 2
}
}
21 changes: 21 additions & 0 deletions JS211_BankAccount/LICENSE
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
MIT License

Copyright (c) 2020 brightonyoung

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
1 change: 1 addition & 0 deletions JS211_BankAccount/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
# JS211_BankAccount
50 changes: 50 additions & 0 deletions JS211_BankAccount/html.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
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();
}
}


25 changes: 25 additions & 0 deletions JS211_BankAccount/index.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
<html lang="en">

<head>
<meta charset="UTF-8">
<title>Bank Account</title>
<script src="html.js"></script>
</head>

<body>
<div class="container">
<h1>Welcome to the Bank of Brighton</h1>
<p>Please chose one of the following items:</p>
<form action="">
<select id="bank-actions" name="bank actions">
<option value="select" class="select">Select One</option>
<option value="check" class="check">Check Balance</option>
<option value="deposit" class="deposit">Deposit Money</option>
<option value="withdraw" class="withdraw">Withdraw Money</option>
<option value="exit" class="exit">Exit</option>
</select>
</form>
<p id="amount" >$ </p>
</div
</body>

75 changes: 75 additions & 0 deletions JS211_BankAccount/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,75 @@
class BankAccount {

constructor(accountNumber, owner) {
this.accountNumber = accountNumber;
this.owner = owner;
this.transactions = [];
}


deposit(amt){
if (amt < 0) {
return;
} else {
let newDeposit = new Transaction(amt);
this.transactions.push(newDeposit);
}

}

charge(amt, payee) {
if (this.balance() < amt * -1) {
return "Insufficent funds, purchase invalidated";
} else {
let charge = new Transaction(amt, payee);
this.transactions.push(charge);
}
}

balance(){
let balance = 0;
this.transactions.forEach((transaction) => {
balance = balance + transaction.amount;
})

return balance;
}
}



class Transaction {
constructor(amount, payee){
this.date = new Date();
this.amount = amount;
this.payee = payee;
}
}

let account = new BankAccount("1234", "John Smith");

console.log(account)

// balance on new accounts
account.balance() // 0
account.deposit(100) //

console.log("My balance after first deposit", account.balance()) // 100

account.deposit(-100) // 100
console.log("Cannot do a negative deposit", account.balance());

// can charge to a vendor
account.charge(-50, "Target");
console.log("My balance after groceries at Target", account.balance()) // 50

// cannot overcharge
account.charge(-1000, "Diamond Shop")
console.log("Cannont overcharge", account.balance()) // 50

// can do refunds
account.charge(20, "Target");
console.log("I got a $20 refund for part of my groceries", account.balance()) // 70

console.log("My number of transactions is", account.transactions.length) // 3

126 changes: 126 additions & 0 deletions JS211_BankAccount/main.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,126 @@
'use strict';
const assert = require('assert');

class BankAccount {
constructor(accountNumber,owner){
this.accountNumber=accountNumber;
this.owner=owner
this.transactions=[];
this.record=[];
}

balance(){
let sum =this.transactions.reduce((total,amount)=> total+amount);
console.log(sum)
sum=sum.toFixed(2);
return sum; }

deposit(amount){
let newTransaction = new Transaction (amount,this.owner);
this.transactions.push(amount);
this.record.push(newTransaction)
}

charge(payee,amt){

if (amt<this.balance()){
let chargeTransaction = new Transaction (-amt,payee)
this.transactions.push(-amt);
this.record.push(chargeTransaction);
}
else {console.log("not enough Money")}

}
}

////Transaction Class below

class Transaction {
constructor(amount, payee){
this.amount=amount;
this.payee=payee;
this.date=new Date();
}
}

class SavingsAccount extends BankAccount {
constructor (acct, owner, ir){
super (acct,owner)
this.interestrate=ir;
}

accrueInterest(){
const irPayment = this.balance()*this.interestrate;
let interestTrans = new Transaction (irPayment, "Intrest Payment");
this.transactions.push(irPayment);
this.record.push (interestTrans);

}
}


// tests below
if (typeof describe === 'function'){
describe('BankAccount', function(){
it('should have an accountNumber, a owner, and a Transaction.lenght of 0', function(){
const myAccount = new BankAccount('1234abc', 'Mark Pustejovsky');
assert.equal(myAccount.accountNumber, '1234abc');
assert.equal(myAccount.owner, 'Mark Pustejovsky');
assert.equal(myAccount.transactions.length, 0);

});});

describe('BankAccount', function(){
it('should create a several deposits and charges and then the correct balance', function(){
const myAccount = new BankAccount('1234abc', 'Mark Pustejovsky');
myAccount.deposit(1000);
myAccount.charge("Target",30);
myAccount.charge("Amazon",23.4);
myAccount.charge("gearworks", 2000)
myAccount.charge("Ebay",230.3);
myAccount.charge("Store",220);
myAccount.deposit(100.77);
console.log (myAccount.record)
assert.equal(myAccount.accountNumber, '1234abc');
assert.equal(myAccount.owner, 'Mark Pustejovsky');
assert.equal(myAccount.balance(),597.07)
assert.equal(myAccount.record.length, 6)


});});

describe('BankAccount', function(){
it('should create a several deposits and ensure no charge greater than balance can occure', function(){
const myAccount = new BankAccount('1234abc', 'Mark Pustejovsky');
myAccount.deposit(20);
myAccount.charge("Walmart",30);
assert.equal(myAccount.accountNumber, '1234abc');
assert.equal(myAccount.owner, 'Mark Pustejovsky');
assert.equal(myAccount.transactions.length, 1);
assert.equal(myAccount.balance(),20)
});});


describe('BankAccount', function(){
it('should create a several deposits and ensure no charge greater than balance can occure', function(){
const myAccount = new BankAccount('1234abc', 'Mark Pustejovsky');
myAccount.deposit(20);
myAccount.charge("Walmart",30);

assert.equal(myAccount.accountNumber, '1234abc');
assert.equal(myAccount.owner, 'Mark Pustejovsky');
assert.equal(myAccount.transactions.length, 1);
assert.equal(myAccount.balance(),20)
});});

describe('savingAccount', function(){
it('should create a several deposits and ensure no charge greater than balance can occure', function(){
const myAccount2 = new SavingsAccount('1234666', 'Mark Pustejovsky',.1);
myAccount2.deposit(20000);
myAccount2.charge("Walmart",10000);
myAccount2.accrueInterest();
assert.equal(myAccount2.balance(),11000);
});});


}
Loading