diff --git a/01week/datatypes.js b/01week/datatypes.js index 3a886817a..accbe8db9 100644 --- a/01week/datatypes.js +++ b/01week/datatypes.js @@ -67,5 +67,7 @@ if(!(a>0 && b>0)){ console.log ('Lies'); } + yea + diff --git a/01week/rockPaperScissors.js b/01week/rockPaperScissors.js index 8dd9f3d60..e82d296e4 100644 --- a/01week/rockPaperScissors.js +++ b/01week/rockPaperScissors.js @@ -60,3 +60,4 @@ if (typeof describe === "function") { } else { getPrompt(); } +yea; diff --git a/02week/pigLatin.js b/02week/pigLatin.js index 046434c94..82d6528e8 100644 --- a/02week/pigLatin.js +++ b/02week/pigLatin.js @@ -1,51 +1,59 @@ -'use strict'; +"use strict"; -const assert = require('assert'); -const readline = require('readline'); +const assert = require("assert"); +const readline = require("readline"); const rl = readline.createInterface({ - input: process.stdin, - output: process.stdout + input: process.stdin, + output: process.stdout }); - function pigLatin(word) { - - // Your code here - + word = word.trim().toLowerCase(); + const vowels = ["a", "e", "i", "o", "u"]; + let vowelIndex = 0; + if (vowels.includes(word[0])) { + return word + "yay"; + } else { + for (let char of word) { + if (vowels.includes(char)) { + vowelIndex = word.indexOf(char); + break; + } + } + return word.slice(vowelIndex) + word.slice(0, vowelIndex) + "ay"; + } } - function getPrompt() { - rl.question('word ', (answer) => { - console.log( pigLatin(answer) ); - getPrompt(); - }); + rl.question("word ", answer => { + console.log(pigLatin(answer)); + getPrompt(); + }); } // Tests -if (typeof describe === 'function') { - - describe('#pigLatin()', () => { - it('should translate a simple word', () => { - assert.equal(pigLatin('car'), 'arcay'); - assert.equal(pigLatin('dog'), 'ogday'); - }); - it('should translate a complex word', () => { - assert.equal(pigLatin('create'), 'eatecray'); - assert.equal(pigLatin('valley'), 'alleyvay'); - }); - it('should attach "yay" if word begins with vowel', () => { - assert.equal(pigLatin('egg'), 'eggyay'); - assert.equal(pigLatin('emission'), 'emissionyay'); - }); - it('should lowercase and trim word before translation', () => { - assert.equal(pigLatin('HeLlO '), 'ellohay'); - assert.equal(pigLatin(' RoCkEt'), 'ocketray'); - }); - }); +if (typeof describe === "function") { + describe("#pigLatin()", () => { + it("should translate a simple word", () => { + assert.equal(pigLatin("car"), "arcay"); + assert.equal(pigLatin("dog"), "ogday"); + }); + it("should translate a complex word", () => { + assert.equal(pigLatin("create"), "eatecray"); + assert.equal(pigLatin("valley"), "alleyvay"); + }); + it('should attach "yay" if word begins with vowel', () => { + assert.equal(pigLatin("egg"), "eggyay"); + assert.equal(pigLatin("emission"), "emissionyay"); + }); + it("should lowercase and trim word before translation", () => { + assert.equal(pigLatin("HeLlO "), "ellohay"); + assert.equal(pigLatin(" RoCkEt"), "ocketray"); + }); + }); } else { - - getPrompt(); - + getPrompt(); } + +//testing diff --git a/02week/pigLatinGUI/pigLatins.js b/02week/pigLatinGUI/pigLatins.js new file mode 100644 index 000000000..7b26cca46 --- /dev/null +++ b/02week/pigLatinGUI/pigLatins.js @@ -0,0 +1,24 @@ +"use strict"; + +function pigLatin() { + let newWord = document.getElementById("enterhere").value; + newWord = newWord.trim().toLowerCase(); + const vowels = ["a", "e", "i", "o", "u"]; + + let vowelIndex = 0; + let finish; + + if (vowels.includes(newWord[0])) { + finish = newWord + "yay"; + } else { + for (let char of newWord) { + if (vowels.includes(char)) { + vowelIndex = newWord.indexOf(char); + break; + } + } + + finish = newWord.slice(vowelIndex) + newWord.slice(0, vowelIndex) + "ay"; + } + document.getElementById("output").innerHTML = finish; +} diff --git a/02week/pigLatinGUI/piglatin.css b/02week/pigLatinGUI/piglatin.css new file mode 100644 index 000000000..954763aaa --- /dev/null +++ b/02week/pigLatinGUI/piglatin.css @@ -0,0 +1,338 @@ +body { + display: grid; + grid-template-columns: 100%; + grid-template-rows: 20% 60% 20%; + width: 100%; + height: 150vh; + margin:0; + padding: 0; + background-image: linear-gradient( #966d49, #c3604c, #b09077); +} + + + + + +header>h1{ + font-family: 'Gloria Hallelujah', cursive; + font-size: 45px; + color:black; + + +} + +header>h2{ + font-family: 'Gloria Hallelujah', cursive; + font-size: 30px; + color:black; +} + + +header{ + display:flex; + grid-column: 1/1; + grid-row: 1/2; + justify-content: center; + align-items: center; + flex-direction: column; + + + +} + + +.middle{ + display:flex; + grid-column: 1/1; + grid-row: 2/3; + + justify-content: center; + align-items: center; + flex-direction: column; + justify-content: space-around; +} + +form{ + font-size:40px; + font-family: 'Gloria Hallelujah', cursive; + position: relative; + +} +input{ + height:85px; + Width:800px; + border-radius: 10px; + +} +input[type="text"] +{ + font-size:35px; + font-family: 'Gloria Hallelujah', cursive; + text-align: center; +} +button{ + height:50px; + Width:200px; + font-family: 'Gloria Hallelujah', cursive; + font-size:15px; + background-color:; + border-radius: 10px; +} +.foot{ + display:flex; + grid-column: 1/1; + grid-row: 3/4; + justify-content: center; + align-items: center; + justify-content: space-evenly; + +} +.foot1:hover{ + color:pink; +} + +.foot2:hover{ + color:pink; +} + +.foot3:hover{ + color:pink; +} + +.foot4:hover{ + color:pink; +} + + +span{ + position:relative; + left:215px; +} + + +.flip-card { + background-color: transparent; + width: 500px; + height: 200px; + + perspective: 1000px; /* Remove this if you don't want the 3D effect */ + } + + /* This container is needed to position the front and back side */ + .flip-card-inner { + position: relative; + width: 100%; + height: 100%; + text-align: center; + transition: transform 0.8s; + transform-style: preserve-3d; + } + + /* Do an horizontal flip when you move the mouse over the flip box container */ + .flip-card:hover .flip-card-inner { + transform: rotateY(180deg); + } + + /* Position the front and back side */ + .flip-card-front, .flip-card-back { + position: absolute; + width: 100%; + height: 100%; + backface-visibility: hidden; + + } + + /* Style the front side (fallback if image is missing) */ + .flip-card-front { + background-color: #604330; + color: black; + font-size:20px; + font-family: 'Gloria Hallelujah', cursive; + display:flex; + align-items:center; + justify-content: center; + + border-radius: 10px; + } + + /* Style the back side */ + .flip-card-back { + background-color: #cc9076; + color: black; + transform: rotateY(180deg); + font-size:40px; + display:flex; + align-items:center; + justify-content: center; + font-family: 'Gloria Hallelujah', cursive; + border-radius: 10px; + + } + + + + @media (max-width: 575.98px){ + + + + + + + header>h1{ + font-family: 'Gloria Hallelujah', cursive; + font-size: 45px; + color:black; + + + } + + header>h2{ + font-family: 'Gloria Hallelujah', cursive; + font-size: 30px; + color:black; + } + + + header{ + display:flex; + grid-column: 1/1; + grid-row: 1/2; + justify-content: center; + align-items: center; + flex-direction: column; + background-color: #966d49; + + + } + + + .middle{ + display:flex; + grid-column: 1/1; + grid-row: 2/3; + background-color: #c3604c; + justify-content: center; + align-items: center; + flex-direction: column; + justify-content: space-around; + } + + form{ + font-size:40px; + font-family: 'Gloria Hallelujah', cursive; + position: relative; + + } + input{ + height:80px; + Width:300px; + + } + input[type="text"] + { + font-size:35px; + font-family: 'Gloria Hallelujah', cursive; + text-align: center; + } + button{ + height:50px; + Width:200px; + font-family: 'Gloria Hallelujah', cursive; + font-size:15px; + background-color: + } + .foot{ + display:flex; + grid-column: 1/1; + grid-row: 3/4; + background-color: #b09077; + justify-content: center; + align-items: center; + justify-content: space-evenly; + + } + .foot1{ + + } + + .foot2{ + display:none; + + } + + .foot3:hover{ + + } + + .foot4{ + display:none; + } + + + span{ + position:relative; + left:215px; + } + + + .flip-card { + background-color: transparent; + width: 275px; + height: 200px; + + perspective: 1000px; /* Remove this if you don't want the 3D effect */ + } + + /* This container is needed to position the front and back side */ + .flip-card-inner { + position: relative; + width: 100%; + height: 100%; + text-align: center; + transition: transform 0.8s; + transform-style: preserve-3d; + + } + + /* Do an horizontal flip when you move the mouse over the flip box container */ + .flip-card:hover .flip-card-inner { + transform: rotateY(180deg); + + } + + /* Position the front and back side */ + .flip-card-front, .flip-card-back { + position: absolute; + width: 100%; + height: 100%; + backface-visibility: hidden; + + + } + + /* Style the front side (fallback if image is missing) */ + .flip-card-front { + background-color: #604330; + color: black; + font-size:20px; + font-family: 'Gloria Hallelujah', cursive; + display:flex; + align-items:center; + justify-content: center; + + } + + /* Style the back side */ + .flip-card-back { + background-color: #cc9076; + color: black; + transform: rotateY(180deg); + font-size:40px; + display:flex; + align-items:center; + justify-content: center; + font-family: 'Gloria Hallelujah', cursive; + + } + + } \ No newline at end of file diff --git a/02week/pigLatinGUI/piglatin.html b/02week/pigLatinGUI/piglatin.html new file mode 100644 index 000000000..273bb2ddb --- /dev/null +++ b/02week/pigLatinGUI/piglatin.html @@ -0,0 +1,62 @@ + + + + + + + pigLatin + + + + + + + + +
+

Kevin Jenkins

+

pigLatin

+
+ +
+ + + +
+
+
+

Reveal Answer Here

+
+
+

+
+
+
+
+ +
+
+ +
+
+ +
+
+ +
+
+ +
+ +
+ + + + + diff --git a/03week/towersOfHanoi.js b/03week/towersOfHanoi.js index 3cf6df049..9622572b2 100644 --- a/03week/towersOfHanoi.js +++ b/03week/towersOfHanoi.js @@ -1,94 +1,114 @@ -'use strict'; +"use strict"; -const assert = require('assert'); -const readline = require('readline'); +const assert = require("assert"); +const readline = require("readline"); const rl = readline.createInterface({ - input: process.stdin, - output: process.stdout + input: process.stdin, + output: process.stdout }); let stacks = { - a: [4, 3, 2, 1], - b: [], - c: [] + a: [4, 3, 2, 1], + b: [], + c: [] }; function printStacks() { - console.log("a: " + stacks.a); - console.log("b: " + stacks.b); - console.log("c: " + stacks.c); + console.log("a: " + stacks.a); + console.log("b: " + stacks.b); + console.log("c: " + stacks.c); } -function movePiece() { - // Your code here - +function movePiece(startStack, endStack) { + // This moves the pieces from one stack to another, this function was the easiest part for me. + stacks[endStack].push(stacks[startStack].pop()); } -function isLegal() { - // Your code here - +function isLegal(startStack, endStack) { + //legal moves took the longest for me to understand this alot of googling hack overflow and stack overflow + if ( + stacks[startStack][stacks[startStack].length - 1] === undefined && + stacks[startStack][stacks[endStack].length - 1] === undefined + ) { + return false; + } else if ( + stacks[startStack][stacks[startStack].length - 1] < + stacks[endStack][stacks[endStack].length - 1] || + stacks[endStack][stacks[endStack].length - 1] === undefined + ) { + return true; + } else { + //illegal moves if does not equal above if statements + console.log("Invalid move"); + return false; + } } function checkForWin() { - // Your code here - + //checks for win the second easiest for to me figure it out while writing. + if (stacks.b.length === 4) { + return true; + } else { + return false; + } } function towersOfHanoi(startStack, endStack) { - // Your code here - + // Runs and ends the game. Also removing spacing and capitol letters. + let newStart = startStack.toLowerCase().trim(); + let newEnd = endStack.toLowerCase().trim(); + if (isLegal(startStack, endStack)) { + movePiece(newStart, newEnd); + checkForWin(); + } } function getPrompt() { - printStacks(); - rl.question('start stack: ', (startStack) => { - rl.question('end stack: ', (endStack) => { - towersOfHanoi(startStack, endStack); - getPrompt(); - }); - }); + printStacks(); + rl.question("start stack: ", startStack => { + rl.question("end stack: ", endStack => { + towersOfHanoi(startStack, endStack); + getPrompt(); + }); + }); } // Tests -if (typeof describe === 'function') { - - describe('#towersOfHanoi()', () => { - it('should be able to move a block', () => { - towersOfHanoi('a', 'b'); - assert.deepEqual(stacks, { a: [4, 3, 2], b: [1], c: [] }); - }); - }); - - describe('#isLegal()', () => { - it('should not allow an illegal move', () => { - stacks = { - a: [4, 3, 2], - b: [1], - c: [] - }; - assert.equal(isLegal('a', 'b'), false); - }); - it('should allow a legal move', () => { - stacks = { - a: [4, 3, 2, 1], - b: [], - c: [] - }; - assert.equal(isLegal('a', 'c'), true); - }); - }); - describe('#checkForWin()', () => { - it('should detect a win', () => { - stacks = { a: [], b: [4, 3, 2, 1], c: [] }; - assert.equal(checkForWin(), true); - stacks = { a: [1], b: [4, 3, 2], c: [] }; - assert.equal(checkForWin(), false); - }); - }); - +if (typeof describe === "function") { + describe("#towersOfHanoi()", () => { + it("should be able to move a block", () => { + towersOfHanoi("a", "b"); + assert.deepEqual(stacks, { a: [4, 3, 2], b: [1], c: [] }); + }); + }); + + describe("#isLegal()", () => { + it("should not allow an illegal move", () => { + stacks = { + a: [4, 3, 2], + b: [1], + c: [] + }; + assert.equal(isLegal("a", "b"), false); + }); + it("should allow a legal move", () => { + stacks = { + a: [4, 3, 2, 1], + b: [], + c: [] + }; + assert.equal(isLegal("a", "c"), true); + }); + }); + describe("#checkForWin()", () => { + it("should detect a win", () => { + stacks = { a: [], b: [4, 3, 2, 1], c: [] }; + assert.equal(checkForWin(), true); + stacks = { a: [1], b: [4, 3, 2], c: [] }; + assert.equal(checkForWin(), false); + }); + }); } else { - - getPrompt(); - + getPrompt(); } diff --git a/04week/mastermind.js b/04week/mastermind.js index 60e5cfa18..2f220353d 100644 --- a/04week/mastermind.js +++ b/04week/mastermind.js @@ -1,77 +1,103 @@ -'use strict'; +"use strict"; -const assert = require('assert'); -const readline = require('readline'); +const assert = require("assert"); +const readline = require("readline"); const rl = readline.createInterface({ - input: process.stdin, - output: process.stdout + input: process.stdin, + output: process.stdout }); let board = []; -let solution = ''; -let letters = ['a', 'b', 'c', 'd', 'e', 'f', 'g', 'h']; +let solution = ""; +let letters = ["a", "b", "c", "d", "e", "f", "g", "h"]; function printBoard() { - for (let i = 0; i < board.length; i++) { - console.log(board[i]); - } + for (let i = 0; i < board.length; i++) { + console.log(board[i]); + } } function generateSolution() { - for (let i = 0; i < 4; i++) { - const randomIndex = getRandomInt(0, letters.length); - solution += letters[randomIndex]; - } + for (let i = 0; i < 4; i++) { + const randomIndex = getRandomInt(0, letters.length); + solution += letters[randomIndex]; + } } function getRandomInt(min, max) { - return Math.floor(Math.random() * (max - min)) + min; + return Math.floor(Math.random() * (max - min)) + min; } -function generateHint() { - // your code here +function generateHint(guess) { + // Create variables solutionArray and guessArray that each split up passed in arguments, .splitting on ''(empty string). + let solutionArray = solution.split(""); + let guessArray = guess.split(""); + let correctLetterLocations = 0; + let correctLetters = 0; + + for (var i = 0; i < solutionArray.length; i++) { + if (solutionArray[i] == guessArray[i]) { + correctLetterLocations += 1; + solutionArray[i] = null; + } + } + + for (var i = 0; i < solutionArray.length; i++) { + let targetIndex = solutionArray.indexOf(guessArray[i]); + if (targetIndex > -1) { + correctLetters++; + solutionArray[targetIndex] = null; + } + } + return `${correctLetterLocations}-${correctLetters}`; } function mastermind(guess) { - solution = 'abcd'; // Comment this out to generate a random solution - // your code here + solution = "abcd"; // Comment this out to generate a random solution + // your code here + if (guess === solution) { + console.log("You guessed it!"); + return "You guessed it!"; + } else { + const hint = generateHint(guess); + board.push(`${guess}-${hint}`); + console.log("Try again"); + return "Try again"; + } + userPlays++; } - function getPrompt() { - rl.question('guess: ', (guess) => { - mastermind(guess); - printBoard(); - getPrompt(); - }); + rl.question("guess: ", guess => { + mastermind(guess); + printBoard(); + getPrompt(); + }); } // Tests -if (typeof describe === 'function') { - solution = 'abcd'; - describe('#mastermind()', () => { - it('should register a guess and generate hints', () => { - mastermind('aabb'); - assert.equal(board.length, 1); - }); - it('should be able to detect a win', () => { - assert.equal(mastermind(solution), 'You guessed it!'); - }); - }); - - describe('#generateHint()', () => { - it('should generate hints', () => { - assert.equal(generateHint('abdc'), '2-2'); - }); - it('should generate hints if solution has duplicates', () => { - assert.equal(generateHint('aabb'), '1-1'); - }); - - }); +if (typeof describe === "function") { + solution = "abcd"; + describe("#mastermind()", () => { + it("should register a guess and generate hints", () => { + mastermind("aabb"); + assert.equal(board.length, 1); + }); + it("should be able to detect a win", () => { + assert.equal(mastermind(solution), "You guessed it!"); + }); + }); + describe("#generateHint()", () => { + it("should generate hints", () => { + assert.equal(generateHint("abdc"), "2-2"); + }); + it("should generate hints if solution has duplicates", () => { + assert.equal(generateHint("aabb"), "1-1"); + }); + }); } else { - - generateSolution(); - getPrompt(); + generateSolution(); + getPrompt(); } diff --git a/05week/checkers.js b/05week/checkers.js index 15d9953d1..bed8c88bf 100644 --- a/05week/checkers.js +++ b/05week/checkers.js @@ -1,111 +1,166 @@ -'use strict'; +"use strict"; -const assert = require('assert'); -const readline = require('readline'); +const assert = require("assert"); +const readline = require("readline"); const rl = readline.createInterface({ - input: process.stdin, - output: process.stdout + input: process.stdin, + output: process.stdout }); +class Board { + constructor() { + this.grid = []; + this.checkers = []; + this.redPiece = "X"; + this.blackPiece = "O"; + this.playerTrn = this.blackPiece; + } -function Checker() { - // Your code here -} + initializeGrid() { + for (let row = 0; row < 3; row++) { + for (let column = 0; column < 8; column++) { + if (column % 2 === 1 && row % 2 === 0) { + this.grid[row][column] = this.redPiece; + this.checkers.push(this.redPiece); + } else if (column % 2 === 0 && row % 2 === 1) { + this.grid[row][column] = this.redPiece; + this.checkers.push(this.redPiece); + } + } + } + for (let row = 5; row < 8; row++) { + for (let column = 0; column < 8; column++) { + if (column % 2 === 1 && row % 2 === 0) { + this.grid[row][column] = this.blackPiece; + this.checkers.push(this.blackPiece); + } else if (column % 2 === 0 && row % 2 === 1) { + this.grid[row][column] = this.blackPiece; + this.checkers.push(this.blackPiece); + } + } + } + } + selectChecker(row, col) { + return this.grid[row][col]; + } -class Board { - constructor() { - this.grid = [] - } - // method that creates an 8x8 array, filled with null values - createGrid() { - // loop to create the 8 rows - for (let row = 0; row < 8; row++) { - this.grid[row] = []; - // push in 8 columns of nulls - for (let column = 0; column < 8; column++) { - this.grid[row].push(null); - } - } - } - viewGrid() { - // add our column numbers - let string = " 0 1 2 3 4 5 6 7\n"; - for (let row = 0; row < 8; row++) { - // we start with our row number in our array - const rowOfCheckers = [row]; - // a loop within a loop - for (let column = 0; column < 8; column++) { - // if the location is "truthy" (contains a checker piece, in this case) - if (this.grid[row][column]) { - // push the symbol of the check in that location into the array - rowOfCheckers.push(this.grid[row][column].symbol); - } else { - // just push in a blank space - rowOfCheckers.push(' '); - } - } - // join the rowOfCheckers array to a string, separated by a space - string += rowOfCheckers.join(' '); - // add a 'new line' - string += "\n"; - } - console.log(string); - } + killChecker(position) { + let checker = this.selectChecker(position[0], position[1]); + let indexChecker = this.checkers.indexOf(checker); + this.checkers.splice(indexChecker, 1); + + this.grid[position[0]][position[1]] = null; + } + + // important numbers + // 11 -11 9 -9 1 4 jump + // -22 22 -18 18 2 jump - // Your code here + // method that creates an 8x8 array, filled with null values + createGrid() { + // loop to create the 8 rows + for (let row = 0; row < 8; row++) { + this.grid[row] = []; + // push in 8 columns of nulls + for (let column = 0; column < 8; column++) { + this.grid[row].push(null); + } + } + } + viewGrid() { + // add our column numbers + let string = " 0 1 2 3 4 5 6 7\n"; + for (let row = 0; row < 8; row++) { + // we start with our row number in our array + const rowOfCheckers = [row]; + // a loop within a loop + for (let column = 0; column < 8; column++) { + // if the location is "truthy" (contains a checker piece, in this case) + if (this.grid[row][column]) { + // push the symbol of the check in that location into the array + rowOfCheckers.push(this.grid[row][column]); + } else { + // just push in a blank space + rowOfCheckers.push(" "); + } + } + // join the rowOfCheckers array to a string, separated by a space + string += rowOfCheckers.join(" "); + // add a 'new line' + string += "\n"; + } + console.log(string); + } } +// Your code here class Game { - constructor() { - this.board = new Board; - } - start() { - this.board.createGrid(); - } + constructor() { + this.board = new Board(); + } + start() { + this.board.createGrid(); + this.board.initializeGrid(); + } + moveChecker(start, end) { + const startX = parseInt(start[0]); + const startY = parseInt(start[1]); + const endX = parseInt(end[0]); + const endY = parseInt(end[1]); + + const checker = this.board.selectChecker(start[0], start[1]); + + this.board.grid[endX][endY] = checker; + this.board.grid[startX][startY] = null; + + if (Math.sqrt((endX - startX) ^ (2 + (endY - startY)) ^ 2) >= 2) { + this.board.killChecker([(endX + startX) / 2, (endY + startY) / 2]); + } + } } function getPrompt() { - game.board.viewGrid(); - rl.question('which piece?: ', (whichPiece) => { - rl.question('to where?: ', (toWhere) => { - game.moveChecker(whichPiece, toWhere); - getPrompt(); - }); - }); + game.board.viewGrid(); + rl.question("which piece?: ", whichPiece => { + rl.question("to where?: ", toWhere => { + game.moveChecker(whichPiece, toWhere); + getPrompt(); + }); + }); } +//dont change below const game = new Game(); game.start(); - // Tests -if (typeof describe === 'function') { - describe('Game', () => { - it('should have a board', () => { - assert.equal(game.board.constructor.name, 'Board'); - }); - it('board should have 24 checkers', () => { - assert.equal(game.board.checkers.length, 24); - }); - }); +if (typeof describe === "function") { + describe("Game", () => { + it("should have a board", () => { + assert.equal(game.board.constructor.name, "Board"); + }); + it("board should have 24 checkers", () => { + assert.equal(game.board.checkers.length, 24); + }); + }); - describe('Game.moveChecker()', () => { - it('should move a checker', () => { - assert(!game.board.grid[4][1]); - game.moveChecker('50', '41'); - assert(game.board.grid[4][1]); - game.moveChecker('21', '30'); - assert(game.board.grid[3][0]); - game.moveChecker('52', '43'); - assert(game.board.grid[4][3]); - }); - it('should be able to jump over and kill another checker', () => { - game.moveChecker('30', '52'); - assert(game.board.grid[5][2]); - assert(!game.board.grid[4][1]); - assert.equal(game.board.checkers.length, 23); - }); - }); + describe("Game.moveChecker()", () => { + it("should move a checker", () => { + assert(!game.board.grid[4][1]); + game.moveChecker("50", "41"); + assert(game.board.grid[4][1]); + game.moveChecker("21", "30"); + assert(game.board.grid[3][0]); + game.moveChecker("52", "43"); + assert(game.board.grid[4][3]); + }); + it("should be able to jump over and kill another checker", () => { + game.moveChecker("30", "52"); + assert(game.board.grid[5][2]); + assert(!game.board.grid[4][1]); + assert.equal(game.board.checkers.length, 23); + }); + }); } else { - getPrompt(); + getPrompt(); } diff --git a/05week/spaceTravelToMars.js b/05week/spaceTravelToMars.js index ce258a382..dccc5b0b4 100644 --- a/05week/spaceTravelToMars.js +++ b/05week/spaceTravelToMars.js @@ -1,59 +1,95 @@ -'use strict'; +"use strict"; -let assert = require('assert'); +let assert = require("assert"); let jobTypes = { - pilot: 'MAV', - mechanic: 'Repair Ship', - commander: 'Main Ship', - programmer: 'Any Ship!' + pilot: "MAV", + mechanic: "Repair Ship", + commander: "Main Ship", + programmer: "Any Ship!" }; -// Your code here +class CrewMember { + constructor(name, job, specialSkill, ship) { + this.name = name; + this.job = job; + this.specialSkill = specialSkill; + this.ship = ship; + } + enterShip(ship) { + this.ship = ship; + ship.crew.push(this); + } +} + +class Ship { + constructor(name, type, ability, crew) { + this.name = name; + this.type = type; + this.ability = ability; + this.crew = []; + } + missionStatement() { + if (this.crew.length >= 1) { + return this.ability; + } else { + return "Can't perform a mission yet."; + } + } +} +// testing //tests -if (typeof describe === 'function'){ - describe('CrewMember', function(){ - it('should have a name, a job, a specialSkill and ship upon instantiation', function(){ - var crewMember1 = new CrewMember('Rick Martinez', 'pilot', 'chemistry'); - assert.equal(crewMember1.name, 'Rick Martinez'); - assert.equal(crewMember1.job, 'pilot'); - assert.equal(crewMember1.specialSkill, 'chemistry'); - assert.equal(crewMember1.ship, null); - }); - - it('can enter a ship', function(){ - let mav = new Ship('Mars Ascent Vehicle', 'MAV', 'Ascend into low orbit'); - let crewMember1 = new CrewMember('Rick Martinez', 'pilot', 'chemistry'); - crewMember1.enterShip(mav); - assert.equal(crewMember1.ship, mav); - assert.equal(mav.crew.length, 1); - assert.equal(mav.crew[0], crewMember1); - }); - }); - - describe('Ship', function(){ - it('should have a name, a type, an ability and an empty crew upon instantiation', function(){ - let mav = new Ship('Mars Ascent Vehicle', 'MAV', 'Ascend into low orbit'); - assert.equal(mav.name, 'Mars Ascent Vehicle'); - assert.equal(mav.type, 'MAV'); - assert.equal(mav.ability, 'Ascend into low orbit'); - assert.equal(mav.crew.length, 0); - }); - - it('can return a mission statement correctly', function(){ - let mav = new Ship('Mars Ascent Vehicle', 'MAV', 'Ascend into low orbit'); - let crewMember1 = new CrewMember('Rick Martinez', 'pilot', 'chemistry'); - let hermes = new Ship('Hermes', 'Main Ship', 'Interplanetary Space Travel'); - let crewMember2 = new CrewMember('Commander Lewis', 'commander', 'geology'); - assert.equal(mav.missionStatement(), "Can't perform a mission yet."); - assert.equal(hermes.missionStatement(), "Can't perform a mission yet."); - - crewMember1.enterShip(mav); - assert.equal(mav.missionStatement(), "Ascend into low orbit"); - - crewMember2.enterShip(hermes); - assert.equal(hermes.missionStatement(), "Interplanetary Space Travel"); - }); - }); +if (typeof describe === "function") { + describe("CrewMember", function() { + it("should have a name, a job, a specialSkill and ship upon instantiation", function() { + var crewMember1 = new CrewMember("Rick Martinez", "pilot", "chemistry"); + assert.equal(crewMember1.name, "Rick Martinez"); + assert.equal(crewMember1.job, "pilot"); + assert.equal(crewMember1.specialSkill, "chemistry"); + assert.equal(crewMember1.ship, null); + }); + + it("can enter a ship", function() { + let mav = new Ship("Mars Ascent Vehicle", "MAV", "Ascend into low orbit"); + let crewMember1 = new CrewMember("Rick Martinez", "pilot", "chemistry"); + crewMember1.enterShip(mav); + assert.equal(crewMember1.ship, mav); + assert.equal(mav.crew.length, 1); + assert.equal(mav.crew[0], crewMember1); + }); + }); + + describe("Ship", function() { + it("should have a name, a type, an ability and an empty crew upon instantiation", function() { + let mav = new Ship("Mars Ascent Vehicle", "MAV", "Ascend into low orbit"); + assert.equal(mav.name, "Mars Ascent Vehicle"); + assert.equal(mav.type, "MAV"); + assert.equal(mav.ability, "Ascend into low orbit"); + assert.equal(mav.crew.length, 0); + }); + + it("can return a mission statement correctly", function() { + let mav = new Ship("Mars Ascent Vehicle", "MAV", "Ascend into low orbit"); + let crewMember1 = new CrewMember("Rick Martinez", "pilot", "chemistry"); + let hermes = new Ship( + "Hermes", + "Main Ship", + "Interplanetary Space Travel" + ); + let crewMember2 = new CrewMember( + "Commander Lewis", + "commander", + "geology" + ); + assert.equal(mav.missionStatement(), "Can't perform a mission yet."); + assert.equal(hermes.missionStatement(), "Can't perform a mission yet."); + + crewMember1.enterShip(mav); + assert.equal(mav.missionStatement(), "Ascend into low orbit"); + + crewMember2.enterShip(hermes); + assert.equal(hermes.missionStatement(), "Interplanetary Space Travel"); + }); + }); } diff --git a/07week/API.html b/07week/API.html new file mode 100644 index 000000000..3cce4d72c --- /dev/null +++ b/07week/API.html @@ -0,0 +1,22 @@ + + + + + Fetch + + + + + + +

+ + + + + diff --git a/07week/api.js b/07week/api.js new file mode 100644 index 000000000..1d2e7cf5a --- /dev/null +++ b/07week/api.js @@ -0,0 +1,62 @@ +// // document.getElementById("getAPI").addEventListener('click', getAPI) +// const ul = document.getElementById("authors"); // Get the list where we will place our authors +// const url = "https://randomuser.me/api/?results=10"; +// let data = { +// name: "Sara" +// }; +// // The parameters we are gonna pass to the fetch function +// let fetchData = { +// method: "POST", +// body: data, +// headers: new Headers() +// }; +// fetch(url, fetchData); +// function createNode(element) { +// return document.createElement(element); // Create the type of element you pass in the parameters +// } + +// function append(parent, el) { +// return parent.appendChild(el); // Append the second parameter(element) to the first one +// } + +// // function getAPI(){ +// fetch("https://randomuser.me/api/") +// .then(res => res.json()) +// .then(data => { +// let authors = data.results; // Get the results +// return authors.map(function(author) { +// // Map through the results and for each run the code below +// let li = createNode("li"), // Create the elements we need +// img = createNode("img"), +// span = createNode("span"); +// img.src = author.picture.medium; // Add the source of the image to be the src of the img element +// span.innerHTML = `${author.name.first} ${author.name.last}`; // Make the HTML of our span to be the first and last name of our author +// append(li, img); // Append all our elements +// append(li, span); +// append(ul, li); +// return authors +// }); +// }); + +// document.getElementById("getAPI").innerHTML = output; + +// document.getElementById("getAPI").addEventListener("click", getAPI); + +function getAPI() { + fetch("https://randomuser.me/api/") + .then((res) => res.json()) + .then((data) => { + let output = "

Api Posts

"; + data.forEach(function(post) { + output += ` + + + `; + }); + + document.getElementById("input").innerHTML = output; + }); +} diff --git a/08week/fetch/index.html b/08week/fetch/index.html index 6417d858f..6411e1ae2 100644 --- a/08week/fetch/index.html +++ b/08week/fetch/index.html @@ -1,16 +1,49 @@ - - - Fetch - - - - -
- - - - - + + + Fetch + + + + +
+ + + + + + + + diff --git a/09week/hackernews/script.js b/09week/hackernews/script.js index ad9a93a7c..b1f4cb20e 100644 --- a/09week/hackernews/script.js +++ b/09week/hackernews/script.js @@ -1 +1,51 @@ 'use strict'; +// document.getElementById("getText").addEventListener('click', getText) +// document.getElementById("getJson").addEventListener('click', getJson) +document.getElementById("getAPI").addEventListener('click', getAPI) + + +// function getText(){ +// fetch("text.txt") +// .then(function(data) { +// // console.log(data.text()) +// Return data.text() +// }).then(function(res)){ +// document.getElementById("input").innerHTML= output; +// }) + + +// function getJson(){ +// fetch("color.json") +// .then((res)=> res.json()) +// .then((data)=>{ +// let output = '

Color

' +// data.forEach(function(color){ +// output += ' + +//