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/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')
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/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 = () => {
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/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 {
rl.question('end stack: ', (endStack) => {
- towersOfHanoi(startStack, endStack);
+ towersOfHanoi(startStack.toLowerCase().trim(), endStack.toLowerCase().trim());
getPrompt();
});
});
@@ -87,7 +108,8 @@ if (typeof describe === 'function') {
});
});
-} else {
+}
+ else {
getPrompt();
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
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(){
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": {