Skip to content
Open
Show file tree
Hide file tree
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 Apr 18, 2020
25e390e
set styling
r-pm Apr 19, 2020
fbe905f
Create README.md
r-pm Apr 19, 2020
6478eb5
Update README.md
r-pm Apr 19, 2020
c3fc181
this is where i was at when i realized i was both trying to create a …
r-pm Apr 20, 2020
bad16a4
got my logic down, but need it to be checked
r-pm Apr 20, 2020
eb8ae5f
bebugged js. still need to review syntax
r-pm Apr 20, 2020
e9d4df4
Merge branch 'rpm/checkpoint1' of https://github.com/r-pm/javascript-…
r-pm Apr 20, 2020
583c924
edits from tutor sesh with emilio. almost there! start is not defined…
r-pm Apr 20, 2020
f9cd69f
updated html & css to connect to js more clearly. cleaned up js
r-pm Apr 21, 2020
a3302b1
added test code to js. seems to have resolved template code errors - …
r-pm Apr 21, 2020
f206c0f
fixed test code. still getting error from template code. will make al…
r-pm Apr 21, 2020
0c13573
more work on test code
r-pm Apr 22, 2020
e10e778
welp i solved the template code errors by removing all testing code. …
r-pm Apr 22, 2020
78488d4
ok fixed css so that i can see my game towers & disks. added a wrap t…
r-pm Apr 22, 2020
eb1a71b
error for undefined html element. think i went wrong somewhere with e…
r-pm Apr 22, 2020
4bfbeea
terminal app using towersOfHanoi template. finished with code but not…
r-pm Apr 22, 2020
4d7ef20
revised checkpoint code to pass tests. placed variables & parameters.
r-pm Apr 23, 2020
224c914
had a tutor look over my code. they also could not get it to pass tes…
r-pm Apr 23, 2020
9638a30
thiiink i fixed isLegal bug by changing conditionals on arrays & chan…
r-pm Apr 24, 2020
037f5f1
first attempt at function mastermind(). making sense
r-pm Apr 25, 2020
55d03dd
finally passes all tests! cleaned up & reduced code.test for win requ…
r-pm Apr 25, 2020
cc7609f
could not figure out how to do nested forEach so need nested for loop…
r-pm Apr 26, 2020
6652ed9
finished nested for loop. can not get it to console log the compariso…
r-pm Apr 26, 2020
cf7e49e
welp i cant figure out how to change specific iterations of the strin…
r-pm Apr 26, 2020
63fac4a
sigh. cleaned up code a bit. consolidated for loop functions into one…
r-pm Apr 28, 2020
a5ae2ad
higher order loops hw begun
r-pm Apr 28, 2020
723b7fb
hw before tutor sesh. started code with class instructions
r-pm Apr 28, 2020
5c151f3
passed all tests & THEN added a conditional for matching this ships c…
r-pm Apr 28, 2020
f8b6d88
pseudo code & filling in classes/methods
r-pm Apr 29, 2020
9f9d4b9
finished methods... need to be checked. started test syntax. need a c…
r-pm Apr 30, 2020
a4a276d
finished reducemethod
r-pm Apr 30, 2020
e4cf399
notes for higher order funts to use
r-pm Apr 30, 2020
5a54342
have not been able to fit current date into object
r-pm May 2, 2020
09aea7e
updated tests. there is an issue with my payee parameter. id like to …
r-pm May 3, 2020
1938545
test failing for deposit method
r-pm May 4, 2020
5717818
still failing deposit balance test. cant console log what these two m…
r-pm May 4, 2020
305d54a
passed test for methods. was missing return outside of reduce functio…
r-pm May 4, 2020
fdfd812
complete. passed tests. could still use some more tests & stretch
r-pm May 5, 2020
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
37 changes: 29 additions & 8 deletions 03week/towersOfHanoi.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,24 +19,45 @@ function printStacks() {
console.log("c: " + stacks.c);
}

