From 9e44785cc5f4499973eac5c5dfd0e93e64c9e274 Mon Sep 17 00:00:00 2001 From: patfitz95 Date: Tue, 24 Mar 2020 19:49:13 -0500 Subject: [PATCH 1/8] My hello world program --- 01week/HelloWorld.js | 2 ++ 1 file changed, 2 insertions(+) create mode 100644 01week/HelloWorld.js diff --git a/01week/HelloWorld.js b/01week/HelloWorld.js new file mode 100644 index 000000000..51e79f2ce --- /dev/null +++ b/01week/HelloWorld.js @@ -0,0 +1,2 @@ +'use strict' +console.log('Hello World') From 8e3dfee1271ed8ddad99994fed1abd668c12ba2b Mon Sep 17 00:00:00 2001 From: patfitz95 Date: Thu, 26 Mar 2020 20:54:08 -0500 Subject: [PATCH 2/8] Completed rock paper scissors trial --- 01week/conditionals.js | 0 01week/rockPaperScissors.js | 11 +++++++++++ package-lock.json | 13 ++++++------- 3 files changed, 17 insertions(+), 7 deletions(-) create mode 100644 01week/conditionals.js diff --git a/01week/conditionals.js b/01week/conditionals.js new file mode 100644 index 000000000..e69de29bb diff --git a/01week/rockPaperScissors.js b/01week/rockPaperScissors.js index 72f0f1a89..46b12c82a 100644 --- a/01week/rockPaperScissors.js +++ b/01week/rockPaperScissors.js @@ -13,6 +13,17 @@ const rl = readline.createInterface({ // the function that will be called by the unit test below const rockPaperScissors = (hand1, hand2) => { + let Hand1 = hand1.toLowerCase().trim(); + let Hand2 = hand2.toLowerCase().trim(); + if(hand1 === hand2) { + return "It's a tie!" + } + else if(Hand1 === "rock" && Hand2 === "scissors" || Hand1 === 'paper' && Hand2 === "rock" || Hand1 === 'scissors' && Hand2 === "paper"){ + return "Hand one wins!" + } + else { + return "Hand two wins!" + } // Write code here // Use the unit test to see what is expected diff --git a/package-lock.json b/package-lock.json index bd07c0e56..9f21138a4 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1728,15 +1728,14 @@ "version": "github:kevincolten/htmllint-cli#5901ac1f6cd612f484f40c7f4f7515f22a2ba52d", "from": "github:kevincolten/htmllint-cli", "requires": { - "bluebird": "^3.4.7", - "chalk": "^1.1.3", + "bluebird": "^3.5.1", + "chalk": "^2.3.0", "cjson": "^0.5.0", "glob": "^7.1.1", - "htmllint": "^0.6.0", - "liftoff": "^2.3.0", - "promise": "^7.1.1", - "semver": "^5.3.0", - "yargs": "^6.6.0" + "htmllint": "^0.7.0", + "liftoff": "^2.5.0", + "semver": "^5.4.1", + "yargs": "^10.0.3" }, "dependencies": { "ansi-styles": { From 7d8be35a5168d2bf1befe4a41fd3c434b99ff93f Mon Sep 17 00:00:00 2001 From: patfitz95 Date: Tue, 7 Apr 2020 16:31:56 -0500 Subject: [PATCH 3/8] Finished pig latin --- 02week/pigLatin.js | 28 ++++++++++++++++++++++++++-- 1 file changed, 26 insertions(+), 2 deletions(-) diff --git a/02week/pigLatin.js b/02week/pigLatin.js index 7f2b58a8a..cc0a438e4 100644 --- a/02week/pigLatin.js +++ b/02week/pigLatin.js @@ -10,9 +10,33 @@ const rl = readline.createInterface({ const pigLatin = (word) => { - // Your code here + let str = word; + // Convert string to lowercase + str = str.toString().toLowerCase(); + // Initialize array of vowels + const vowels = ["a", "e", "i", "o", "u"]; + // Initialize vowel index to 0 + let vowelIndex = 0; + + if (vowels.includes(str[0])) { + // If first letter is a vowel + return str + "yay"; + } else { + // If the first letter isn't a vowel i.e is a consonant + for (let char of str) { + // Loop through until the first vowel is found + if (vowels.includes(char)) { + // Store the index at which the first vowel exists + vowelIndex = str.indexOf(char); + break; + } + } + // Compose final string + return str.slice(vowelIndex) + str.slice(0, vowelIndex) + "ay"; + } + } + -} const getPrompt = () => { From 41b7e5e58a5526f77be4fbebdde14b7252fe91a0 Mon Sep 17 00:00:00 2001 From: patfitz95 Date: Tue, 7 Apr 2020 21:05:51 -0500 Subject: [PATCH 4/8] To do list with the Ui finished --- 03week/todo.html | 21 ++++++++++++++++++ 03week/todo.js | 58 ++++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 79 insertions(+) create mode 100644 03week/todo.html create mode 100644 03week/todo.js diff --git a/03week/todo.html b/03week/todo.html new file mode 100644 index 000000000..26bd2ff1e --- /dev/null +++ b/03week/todo.html @@ -0,0 +1,21 @@ + + + + + + Document + + +

The Best ToDo Tracker

+
    +
+ + + + + + \ No newline at end of file diff --git a/03week/todo.js b/03week/todo.js new file mode 100644 index 000000000..00d619985 --- /dev/null +++ b/03week/todo.js @@ -0,0 +1,58 @@ +console.log("Loaded todo.js file"); +//when the add button gets clicked +// append the text to the bottom of the list + // add a new list item +let addButton = document.getElementById('addButton'); +addButton.addEventListener('click', function(){ + + let inputElement = document.getElementById('inputText'); + let todoText = inputElement.value; + inputElement.value = ''; + let li = document.createElement('li'); + let span =document.createElement('span'); + span.innerText = todoText; + let deleteButton = document.createElement('button'); + deleteButton.innerText = 'delete'; + deleteButton.classList.add('delete'); + + let ul =document.querySelector('ul'); + ul.appendChild(li); + li.appendChild(span); + li.appendChild(deleteButton); + setupDeleteEvent(deleteButton); + setupSpanEvent(span); +}) + +// when a delete button get clicked +// delete its parent list item + +let allDeletes = document.querySelectorAll('.delete'); +for(let i=0; i Date: Tue, 14 Apr 2020 20:00:38 -0500 Subject: [PATCH 5/8] finished to-dochecklist UI --- 02week/tests.js | 14 ++++++++++++++ 03week/Towers.js | 23 +++++++++++++++++++++++ 03week/towersOfHanoi.js | 5 +++-- 3 files changed, 40 insertions(+), 2 deletions(-) create mode 100644 03week/Towers.js diff --git a/02week/tests.js b/02week/tests.js index e69de29bb..ea3636b62 100644 --- a/02week/tests.js +++ b/02week/tests.js @@ -0,0 +1,14 @@ +function longestString(sentence) { + + let sentenceArr = sentence.trim().split(" "); + let longestCandidate = sentenceArr[0]; + for (let i=0; i< sentenceArr.length; i++) { + let currentWord = sentenceArr[i]; + if (currentWord.length > longestCandidate.length) { + longestCandidate = currentWord; + } + } + return longestCandidate; + + } + console.log(longestString("The lazy dog jumped over the brown cow")); \ No newline at end of file diff --git a/03week/Towers.js b/03week/Towers.js new file mode 100644 index 000000000..9d8398edb --- /dev/null +++ b/03week/Towers.js @@ -0,0 +1,23 @@ +let board = { + towerA: [], + towerB: [], + towerC: [] +} + + +board.towerA.push(7); +board.towerC.push(4); +board.towerC.push(1); + +let fromTower = board.towerA; +let toTower = board.towerC; + +// get the last value of the object +let lastFrom = fromTower[fromTower.length-1]; +let lastTo = toTower[toTower.length-1]; + +// move pieces +let poped = fromTower.pop(); +toTower.push(poped); + +console.log(board); \ No newline at end of file diff --git a/03week/towersOfHanoi.js b/03week/towersOfHanoi.js index 3cf6df049..d5e0d2e4e 100644 --- a/03week/towersOfHanoi.js +++ b/03week/towersOfHanoi.js @@ -18,7 +18,7 @@ function printStacks() { console.log("b: " + stacks.b); console.log("c: " + stacks.c); } - +//act function movePiece() { // Your code here @@ -35,7 +35,8 @@ function checkForWin() { } function towersOfHanoi(startStack, endStack) { - // Your code here + let fromStack = stacks[startStack]; + let toStack = stacks[endStack]; } From 18badf7a1a128ef963840c78828e9f98211e39a0 Mon Sep 17 00:00:00 2001 From: patfitz95 Date: Tue, 21 Apr 2020 18:29:03 -0500 Subject: [PATCH 6/8] Towers of Hanoi Finished Code --- .vscode/random/scottie.html | 10 +++++++++ 03week/towersOfHanoi.js | 41 ++++++++++++++++++++++++++++--------- 2 files changed, 41 insertions(+), 10 deletions(-) create mode 100644 .vscode/random/scottie.html diff --git a/.vscode/random/scottie.html b/.vscode/random/scottie.html new file mode 100644 index 000000000..633d2d2df --- /dev/null +++ b/.vscode/random/scottie.html @@ -0,0 +1,10 @@ + + + + + Document + + + + + \ No newline at end of file diff --git a/03week/towersOfHanoi.js b/03week/towersOfHanoi.js index d5e0d2e4e..1449d429a 100644 --- a/03week/towersOfHanoi.js +++ b/03week/towersOfHanoi.js @@ -7,6 +7,7 @@ const rl = readline.createInterface({ output: process.stdout }); + let stacks = { a: [4, 3, 2, 1], b: [], @@ -19,24 +20,43 @@ function printStacks() { console.log("c: " + stacks.c); } //act -function movePiece() { - // Your code here +function movePiece(A, B) { + if (isLegal(A,B)) { + let temp = A[A.length -1]; + B.push(temp); + A.pop(); + } + checkForWin(stacks.a,stacks.b,stacks.c); } - -function isLegal() { - // Your code here - +// source has to be less than the destination +function isLegal(A, B) { + if ((A || B) == null) { + return false; + } + if (B.length == 0){ + return true; + } + if (A[A.length -1]< B[B.length -1]) { + return true; + } else { + return false; + } } -function checkForWin() { - // Your code here +function checkForWin(A, B, C) { + if (A.length == 0 && (B.length == 0 || C.length == 0)) { + console.log('You win!'); + process.exit(0); + } } function towersOfHanoi(startStack, endStack) { let fromStack = stacks[startStack]; let toStack = stacks[endStack]; + console.log(movePiece(fromStack, toStack)); + } @@ -44,7 +64,7 @@ function getPrompt() { printStacks(); rl.question('start stack: ', (startStack) => { rl.question('end stack: ', (endStack) => { - towersOfHanoi(startStack, endStack); + towersOfHanoi(startStack.toLowerCase().trim(), endStack.toLowerCase().trim()); getPrompt(); }); }); @@ -88,7 +108,8 @@ if (typeof describe === 'function') { }); }); -} else { +} + else { getPrompt(); From 0cf594588a00be955838888879fb05a77ac26845 Mon Sep 17 00:00:00 2001 From: patfitz95 Date: Thu, 23 Apr 2020 17:39:51 -0500 Subject: [PATCH 7/8] Higher Order Function Loops assignment --- 04week/loop.js | 57 ++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 57 insertions(+) diff --git a/04week/loop.js b/04week/loop.js index e69de29bb..915e1a2c5 100644 --- a/04week/loop.js +++ b/04week/loop.js @@ -0,0 +1,57 @@ +'use strict' +let Person1 = { + firstName: 'Jane', + lastName: 'Doe', + birthYear: 1925, + gender: 'female' +} +let x = Person1.birthYear +function isOdd(x) { + if (x%2 !== 0){ + return x; + } +} +for (Person1[2] in Person1) { + if (isOdd(x) == x) { + console.log(isOdd(x)); + } +}; +let Person2 = { + firstName: 'Jim', + lastName: 'Boyo', + birthYear: 1928, + gender: 'male' +}; +let Person3 = { + firstName: 'Chad', + lastName: 'Volnie', + birthYear: 1991, + gender: 'male' +}; + +let arrayOfStudents = [Person1, Person2, Person3]; +let mapFunction = function(element, index) { + return ` Name is: ${element.firstName} ${element.lastName} Birth date: ${element.birthYear} gender: ${element.gender}`; +}; +let map = arrayOfStudents.map(mapFunction); +console.log(map); + +let isMaleFilter = function(element, index) { + if (element.gender == 'male') { + return true; + } else { + return false; + } +} +let isMale = arrayOfStudents.filter(isMaleFilter); +console.log('The Males are as follows:', isMale) + +let birthYearFilter = function(element, index) { + if (element.birthYear < 1990) { + return true; + } else { + return false; + } +} +let birthYear = arrayOfStudents.filter(birthYearFilter); +console.log('The people born before Jan 1, 1990 is as follows:', birthYear) \ No newline at end of file From 93e3772234a250e148ec8bf487932099d02b0f05 Mon Sep 17 00:00:00 2001 From: patfitz95 Date: Fri, 24 Apr 2020 14:02:57 -0500 Subject: [PATCH 8/8] pushed all changes on 4/24 --- 04week/mastermind.js | 10 ++-- 05week/Vehicle.js | 95 +++++++++++++++++++++++++++++++++++++ 05week/classes.js | 36 ++++++++++++++ 05week/spaceTravelToMars.js | 33 +++++++++++++ 4 files changed, 171 insertions(+), 3 deletions(-) create mode 100644 05week/Vehicle.js create mode 100644 05week/classes.js diff --git a/04week/mastermind.js b/04week/mastermind.js index 60e5cfa18..efea3ccb4 100644 --- a/04week/mastermind.js +++ b/04week/mastermind.js @@ -33,14 +33,18 @@ function generateHint() { } function mastermind(guess) { - solution = 'abcd'; // Comment this out to generate a random solution - // your code here + let solution = 'abcd'; // Comment this out to generate a random solution + if (guess === solution) { + return 'you guessed it!'; + } else { + return 'that is wrong.'; + } } - function getPrompt() { rl.question('guess: ', (guess) => { mastermind(guess); + console.log(mastermind(guess)) printBoard(); getPrompt(); }); diff --git a/05week/Vehicle.js b/05week/Vehicle.js new file mode 100644 index 000000000..c8c7e22dc --- /dev/null +++ b/05week/Vehicle.js @@ -0,0 +1,95 @@ +'use strict' +// vehicle simulation +// want a class to represent our vehicle +// vehicle should have attributes +// we should be able to add gas to the vehicle +// we should be able to drive for a certain amount of time +// we should be able to query it for the range left + + + + +class Vehicle { + constructor(mpg, color, engineType, gasTankCapacity) { + this.mpg = mpg; + this.color = color; + this.engineType = engineType + this.gasTankCapacity = gasTankCapacity // hold the max capacity of our tank + this.fuelLevel = 0; //holds the current fuel level in gallons + this.mileage = 0; + } + + +// gallons: number of gallons to add to the tank + fuelUp(gallons) { + this.fuelLevel = this.fuelLevel + gallons; + if (this.fuelLevel > this.gasTankCapacity) { + this.fuelLevel = this.gasTankCapacity; + } + if(this.fuelLevel < 0) { + this.fuelLevel = 0; + } + } + // the number of miles you are driving + // want to update the fuel level based on the number of miles driven + drive(miles){ + // distance/mpg gives us the amount of gas consumed + // now that i have the amount of gas consumed, i can subtract it from the fuel level + let gallonsConsumed = miles/this.mpg; + this.fuelLevel = this.fuelLevel - gallonsConsumed; + if(this.fuelLevel < 0) { + this.fuelLevel = 0; + } + } +} + + +// my truck class +// should have a bedsize +// trucks only come in one color which is white +// it should override the drive method, such that if i am carrying cargo, my mpg is reduced by 15% + +class Truck extends Vehicle { + constructor(mpg, engineType, gasTankCapacity, bedSize) { + super(mpg, 'white', engineType, gasTankCapacity); + this.bedSize = bedSize; + this.hasCargo = false; + } + loadUp() { + this.hasCargo = true; + } + unLoad() { + this.hasCargo = false; + } + drive(miles){ + // distance/mpg gives us the amount of gas consumed + // now that i have the amount of gas consumed, i can subtract it from the fuel level + let gallonsConsumed; + if (this.hasCargo){ + gallonsConsumed = miles/(this.mpg * .85) + } else { + gallonsConsumed = miles/this.mpg + } + this.fuelLevel = this.fuelLevel - gallonsConsumed; + if(this.fuelLevel < 0) { + this.fuelLevel = 0; + } + } +} + + + + + + + + +let myJeep = new Vehicle(15,'blue', '5.3 liter', 24); +myJeep.fuelUp(10); // add 10 gallons +myJeep.drive(30); // let us drive 30 miles +console.log(myJeep.fuelLevel); // should be 8 gallons + +let myTruck = new Truck (30, 'electric', 25, 'long'); +myTruck.fuelUp(25); +myTruck.drive(4); +console.log(myTruck.fuelLevel) \ No newline at end of file diff --git a/05week/classes.js b/05week/classes.js new file mode 100644 index 000000000..8d291ecf3 --- /dev/null +++ b/05week/classes.js @@ -0,0 +1,36 @@ +'use strict' + +class Person { + // constructor is a + constructor(n, isMale) { + //console.log('inside the constructor'); + this.age = 21 + if(isMale) { + this.name = n + this.height = 72 + } else { + this.name = n + this.height = 70 + } + } +} + +let guy = new Person('Adam', true) +let gal = new Person('Eve', false) +//console.log('mike =', guy); +//console.log('adam =', gal); + +class Rectangle { + constructor (L, H) { + this.length = L + this.height = H + } + perimeter() { + return (2*this.length) + (2*this.height); + } + area() { + return this.length*this.height + } +} +let Rectangle1 = new Rectangle (10,10) +console.log(Rectangle1, 'perimeter: ', Rectangle1.perimeter(), 'area: ', Rectangle1.area()) \ No newline at end of file diff --git a/05week/spaceTravelToMars.js b/05week/spaceTravelToMars.js index ce258a382..ebf48656a 100644 --- a/05week/spaceTravelToMars.js +++ b/05week/spaceTravelToMars.js @@ -11,6 +11,39 @@ let jobTypes = { // Your code here +// you want to create a CrewMember Class +// constructor should take in as input: name, job, and specialSkill +// have an attribute "ship", this is the ship they are in + +class CrewMember { + constructor() { + + } + // this method should add THIS crewmember to the ship being passed in + // NOTE: an entire ship instance is passed in, not just the name + // NOTE: the entire crewmember is added to the ship's array of crew + enterShip(someShip) { + + } +} + +// you want to create a Ship class +// constructor should take in as input: name, type, ability +// have a list of crew, that starts out empty +// ship should have a "missionStatement()", +// if there is a crew member that can activate it, it should return its ability +// otherwise it should return "Can't perform a mission yet." +class Ship { + constructor() { + + } +// this method should return the ship's ability if there is a crew member +// whose job matches up with the ships type + missionStatement() { + + } +} + //tests if (typeof describe === 'function'){ describe('CrewMember', function(){