forked from AustinCodingAcademy/javascript-workbook
-
Notifications
You must be signed in to change notification settings - Fork 0
Rpm/05week/hw #5
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
r-pm
wants to merge
39
commits into
gh-pages
Choose a base branch
from
rpm/05week/hw
base: gh-pages
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
39 commits
Select commit
Hold shift + click to select a range
748d055
created html css & js files. imported previous tower code for html & css
r-pm 25e390e
set styling
r-pm fbe905f
Create README.md
r-pm 6478eb5
Update README.md
r-pm c3fc181
this is where i was at when i realized i was both trying to create a …
r-pm bad16a4
got my logic down, but need it to be checked
r-pm eb8ae5f
bebugged js. still need to review syntax
r-pm e9d4df4
Merge branch 'rpm/checkpoint1' of https://github.com/r-pm/javascript-…
r-pm 583c924
edits from tutor sesh with emilio. almost there! start is not defined…
r-pm f9cd69f
updated html & css to connect to js more clearly. cleaned up js
r-pm a3302b1
added test code to js. seems to have resolved template code errors - …
r-pm f206c0f
fixed test code. still getting error from template code. will make al…
r-pm 0c13573
more work on test code
r-pm e10e778
welp i solved the template code errors by removing all testing code. …
r-pm 78488d4
ok fixed css so that i can see my game towers & disks. added a wrap t…
r-pm eb1a71b
error for undefined html element. think i went wrong somewhere with e…
r-pm 4bfbeea
terminal app using towersOfHanoi template. finished with code but not…
r-pm 4d7ef20
revised checkpoint code to pass tests. placed variables & parameters.
r-pm 224c914
had a tutor look over my code. they also could not get it to pass tes…
r-pm 9638a30
thiiink i fixed isLegal bug by changing conditionals on arrays & chan…
r-pm 037f5f1
first attempt at function mastermind(). making sense
r-pm 55d03dd
finally passes all tests! cleaned up & reduced code.test for win requ…
r-pm cc7609f
could not figure out how to do nested forEach so need nested for loop…
r-pm 6652ed9
finished nested for loop. can not get it to console log the compariso…
r-pm cf7e49e
welp i cant figure out how to change specific iterations of the strin…
r-pm 63fac4a
sigh. cleaned up code a bit. consolidated for loop functions into one…
r-pm a5ae2ad
higher order loops hw begun
r-pm 723b7fb
hw before tutor sesh. started code with class instructions
r-pm 5c151f3
passed all tests & THEN added a conditional for matching this ships c…
r-pm f8b6d88
pseudo code & filling in classes/methods
r-pm 9f9d4b9
finished methods... need to be checked. started test syntax. need a c…
r-pm a4a276d
finished reducemethod
r-pm e4cf399
notes for higher order funts to use
r-pm 5a54342
have not been able to fit current date into object
r-pm 09aea7e
updated tests. there is an issue with my payee parameter. id like to …
r-pm 1938545
test failing for deposit method
r-pm 5717818
still failing deposit balance test. cant console log what these two m…
r-pm 305d54a
passed test for methods. was missing return outside of reduce functio…
r-pm fdfd812
complete. passed tests. could still use some more tests & stretch
r-pm File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,58 @@ | ||
| // Use a do...while loop to console.log the numbers from 1 to 1000. | ||
| let result = [,]; | ||
| let i = 0; | ||
|
|
||
| do { | ||
| i = i + 1; | ||
| result = result + i; | ||
| } while (i <= 999); | ||
| console.log(result); | ||
|
|
||
| // Create an object (an array with keys and values) called person with the following data: | ||
| let person = { | ||
| firstName: "Jane", | ||
| lastName: "Doe", | ||
| birthDate: "Jan 5, 1925", | ||
| gender: "female" | ||
| } | ||
|
|
||
| // Use a for...in loop and if statement to console.log | ||
| //the value associated with the key birthDate if the birth year is an odd number. | ||
| for(birthDate in person){ | ||
| if(birthDate % 2 !== 0){ | ||
| console.log(person.birthDate); | ||
| }; | ||
| } | ||
|
|
||
| // Create an arrayOfPersons that contains multiple objects. | ||
| //You can simply copy/paste the person object you made above multiple times. | ||
| //Feel free to change the values to reflect multiple people you might have in your database. | ||
| arrayOfPersons = [ | ||
| { | ||
| firstName: "Jane", | ||
| lastName: "Doe", | ||
| birthDate: "Jan 5, 1925", | ||
| gender: "female" | ||
| }, | ||
| { | ||
| firstName: "Bob", | ||
| lastName: "Doe", | ||
| birthDate: "Jan 5, 1925", | ||
| gender: "female" | ||
| }, | ||
| { | ||
| firstName: "Steve", | ||
| lastName: "Doe", | ||
| birthDate: "Jan 5, 1925", | ||
| gender: "female" | ||
| }, | ||
| { | ||
| firstName: "Marcus", | ||
| lastName: "Doe", | ||
| birthDate: "Jan 5, 1925", | ||
| gender: "female" | ||
| }, | ||
| ] | ||
| // Use .map() to map over the arrayOfPersons and console.log() their information. | ||
| // Use .filter() to filter the persons array and console.log only males in the array. | ||
| // Use .filter() to filter the persons array and console.log only people that were born before Jan 1, 1990. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,137 @@ | ||
| 'use strict'; | ||
|
|
||
| let assert = require('assert'); | ||
| // For this assignment we are creating 2 classes that can be used to represent a Bank Account and the transactions it holds. | ||
|
|
||
| class BankAccount { | ||
|
|
||
| constructor(accountNumber, owner){ | ||
| this.accountNumber = accountNumber;//String representing the account number | ||
| this.owner = owner;//String representing the owner of the account | ||
| this.transactions = []; //an array of transactions representing the history of all transactions associated with this account | ||
| //the array will contain entire transaction objects | ||
| } | ||
|
|
||
| balance(){ | ||
| if(this.transactions.length > 0){ | ||
| let balanceAmount = this.transactions.reduce((accumulator, currentValue) => {//reduce() works w literal accumulator & currentValue params, replaced by initial value & next array item | ||
| return accumulator + currentValue.amount;//will add AMOUNT of ea array item to initial value, 0 | ||
| //adds up all transactions[]items using reduce() | ||
| //returns the current balance on the account | ||
| console.log(balanceTotal); | ||
| }, 0); | ||
| return balanceAmount; | ||
| }else{ | ||
| return 0; | ||
| } | ||
|
|
||
| } | ||
|
|
||
| deposit(amount, payee){ | ||
| if (amount > 0){//You should not be able to deposit a negative amount | ||
| let transaction = new Transaction(amount, payee);//creates a new transaction with the payee and amount | ||
| this.transactions.push(transaction);//and add it to the transactions array. | ||
| console.log(this.deposit); | ||
| } | ||
| } | ||
|
|
||
| charge(payee, amount){ | ||
| if ((this.balance - amount) > 0){//You should not be able to charge an amount that would make you balance dip below 0 | ||
| let transaction = new Transaction(amount , payee);//creates a new transaction with the payee and amount | ||
| this.transactions.push(transaction);//and add it to the transactions array. | ||
| }else if(amount < 0){ | ||
| return 'refund'; | ||
| } | ||
|
|
||
| } | ||
|
|
||
| } | ||
|
|
||
| class Transaction{ | ||
| constructor(amount, payee){ | ||
| this.amount = amount;//amount of the transaction. Positive amounts are money going into the account (deposit, refund). Negative amounts are money coming out of the account (a charge, or debit) | ||
| this.payee = payee;//description or payee on the transaction | ||
| this.today = new Date(); | ||
|
|
||
| } | ||
|
|
||
| } | ||
|
|
||
|
|
||
| // Stretch Goal: SavingsAccount Class - This class should extend the BankAccount Class | ||
| // ---------------------------------- | ||
| // 1. The class should have an additional field: | ||
| // a. interestRate - this value represents the rate at which the account earns interest | ||
|
|
||
| // 2. The constructor should take the following as input: | ||
| // a. accountNumber - see BankAccount class | ||
| // b. owner - see BankAccount class | ||
| // c. interestRate - the rate that is used to compute interest | ||
|
|
||
| // 3. Additional methods: | ||
| // a. accrueInterest() - this method should use the balance() to get the current balance, and add a new transaction representing a deposit of the appropriate amount. | ||
|
|
||
|
|
||
|
|
||
|
|
||
| //Tests | ||
| if (typeof describe === 'function'){ | ||
| describe('BankAccount', function(){ | ||
| it('should create a new account with all methods working', function(){//describe | ||
| let acct1 = new BankAccount("5553429", "John Doe");//example passing in | ||
| assert.equal(acct1.accountNumber, '5553429');//keep assert.equal(what im feeding, 'what it expects') | ||
| assert.equal(acct1.owner, 'John Doe');//should return name of owner as provided above | ||
| }); | ||
| }); | ||
| describe('BankAccount', function(){ | ||
| it('should check that balance starts at zero', function(){//describe | ||
| let acct1 = new BankAccount("5553429", "John Doe");//example passing in | ||
| assert.equal(acct1.balance(), 0);//at start, a balance of 0 | ||
| }); | ||
| }); | ||
| describe('BankAccount', function(){ | ||
| it('should receive deposit & update balance', function(){//describe | ||
| let acct1 = new BankAccount("5553429", "John Doe");//example passing in | ||
| acct1.deposit(100, 'me'); | ||
| assert.equal(acct1.balance(), 100);//after deposit, balance should be 100 | ||
|
|
||
| }); | ||
| }); | ||
| describe('BankAccount', function(){ | ||
| it('should display refund for credits to charge', function(){//describe | ||
| let acct1 = new BankAccount("5553429", "John Doe");//example passing in | ||
| assert.equal(acct1.charge("Targé", -20), 'refund'); | ||
| }); | ||
| }); | ||
|
|
||
| } | ||
|
|
||
| // assert.equal(acct1.charge("Targé", -20), 'refund'); | ||
| // acct1.charge("Diamond Shop", 1000) // should not be allowed | ||
| ///testing deposit() | ||
| // acct1.deposit(100) | ||
| // console.log(acct1.balance()): // 100 | ||
|
|
||
| // acct1.deposit(-200) // should not be allowed | ||
| // console.log(acct1.balance()): // 100 | ||
|
|
||
| ///testing charge() | ||
| // acct1.charge("Target", 30.50) | ||
| // acct1.charge("FreeBirds", 15.15) | ||
| // console.log(acct1.balance()) //54.35 | ||
|
|
||
| // console.log(acct1.balance()) //54.35 | ||
|
|
||
| // acct1.charge("Targe", -20) //refund | ||
| // console.log(acct1.balance()) //74.35 | ||
|
|
||
|
|
||
|
|
||
|
|
||
|
|
||
|
|
||
|
|
||
|
|
||
|
|
||
|
|
||
|
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
you do not need to check the crew.length in the if statement because you would not be inside the loop if it wasn't greater than zero