function movePiece() {
// Your code here
function movePiece(startStack,endStack) {
// console.log(start)
// console.log(end)
let disc = stacks[startStack].pop();
// console.log(disc)
stacks[endStack].push(disc);

}

function isLegal() {
// Your code here

function isLegal(startStack,endStack) {
let start = stacks[startStack];
let end = stacks[endStack];
let startDisc = start[start.length-1];
let endDisc = end[end.length-1];
// console.log(startDisc,endDisc)
if(start.length == 0 ){
return false;
}else if((startDisc < endDisc) ||(end.length == 0)){
return true;
}else{
console.log('invalid, did nothing')
return false;

}

}

function checkForWin() {
// Your code here

if (stacks.b.length === 4 || stacks.c.length === 4){
console.log('win!')
return true;
}else {
return false;
}
}

function towersOfHanoi(startStack, endStack) {
// Your code here

movePiece(startStack,endStack);
}

function getPrompt() {
Expand Down
58 changes: 58 additions & 0 deletions 04week/loop.js
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.
59 changes: 42 additions & 17 deletions 04week/mastermind.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ const rl = readline.createInterface({
});

let board = [];
let solution = '';
let solution =['abcd'];
let letters = ['a', 'b', 'c', 'd', 'e', 'f', 'g', 'h'];

function printBoard() {
Expand All @@ -17,31 +17,56 @@ function printBoard() {
}
}

function generateSolution() {
for (let i = 0; i < 4; i++) {
const randomIndex = getRandomInt(0, letters.length);
solution += letters[randomIndex];
}
}
// function generateSolution() { //creates the randomized solution
// for (let i = 0; i < 4; i++) {
// const randomIndex = getRandomInt(0, letters.length);
// solution += letters[randomIndex];
// }
// }

// function getRandomInt(min, max) { //creates rando interger to use in generate soln?
// return Math.floor(Math.random() * (max - min)) + min;
// }

function getRandomInt(min, max) {
return Math.floor(Math.random() * (max - min)) + min;
}

function generateHint() {
// your code here
function generateHint(guess) {
let countExact = 0;
let countLetter = 0;
// could i have used: for (let i of guess){} ? //
for (let i= 0; i<= guess.length; i++) {
for (let j= 0; j< 4; j++) {//for each [i] of array, compare every [j] of array
if(guess[i] == solution[i]){ //for exact match
countExact ++; //add to count
solution[i] = 'null';//take it off soln [] so it won't be double counted
//add to board [] <- has all the exact matches //<- the test seems to use board.length for hints?


}else if(guess[i] == solution[j]){//for letter only match
countLetter++; //add to count
solution[j] = 'null';//take off solution
// board.push(solution[j]);//add to board [] <- now has all the exact & letter only matches, including doubles, in order:exact,letter
};
return `${countExact} - ${countLetter}`;
};
};
}

function mastermind(guess) {
solution = 'abcd'; // Comment this out to generate a random solution
// your code here

function mastermind(guess) {
// console.log(solution);
if(guess === solution){
console.log('You guessed it!');
}else{
generateHint(guess);
}

}


function getPrompt() {
printBoard();
rl.question('guess: ', (guess) => {
mastermind(guess);
printBoard();
getPrompt();
});
}
Expand Down Expand Up @@ -72,6 +97,6 @@ if (typeof describe === 'function') {

} else {

generateSolution();
// generateSolution();
getPrompt();
}
137 changes: 137 additions & 0 deletions 05week/bankAccount.js
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











41 changes: 40 additions & 1 deletion 05week/spaceTravelToMars.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,46 @@ let jobTypes = {
programmer: 'Any Ship!'
};

// Your code here
//create crewmember class
class CrewMember {
constructor(name, job, specialSkill){
this.name = name;
this.job = job ; //(jobTypes)
this.specialSkill = specialSkill;
this.ship = null;
}

enterShip(anyShip){
// add this.CrewMember
//add entire variable ship & crew
this.ship = anyShip;
anyShip.crew.push(this);
console.log(anyShip)

}

}

class Ship {
constructor(name, type, ability){
this.name = name;
this.type = type;//(jobTypes)
this.ability = ability;
this.crew = [];
}

// this method returns ship's ability IF
missionStatement(){
for(let i = 0; i < this.crew.length; i++){
console.log(jobTypes[this.crew[i].job])
if(this.crew.length > 0 && jobTypes[this.crew[i].job] == this.type){

Copy link
Copy Markdown

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

return this.ability;
}
}
return "Can't perform a mission yet.";
}
}


//tests
if (typeof describe === 'function'){
Expand Down
1 change: 1 addition & 0 deletions 06week/higherOrder.js
Original file line number Diff line number Diff line change
Expand Up @@ -101,3 +101,4 @@ if (typeof describe === 'function') {
console.log('Only run the tests on this one!')

}
I mapped II filter III reduce
Loading