From 9e44785cc5f4499973eac5c5dfd0e93e64c9e274 Mon Sep 17 00:00:00 2001 From: patfitz95 Date: Tue, 24 Mar 2020 19:49:13 -0500 Subject: [PATCH 01/11] 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 02/11] 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 03/11] 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 04/11] 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 05/11] 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 06/11] 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 07/11] 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 08/11] 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(){ From 9fc4afa1f49bf4863b19c09f5310196d59e77f34 Mon Sep 17 00:00:00 2001 From: patfitz95 Date: Mon, 4 May 2020 20:28:03 -0500 Subject: [PATCH 09/11] finished sorting.js --- 06week/sorting.js | 107 ++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 107 insertions(+) create mode 100644 06week/sorting.js diff --git a/06week/sorting.js b/06week/sorting.js new file mode 100644 index 000000000..5fa02a729 --- /dev/null +++ b/06week/sorting.js @@ -0,0 +1,107 @@ +'use strict' +const strNums = ["1","4","1","5","9","2","6","5","3","5","8","9","7","9","3","2","3","8","4","6","2","6","4","3","3","8","3","2","7","9","5","0","2","8","8","4","1","9","7","1","6","9","3","9","9","3","7","5","1","0","5","8","2","0","9","7","4","9","4","4","5","9","2","3","0","7","8","1","6","4","0","6","2","8","6","2","0","8","9","9","8","6","2","8","0","3","4","8","2","5","3","4","2","1","1","7","0","6","7","9","8","2","1","4","8","0","8","6","5","1","3","2","8","2","3","0","6","6","4","7","0","9","3","8","4","4","6","0","9","5","5","0","5","8","2","2","3","1","7","2","5","3","5","9","4","0","8","1","2","8","4","8","1","1","1","7","4","5","0","2","8","4","1","0","2","7","0","1","9","3","8","5","2","1","1","0","5","5","5","9","6","4","4","6","2","2","9","4","8","9","5","4","9","3","0","3","8","1","9","6","4","4","2","8","8","1","0","9","7","5","6","6","5","9","3","3","4","4","6","1","2","8","4","7","5","6","4","8","2","3","3","7","8","6","7","8","3","1","6","5","2","7","1","2","0","1","9","0","9","1","4","5","6","4","8","5","6","6","9","2","3","4","6","0","3","4","8","6","1","0","4","5","4","3","2","6","6","4","8","2","1","3","3","9","3","6","0","7","2","6","0","2","4","9","1","4","1","2","7","3","7","2","4","5","8","7","0","0","6","6","0","6","3","1","5","5","8","8","1","7","4","8","8","1","5","2","0","9","2","0","9","6","2","8","2","9","2","5","4","0","9","1","7","1","5","3","6","4","3","6","7","8","9","2","5","9","0","3","6","0","0","1","1","3","3","0","5","3","0","5","4","8","8","2","0","4","6","6","5","2","1","3","8","4","1","4","6","9","5","1","9","4","1","5","1","1","6","0","9","4","3","3","0","5","7","2","7","0","3","6","5","7","5","9","5","9","1","9","5","3","0","9","2","1","8","6","1","1","7","3","8","1","9","3","2","6","1","1","7","9","3","1","0","5","1","1","8","5","4","8","0","7","4","4","6","2","3","7","9","9","6","2","7","4","9","5","6","7","3","5","1","8","8","5","7","5","2","7","2","4","8","9","1","2","2","7","9","3","8","1","8","3","0","1","1","9","4","9","1","2","9","8","3","3","6","7","3","3","6","2","4","4","0","6","5","6","6","4","3","0","8","6","0","2","1","3","9","4","9","4","6","3","9","5","2","2","4","7","3","7","1","9","0","7","0","2","1","7","9","8","6","0","9","4","3","7","0","2","7","7","0","5","3","9","2","1","7","1","7","6","2","9","3","1","7","6","7","5","2","3","8","4","6","7","4","8","1","8","4","6","7","6","6","9","4","0","5","1","3","2","0","0","0","5","6","8","1","2","7","1","4","5","2","6","3","5","6","0","8","2","7","7","8","5","7","7","1","3","4","2","7","5","7","7","8","9","6","0","9","1","7","3","6","3","7","1","7","8","7","2","1","4","6","8","4","4","0","9","0","1","2","2","4","9","5","3","4","3","0","1","4","6","5","4","9","5","8","5","3","7","1","0","5","0","7","9","2","2","7","9","6","8","9","2","5","8","9","2","3","5","4","2","0","1","9","9","5","6","1","1","2","1","2","9","0","2","1","9","6","0","8","6","4","0","3","4","4","1","8","1","5","9","8","1","3","6","2","9","7","7","4","7","7","1","3","0","9","9","6","0","5","1","8","7","0","7","2","1","1","3","4","9","9","9","9","9","9","8","3","7","2","9","7","8","0","4","9","9","5","1","0","5","9","7","3","1","7","3","2","8","1","6","0","9","6","3","1","8","5","9","5","0","2","4","4","5","9","4","5","5","3","4","6","9","0","8","3","0","2","6","4","2","5","2","2","3","0","8","2","5","3","3","4","4","6","8","5","0","3","5","2","6","1","9","3","1","1","8","8","1","7","1","0","1","0","0","0","3","1","3","7","8","3","8","7","5","2","8","8","6","5","8","7","5","3","3","2","0","8","3","8","1","4","2","0","6","1","7","1","7","7","6","6","9","1","4","7","3","0","3","5","9","8","2","5","3","4","9","0","4","2","8","7","5","5","4","6","8","7","3","1","1","5","9","5","6","2","8","6","3","8","8","2","3","5","3","7","8","7","5","9","3","7","5","1","9","5","7","7","8","1","8","5","7","7","8","0","5","3","2","1","7","1","2","2","6","8","0","6","6","1","3","0","0","1","9","2","7","8","7","6","6","1","1","1","9","5","9","0","9","2","1","6","4","2","0","1","9","8","9"]; +// Given 1000 digits of PI as strings, return an array of the digits as numbers +const stringsToNumbs = strNums.map(function(numbers) { + return parseInt(numbers); +}); +console.log(stringsToNumbs); + +// With the same numbers, find the sum of the even values +const evens = stringsToNumbs.filter(function(x) { + return x % 2 === 0; +}); +console.log(evens) +const reducer = (accumulator, currentValue) => accumulator + currentValue; +const sumEvens = evens.reduce(reducer); + +console.log(sumEvens); + +// Find the index of the first value when added to it's index = 512 (#ATX!!) +const atxIdxFunction = stringsToNumbs.forEach(function(element, index){ + if (element+index == 512) { + console.log('index:', index, 'element:', element) + } +}); + +const weather = [ + { id: 5743823523151872, + weather_state_name: "Light Cloud", + weather_state_abbr: "lc", + wind_direction_compass: "NNE", + created: "2018-07-11T20:53:03.251710Z", + applicable_date: "2018-07-11", + min_temp: 14.43, + max_temp: 23.36, + the_temp: 22.785, + wind_speed: 5.682503989556987, + wind_direction: 21.6264939172659, + air_pressure: 1024.45, + humidity: 58, + visibility: 8.683041040324504, + predictability: 70 + }, + { id: 6188149969518592, + weather_state_name: "Heavy Cloud", + weather_state_abbr: "hc", + wind_direction_compass: "NE", + created: "2018-07-11T20:53:03.268190Z", + applicable_date: "2018-07-12", + min_temp: 14.81, + max_temp: 25.52, + the_temp: 24.61, + wind_speed: 3.2461141472739206, + wind_direction: 42.72552812997726, + air_pressure: 1024.605, + humidity: 54, + visibility: 10.633835898353615, + predictability: 71 + }, + { id: 5742049676492800, + weather_state_name: "Showers", + weather_state_abbr: "s", + wind_direction_compass: "E", + created: "2018-07-11T20:53:03.947390Z", + applicable_date: "2018-07-13", + min_temp: 15.5525, + max_temp: 25.3475, + the_temp: 24.175, + wind_speed: 3.6572546846814604, + wind_direction: 90.32910675612557, + air_pressure: 1025.385, + humidity: 57, + visibility: 10.181166984808717, + predictability: 73 + }, + { id: 6696130918219776, + weather_state_name: "Heavy Cloud", + weather_state_abbr: "hc", + wind_direction_compass: "SSW", + created: "2018-07-11T20:53:04.068570Z", + applicable_date: "2018-07-14", + min_temp: 15.915, + max_temp: 27.0925, + the_temp: 26.585, + wind_speed: 3.649847972759087, + wind_direction: 200.04283406736377, + air_pressure: 1024.4450000000002, + humidity: 52, + visibility: 11.14056410562316, + predictability: 71 + }, +] +//using a higher order function, create an array of the unique 'weather_state_name' values of the weather array. Your function should return the following array ['Light Cloud', 'Heavy Cloud', 'Showers'] +let myMapFunction = function(element, index) { + return `${element.weather_state_name}` +}; +const uniqueWeatherStates = [new Set(weather.map(myMapFunction))]; +console.log(uniqueWeatherStates) +//find the id of the object in weather that has a min_temp of 15.915 +let myFilterFunction = function(element, index) { + if (element.min_temp ==15.915){ + return element + } else { + return false; + } +} +const idealTemp = weather.filter(myFilterFunction) +console.log('the weather for ideal temperature is: ',idealTemp) From 6b55675e3ff62b1caaff835fce817e3974e4bce8 Mon Sep 17 00:00:00 2001 From: patfitz95 Date: Thu, 14 May 2020 18:03:04 -0500 Subject: [PATCH 10/11] apiIndex and apiScript finished for choose your api assignment --- 07week/addressIndex.html | 17 ++++++++++++ 07week/addressScript.js | 27 +++++++++++++++++++ 07week/apiAssignment.html | 17 ++++++++++++ 07week/apiAssignment.js | 53 ++++++++++++++++++++++++++++++++++++ 07week/apiIndex.css | 13 +++++++++ 07week/apiIndex.html | 19 +++++++++++++ 07week/apiScript.js | 51 +++++++++++++++++++++++++++++++++++ 07week/index.html | 17 ++++++++++++ 07week/script.js | 56 +++++++++++++++++++++++++++++++++++++++ 9 files changed, 270 insertions(+) create mode 100644 07week/addressIndex.html create mode 100644 07week/addressScript.js create mode 100644 07week/apiAssignment.html create mode 100644 07week/apiAssignment.js create mode 100644 07week/apiIndex.css create mode 100644 07week/apiIndex.html create mode 100644 07week/apiScript.js create mode 100644 07week/index.html create mode 100644 07week/script.js diff --git a/07week/addressIndex.html b/07week/addressIndex.html new file mode 100644 index 000000000..57d457df2 --- /dev/null +++ b/07week/addressIndex.html @@ -0,0 +1,17 @@ + + + + + + Address + + + + + +
+
    + +
+
+ \ No newline at end of file diff --git a/07week/addressScript.js b/07week/addressScript.js new file mode 100644 index 000000000..c49c824f8 --- /dev/null +++ b/07week/addressScript.js @@ -0,0 +1,27 @@ +'use strict' + +window.onload = function() { + console.log('window loaded') + fetchAddressBook(); +} + +function fetchAddressBook(){ + + fetch('https://randomuser.me/api?results=10') + .then(function(response){ + console.log('processing the response') + return response.json(); + }) + .then(function(json){ + console.log('processing the json load') + processContact(json.results) + }) +} + + +function processContact(contacts) { + console.log('contact size = ',contacts.length) + contacts.forEach(function(contact) { + + }) +} \ No newline at end of file diff --git a/07week/apiAssignment.html b/07week/apiAssignment.html new file mode 100644 index 000000000..39d3973c0 --- /dev/null +++ b/07week/apiAssignment.html @@ -0,0 +1,17 @@ + + + + + + API + + + hello + + +
+
    + +
+
+ \ No newline at end of file diff --git a/07week/apiAssignment.js b/07week/apiAssignment.js new file mode 100644 index 000000000..5f59fec75 --- /dev/null +++ b/07week/apiAssignment.js @@ -0,0 +1,53 @@ +'use strict' + +console.log("loading script.js file") + +window.onload = function() { + console.log("window loaded") + getPosts() +} + +let getPosts = function() { + console.log("Inside the post method, about to make a fetch request") + let fetchPromise = + fetch('http://jsonplaceholder.typicode.com/posts') + .then(function(response) { + + if(!response.ok) { + throw Error("Server said no"); + } + console.log("The packaging of the amazon item has arrived", response) + return response.json() + + }) + .then(function(data) { + console.log("We have opened the packaging and the item/data is here! data =", data) + data.forEach(updateHtml) + }).catch(function(error){ + alert("Something went wrong!") + }) + console.log("Request sent off...") +} + +let updateHtml = function(post) { + console.log("Updating the HTML for posts = ", post) + let postsUl = document.getElementById("posts") + + let postLi = document.createElement("li") + postLi.innerText = post.title + postsUl.appendChild(postLi) + + let userNameSpan = document.createElement("span") + userNameSpan.innerText = " - by " +post.userid + postLi.append(userNameSpan) + +} + +const li = document.createElement("li") + const button = document.createElement("button") + button.innerHTML = "Make Player" + button.addEventListener('click', function() { + makePlayer(person) + removeFromList(button) + }) + li.appendChild(button) \ No newline at end of file diff --git a/07week/apiIndex.css b/07week/apiIndex.css new file mode 100644 index 000000000..30706859d --- /dev/null +++ b/07week/apiIndex.css @@ -0,0 +1,13 @@ +h1 { + color: Green; + text-align: center; + +} +body { + background-color: grey; + color : whitesmoke +} +ul { + list-style-type: decimal; + display: none; +} diff --git a/07week/apiIndex.html b/07week/apiIndex.html new file mode 100644 index 000000000..f558c753a --- /dev/null +++ b/07week/apiIndex.html @@ -0,0 +1,19 @@ + + + + + + APIProject + + + +

Welcome to the POE League descriptor

+ + + +
+
    + +
+
+ \ No newline at end of file diff --git a/07week/apiScript.js b/07week/apiScript.js new file mode 100644 index 000000000..e9c6ac56c --- /dev/null +++ b/07week/apiScript.js @@ -0,0 +1,51 @@ +'use strict' + +console.log('hello world'); + + +window.onload = function() { +console.log('window loaded') +getLeague() +} +let getLeague = function(){ + let fetchPromise = fetch("http://api.pathofexile.com/leagues"); + + let dataPromise = fetchPromise.then(function(response){ + console.log(response); + return response.json() + }) + + dataPromise.then(function(data){ + console.log('got my data', data); + data.forEach(updateHtml); + }); + console.log('request sent off....') +} +let updateHtml = function(league){ + console.log('updating the html for league=', league); + let leagueUl = document.getElementById('league'); + let leagueLi = document.createElement('li'); + + + + leagueLi.innerText = league.id; + leagueUl.appendChild(leagueLi); + + let leagueId = league.description; + let userSpan = document.createElement('span'); + userSpan.innerText = ` + + Description of the league: ${leagueId} + + `; + leagueLi.appendChild(userSpan); + +} +let hideDisplay = function() { + let x = document.getElementById("league"); + if (x.style.display === "block") { + x.style.display = "none"; + } else { + x.style.display = "block"; + } + } \ No newline at end of file diff --git a/07week/index.html b/07week/index.html new file mode 100644 index 000000000..5da7916cc --- /dev/null +++ b/07week/index.html @@ -0,0 +1,17 @@ + + + + + + Document + + + hello fetch! + + +
+
    + +
+
+ \ No newline at end of file diff --git a/07week/script.js b/07week/script.js new file mode 100644 index 000000000..26e09d22e --- /dev/null +++ b/07week/script.js @@ -0,0 +1,56 @@ +'use strict' + +console.log('hello world'); + + +window.onload = function() { +console.log('window loaded') +console.log(getPosts()) +} + +document.onload = function() { + +} + +let getPosts = function(){ + console.log() + let fetchPromise = fetch("http://jsonplaceholder.typicode.com/posts"); + + let dataPromise = fetchPromise.then(function(response){ + console.log(response); + return response.json() + }) + + dataPromise.then(function(data){ + console.log('got my data! data.length: ', data.length); + data.forEach(updateHtml); + }); + console.log('request sent off....') +} + +let fetchedUsers = {}; + +let updateHtml = function(post){ + console.log('updating the html for post=', post); + let postsUl = document.getElementById('posts'); + let postLi = document.createElement('li'); + + + + postLi.innerText = post.title; + postsUl.appendChild(postLi); + + let userId = post.Id; + let userSpan = document.createElement('span'); + userSpan.innerText = " - by"+userId; + postLi.append(userSpan); + + fetch('http://jsonplaceholder.typicode.com/users/'+userId) + .then(function(response){ + return response.json() + }) + .then(function(data){ + fetchedUsers[userId] = data; + userSpan.innerText = ' - by'+data.name; + }) +} \ No newline at end of file From 740085ff40fd4c845d227f35b4d24b680bfbe7e3 Mon Sep 17 00:00:00 2001 From: patfitz95 Date: Fri, 15 May 2020 16:23:43 -0500 Subject: [PATCH 11/11] finished dodgeball checkpoint --- .vscode/DodgeballCP/DCPindex.html | 29 +++++ .vscode/DodgeballCP/DCPscript.js | 175 ++++++++++++++++++++++++++++++ .vscode/DodgeballCP/README.md | 10 ++ .vscode/DodgeballCP/TEST.md | 5 + 4 files changed, 219 insertions(+) create mode 100644 .vscode/DodgeballCP/DCPindex.html create mode 100644 .vscode/DodgeballCP/DCPscript.js create mode 100644 .vscode/DodgeballCP/README.md create mode 100644 .vscode/DodgeballCP/TEST.md diff --git a/.vscode/DodgeballCP/DCPindex.html b/.vscode/DodgeballCP/DCPindex.html new file mode 100644 index 000000000..03b85fae9 --- /dev/null +++ b/.vscode/DodgeballCP/DCPindex.html @@ -0,0 +1,29 @@ + + + + + + + Dodge Ball + + +
+

List Of People

+
    +
    + +
    +

    Dodge Ball Players

    +
      +
      +
      +

      Blue Team

      +
        +
        +
        +

        Red Team

        +
          +
          + + + \ No newline at end of file diff --git a/.vscode/DodgeballCP/DCPscript.js b/.vscode/DodgeballCP/DCPscript.js new file mode 100644 index 000000000..ba25c5b70 --- /dev/null +++ b/.vscode/DodgeballCP/DCPscript.js @@ -0,0 +1,175 @@ +'use strict' +const arrOfPeople = [ + { + id: 2, + name: "Charles Young", + age: 55, + skillSet: "welding", + placeBorn: "Omaha, Nebraska" + }, + { + id: 3, + name: "Judy Twilight", + age: 35, + skillSet: "fishing", + placeBorn: "Louisville, Kentucky" + }, + { + id: 4, + name: "Cynthia Doolittle", + age: 20, + skillSet: "tic tac toe", + placeBorn: "Pawnee, Texas" + }, + { + id: 5, + name: "John Willouby", + age: 28, + skillSet: "pipe fitting", + placeBorn: "New York, New York" + }, + { + id: 6, + name: "Stan Honest", + age: 20, + skillSet: "boom-a-rang throwing", + placeBorn: "Perth, Australia" + }, + { + id: 7, + name: "Mia Watu", + age: 17, + skillSet: "acrobatics", + placeBorn: "Los Angeles, California" + }, + { + id: 8, + name: "Walter Cole", + age: 32, + skillSet: "jump rope", + placeBorn: "New Orleans, Louisiana" + }, + ] + + const listOfPlayers = [] + const blueTeam = [] + const redTeam = [] + // creating player class + class player { + constructor(name, age, skillSet){ + this.name = name + this.age = age + this.skillSet = skillSet + this.placeBorn = this.placeBorn + } + // adding the class to the people of the array + addToArrayOfPeople() { + arrOfPeople.push(this) + } + } + // creating blue team class + class blueTeammate extends player { + constructor(name, age, skillSet, placeBorn, team){ + super (name, age, skillSet, placeBorn); + this.team = team + this.color = blue + this.mascot = Sky + } + // adding the class and attributes to the people of the blue team array + joinTeam() { + if (this.team === 'blue') { + blueTeam.push(this.name) + } + } + } + // creating red team class + class redTeammate extends player { + constructor(name, age, skillSet, placeBorn, team,){ + super (name, age, skillSet, placeBorn); + this.team = team + this.color = red + this.mascot = Tomato + } + // adding the class and attributes to the people of the red team array + joinTeam() { + if (this.team === 'red') { + redTeam.push(this.name) + } + } + } + const listPeopleChoices = () => { + const listElement = document.getElementById('people') + arrOfPeople.map(person => { + const li = document.createElement("li") + const button = document.createElement("button") + button.innerHTML = "Make Player" + button.addEventListener('click', function() { + makePlayer(person) + removeFromList(button) + }) + li.appendChild(button) + li.appendChild(document.createTextNode(person.name + " - " + person.skillSet)) + listElement.append(li) + }) + } + //creating a function that removes people from the List People list + const removeFromList = (button) => { + const parentLi = button.parentElement + parentLi.remove() + } + // creating a function that removes people and buttons from the bodgeball players list + const removeFromSort = (li, redButton, blueButton) => { + li.remove() + redButton.remove() + blueButton.remove() + } + // creating a function that adds people to the red team and pushes the redTeam class and its attributes onto them by adding them to the redTeam array + const joinRed = (person) => { + const red = document.getElementById('red') + const li = document.createElement('li') + li.innerHTML = `${person.name}` + red.append(li) + redTeam.push(person.name) + } + // creating a function that adds people to the blue team and pushes the blueTeam class and its attributes onto them by adding them to the blueTeam array + const joinBlue = (person) => { + const blue = document.getElementById('blue') + const li = document.createElement('li') + li.innerHTML = `${person.name}` + blue.append(li) + blueTeam.push(person.name) + } + + // creating players + const makePlayer = (player) => { + console.log(`li ${player.id} was clicked!`) + // finding people in the array who's id's match those of the people who were clicked + const person = arrOfPeople.find((p)=> { + console.log(p) + return p.id === player.id; + }) + const listElement = document.getElementById("players") + const li = document.createElement('li') + li.appendChild((document.createTextNode(person.name + " - " + person.skillSet))) + listOfPlayers.push(player) + console.log('this is the new list of players', listOfPlayers) + // making a button for the red team that adds them to the red team when clicked + const redButton = document.createElement('button') + redButton.innerHTML = 'Red Team' + redButton.classList.add('red') + redButton.addEventListener('click', function() { + removeFromSort(li, redButton, blueButton) + joinRed(person) + }) + // making a button for the blue team that adds them to the blue team when clicked + const blueButton = document.createElement('button') + blueButton.innerHTML = 'Blue Team' + blueButton.classList.add('blue') + blueButton.addEventListener('click', function() { + removeFromSort(li, blueButton, redButton) + joinBlue(person) + }) + // adding the buttons to the ul + listElement.append(li,blueButton, redButton) + } + diff --git a/.vscode/DodgeballCP/README.md b/.vscode/DodgeballCP/README.md new file mode 100644 index 000000000..0fc8dfda8 --- /dev/null +++ b/.vscode/DodgeballCP/README.md @@ -0,0 +1,10 @@ + Overview: +We are in need of a sorting and organizing app for our community dodge ball league. There are already 6 players signed up and we hope to get more! We need to select from our currently sign-up people to make them dodge ball players and from there we need to be able to select them to be on different teams. Please look over the Specs Checklist to make sure you understand the needs of this app. + +Starting out there is 4 arrays in the problem. One is the array of people we are given at the beginning, then there is the list of players array (which is empty), the blue team array (which is empty), and the red team array (which is empty). + Plan: +If you load the webpage the first time the only thing is a button that says list people, when you click it, it creates and populates the list of people and their skill set shown in the DOM. Clicking this will also create a 'Make Player' button next to each persons name. + +My first step would be adding attributes to the different classes such as Player, and extending those attributes to the BlueTeammate and RedTeammate while also adding new attributes to the different teams such as color and mascot. + +My second step to creating this program is going to be giving the make player function, functionality. We need a few things to happen when the button is clicked. When the button is clicked we need it to add the persons name to the dodgeball players list and create 2 buttons next to their name that say "red team" or "blue team" while also taking the original name and button away in the list of people list. Then behind the scenes, when the button is clicked we want to take the player off of the arrOfPeople array and add them to the list of players array. We need to add functionality to the Red Team and Blue Team buttons, so that when they are clicked it will then add the player to the corresponding team list in the DOM while also taking them and the two team buttons off the list of dodgeball players in the DOM. Again behind the scenes we need to make sure the player is added to the corresponding array for the team they are selected onto. \ No newline at end of file diff --git a/.vscode/DodgeballCP/TEST.md b/.vscode/DodgeballCP/TEST.md new file mode 100644 index 000000000..42d017772 --- /dev/null +++ b/.vscode/DodgeballCP/TEST.md @@ -0,0 +1,5 @@ +1. Once a person is moved to the dodgeball players list in the DOM, console log the listOfPlayers array and open the console to see if the person was moved and if they have inherited the class 'Player' attributes. + +2. Once a person is moved to the red team list in the DOM, console log the redTeammate array and open the console to see if the person was moved and if they have inherited the class 'redTeam' attributes. + +3. Once a person is moved to theblue team list in the DOM, console log the blueTeammatearray and open the console to see if the person was moved and if they have inherited the class 'blueTeam' attributes. \ No newline at end of file