From 2d79fc2ad0d54bf29c89c1376e938b13cc92c4ec Mon Sep 17 00:00:00 2001 From: kevinjj30 Date: Tue, 25 Jun 2019 20:13:19 -0500 Subject: [PATCH 01/11] this is my first commit --- 01week/rockPaperScissors.js | 1 + 1 file changed, 1 insertion(+) 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; From 6d84bb4add15acef5283eb886b8ed17c89b1a991 Mon Sep 17 00:00:00 2001 From: kevinjj30 Date: Tue, 25 Jun 2019 20:35:37 -0500 Subject: [PATCH 02/11] this is my first commit --- 01week/datatypes.js | 2 ++ 1 file changed, 2 insertions(+) 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 + From a73c7a60f6ddbd7b9473dd4a2c414bf126491921 Mon Sep 17 00:00:00 2001 From: kevinjj30 Date: Mon, 1 Jul 2019 20:58:07 -0500 Subject: [PATCH 03/11] tictactoecommit1 --- 02week/tests.js | 9 +++ 03week/ticTacToe.js | 163 +++++++++++++++++++++++++++----------------- 2 files changed, 109 insertions(+), 63 deletions(-) diff --git a/02week/tests.js b/02week/tests.js index e69de29bb..2255aa678 100644 --- a/02week/tests.js +++ b/02week/tests.js @@ -0,0 +1,9 @@ +let double = function(x) { + return x * 2; +}; + +let triple = function(x) { + return x * 2; +}; + +let assert = require; diff --git a/03week/ticTacToe.js b/03week/ticTacToe.js index 1abf5b900..43704dd4e 100644 --- a/03week/ticTacToe.js +++ b/03week/ticTacToe.js @@ -1,93 +1,130 @@ -'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 playerTurn = 'X'; +let board = [[" ", " ", " "], [" ", " ", " "], [" ", " ", " "]]; +let playerTurn = "X"; function printBoard() { - console.log(' 0 1 2'); - console.log('0 ' + board[0].join(' | ')); - console.log(' ---------'); - console.log('1 ' + board[1].join(' | ')); - console.log(' ---------'); - console.log('2 ' + board[2].join(' | ')); + console.log(" 0 1 2"); + console.log("0 " + board[0].join(" | ")); + console.log(" ---------"); + console.log("1 " + board[1].join(" | ")); + console.log(" ---------"); + console.log("2 " + board[2].join(" | ")); } function horizontalWin() { - // Your code here + for (let i = 0; i < board.length; i++) { + if ( + board[i][0] == board[i][1] && + board[i][0] == board[i][2] && + board[i][0] == playerTurn + ) { + return true; + } + } + return false; } function verticalWin() { - // Your code here + for (let i = 0; i < board[0].length; i++) { + if ( + board[0][i] == playerTurn && + board[0][i] == board[1][i] && + board[0][i] == board[2][i] + ) { + return true; + } + } + return false; } function diagonalWin() { - // Your code here + if (board[1][1] == playerTurn) { + if (board[0][0] == playerTurn && board[2][2] == playerTurn) { + return true; + } else if (board[0][2] == playerTurn && board[2][0] == playerTurn) { + return true; + } else return false; + } else return false; } function checkForWin() { - // Your code here + if (horizontalWin() || verticalWin() || diagonalWin()) { + return true; + } else { + return false; + } } function ticTacToe(row, column) { - // Your code here + if (board[row][column] === " ") { + board[row][column] = playerTurn; + } else { + return playerTurn; + } + checkForWin(); + + if (playerTurn == "X") { + playerTurn = "O"; + } else if (playerTurn == "O") { + playerTurn = "X"; + } } function getPrompt() { - printBoard(); - console.log("It's Player " + playerTurn + "'s turn."); - rl.question('row: ', (row) => { - rl.question('column: ', (column) => { - ticTacToe(row, column); - getPrompt(); - }); - }); - + printBoard(); + console.log("It's Player " + playerTurn + "'s turn."); + rl.question("row: ", row => { + rl.question("column: ", column => { + ticTacToe(row, column); + getPrompt(); + }); + }); } - - // Tests -if (typeof describe === 'function') { - - describe('#ticTacToe()', () => { - it('should place mark on the board', () => { - ticTacToe(1, 1); - assert.deepEqual(board, [ [' ', ' ', ' '], [' ', 'X', ' '], [' ', ' ', ' '] ]); - }); - it('should alternate between players', () => { - ticTacToe(0, 0); - assert.deepEqual(board, [ ['O', ' ', ' '], [' ', 'X', ' '], [' ', ' ', ' '] ]); - }); - it('should check for vertical wins', () => { - board = [ [' ', 'X', ' '], [' ', 'X', ' '], [' ', 'X', ' '] ]; - assert.equal(verticalWin(), true); - }); - it('should check for horizontal wins', () => { - board = [ ['X', 'X', 'X'], [' ', ' ', ' '], [' ', ' ', ' '] ]; - assert.equal(horizontalWin(), true); - }); - it('should check for diagonal wins', () => { - board = [ ['X', ' ', ' '], [' ', 'X', ' '], [' ', ' ', 'X'] ]; - assert.equal(diagonalWin(), true); - }); - it('should detect a win', () => { - assert.equal(checkForWin(), true); - }); - }); +if (typeof describe === "function") { + describe("#ticTacToe()", () => { + it("should place mark on the board", () => { + ticTacToe(1, 1); + assert.deepEqual(board, [ + [" ", " ", " "], + [" ", "X", " "], + [" ", " ", " "] + ]); + }); + it("should alternate between players", () => { + ticTacToe(0, 0); + assert.deepEqual(board, [ + ["O", " ", " "], + [" ", "X", " "], + [" ", " ", " "] + ]); + }); + it("should check for vertical wins", () => { + board = [[" ", "X", " "], [" ", "X", " "], [" ", "X", " "]]; + assert.equal(verticalWin(), true); + }); + it("should check for horizontal wins", () => { + board = [["X", "X", "X"], [" ", " ", " "], [" ", " ", " "]]; + assert.equal(horizontalWin(), true); + }); + it("should check for diagonal wins", () => { + board = [["X", " ", " "], [" ", "X", " "], [" ", " ", "X"]]; + assert.equal(diagonalWin(), true); + }); + it("should detect a win", () => { + assert.equal(checkForWin(), true); + }); + }); } else { - - getPrompt(); - + getPrompt(); } From e446f0080df4845bac3fbb3dc33634fc204c7850 Mon Sep 17 00:00:00 2001 From: kevinjj30 Date: Wed, 3 Jul 2019 11:54:25 -0500 Subject: [PATCH 04/11] pigLatinGUI --- 02week/pigLatinGUI/pigLatins.js | 24 ++++++ 02week/pigLatinGUI/piglatin.css | 143 +++++++++++++++++++++++++++++++ 02week/pigLatinGUI/piglatin.html | 62 ++++++++++++++ 3 files changed, 229 insertions(+) create mode 100644 02week/pigLatinGUI/pigLatins.js create mode 100644 02week/pigLatinGUI/piglatin.css create mode 100644 02week/pigLatinGUI/piglatin.html 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..c12c6f90e --- /dev/null +++ b/02week/pigLatinGUI/piglatin.css @@ -0,0 +1,143 @@ +body { + display: grid; + grid-template-columns: 100%; + grid-template-rows: 20% 60% 20%; + width: 100%; + height: 150vh; + margin: 0; + padding: 0; +} + +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: 100px; + width: 800px; +} +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: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; +} + +.flip-card-inner { + position: relative; + width: 100%; + height: 100%; + text-align: center; + transition: transform 0.8s; + transform-style: preserve-3d; +} + +.flip-card:hover .flip-card-inner { + transform: rotateY(180deg); +} + +.flip-card-front, +.flip-card-back { + position: absolute; + width: 100%; + height: 100%; + backface-visibility: hidden; +} + +.flip-card-front { + background-color: #604330; + color: black; + font-size: 20px; + font-family: "Gloria Hallelujah", cursive; + display: flex; + align-items: center; + justify-content: center; +} + +.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; +} 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

+
+
+

+
+
+
+
+ +
+
+ +
+
+ +
+
+ +
+
+ +
+ +
+ + + + + From 7ca0376086f0eb2d441ba3097a082bf5f7b74802 Mon Sep 17 00:00:00 2001 From: kevinjj30 Date: Sat, 6 Jul 2019 11:31:41 -0500 Subject: [PATCH 05/11] final commit --- 02week/pigLatinGUI/piglatin.css | 413 +++++++++++++++++++++++--------- 1 file changed, 304 insertions(+), 109 deletions(-) diff --git a/02week/pigLatinGUI/piglatin.css b/02week/pigLatinGUI/piglatin.css index c12c6f90e..954763aaa 100644 --- a/02week/pigLatinGUI/piglatin.css +++ b/02week/pigLatinGUI/piglatin.css @@ -1,143 +1,338 @@ body { display: grid; grid-template-columns: 100%; - grid-template-rows: 20% 60% 20%; - width: 100%; - height: 150vh; - margin: 0; - padding: 0; + 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>h1{ + font-family: 'Gloria Hallelujah', cursive; + font-size: 45px; + color:black; + + } -header > h2 { - font-family: "Gloria Hallelujah", cursive; - font-size: 30px; - 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; + +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; - background-color: #c3604c; - justify-content: center; - align-items: center; - flex-direction: column; - justify-content: space-around; + +.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; +form{ + font-size:40px; + font-family: 'Gloria Hallelujah', cursive; + position: relative; + } -input { - height: 100px; - width: 800px; +input{ + height:85px; + Width:800px; + border-radius: 10px; + } -input[type="text"] { - font-size: 35px; - font-family: "Gloria Hallelujah", cursive; - text-align: center; +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: ; +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; - background-color: #b09077; - justify-content: center; - align-items: center; - justify-content: space-evenly; +.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; +.foot1:hover{ + color:pink; } -.foot2:hover { - color: pink; +.foot2:hover{ + color:pink; } -.foot3:hover { - color: pink; +.foot3:hover{ + color:pink; } -.foot4:hover { - color: pink; +.foot4:hover{ + color:pink; } -span { - position: relative; - left: 215px; + +span{ + position:relative; + left:215px; } -.flip-card { - background-color: transparent; - width: 500px; - height: 200px; - perspective: 1000px; -} +.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; -.flip-card-inner { - position: relative; - width: 100%; - height: 100%; - text-align: center; - transition: transform 0.8s; - transform-style: preserve-3d; -} + } + + /* 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; -.flip-card:hover .flip-card-inner { - transform: rotateY(180deg); -} + } -.flip-card-front, -.flip-card-back { - position: absolute; - width: 100%; - height: 100%; - backface-visibility: hidden; -} + -.flip-card-front { - background-color: #604330; - color: black; - font-size: 20px; - font-family: "Gloria Hallelujah", cursive; - display: flex; - align-items: center; - justify-content: center; -} + @media (max-width: 575.98px){ -.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; -} + + + + + + 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 From 7d1ba465d6868a27e8a517e6c0f5c07743be53a2 Mon Sep 17 00:00:00 2001 From: kevinjj30 Date: Thu, 11 Jul 2019 06:16:09 -0500 Subject: [PATCH 06/11] 4 test passing --- 03week/towersOfHanoi.js | 149 ++++++++++++++++++++++------------------ 1 file changed, 82 insertions(+), 67 deletions(-) diff --git a/03week/towersOfHanoi.js b/03week/towersOfHanoi.js index 3cf6df049..1b1e1082b 100644 --- a/03week/towersOfHanoi.js +++ b/03week/towersOfHanoi.js @@ -1,94 +1,109 @@ -'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) { + stacks[endStack].push(stacks[startStack].pop()); } -function isLegal() { - // Your code here - +function isLegal(startStack, endStack) { + 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 { + console.log("Invalid move"); + return false; + } } function checkForWin() { - // Your code here - + if (stacks.b.length === 4) { + return true; + } else { + return false; + } } function towersOfHanoi(startStack, endStack) { - // Your code here - + 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(); } From 3c278172623d5ec25b6c0e2047f5236da178cdcf Mon Sep 17 00:00:00 2001 From: kevinjj30 Date: Thu, 11 Jul 2019 11:31:16 -0500 Subject: [PATCH 07/11] added comments to code --- 03week/towersOfHanoi.js | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/03week/towersOfHanoi.js b/03week/towersOfHanoi.js index 1b1e1082b..9622572b2 100644 --- a/03week/towersOfHanoi.js +++ b/03week/towersOfHanoi.js @@ -20,10 +20,12 @@ function printStacks() { } 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(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 @@ -36,12 +38,14 @@ function isLegal(startStack, endStack) { ) { return true; } else { + //illegal moves if does not equal above if statements console.log("Invalid move"); return false; } } function checkForWin() { + //checks for win the second easiest for to me figure it out while writing. if (stacks.b.length === 4) { return true; } else { @@ -50,6 +54,7 @@ function checkForWin() { } function towersOfHanoi(startStack, endStack) { + // 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)) { From bf6cfb27c9374a266d65187b9dd34fef75c9b161 Mon Sep 17 00:00:00 2001 From: kevinjj30 Date: Tue, 23 Jul 2019 10:36:29 -0500 Subject: [PATCH 08/11] first commit test passed --- 04week/mastermind.js | 95 ++++++++++++------------- 05week/spaceTravelToMars.js | 138 +++++++++++++++++++++++------------- 2 files changed, 134 insertions(+), 99 deletions(-) diff --git a/04week/mastermind.js b/04week/mastermind.js index 60e5cfa18..c05ff2c4d 100644 --- a/04week/mastermind.js +++ b/04week/mastermind.js @@ -1,77 +1,76 @@ -'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 + let solutionArray = solution.split(""); + let guessArray = solution.split(""); + let correctLetterLocations = 0; } 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//could be function validinput + let isvalid = true; + if (!guessArr.includes(letters)) isvalid = false; } - 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/spaceTravelToMars.js b/05week/spaceTravelToMars.js index ce258a382..a02282bc5 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."; + } + } +} //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"); + }); + }); } From c29f0e01b945699afa20bc878670e4e2a2bf424c Mon Sep 17 00:00:00 2001 From: kevinjj30 Date: Tue, 23 Jul 2019 10:40:00 -0500 Subject: [PATCH 09/11] final commit test passed --- 05week/spaceTravelToMars.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/05week/spaceTravelToMars.js b/05week/spaceTravelToMars.js index a02282bc5..dccc5b0b4 100644 --- a/05week/spaceTravelToMars.js +++ b/05week/spaceTravelToMars.js @@ -38,7 +38,7 @@ class Ship { } } } - +// testing //tests if (typeof describe === "function") { describe("CrewMember", function() { From 232ff10b159c638d7b3a81c732dd2a968c68ffae Mon Sep 17 00:00:00 2001 From: kevinjj30 Date: Tue, 23 Jul 2019 11:02:26 -0500 Subject: [PATCH 10/11] 4 test passed --- 04week/mastermind.js | 124 ++++++++++++++++++++++++++----------------- 1 file changed, 75 insertions(+), 49 deletions(-) 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(); } From 9a9103584fa91cd1fe28ff10f49cfeac6f658ddc Mon Sep 17 00:00:00 2001 From: kevinjj30 Date: Mon, 5 Aug 2019 18:45:42 -0500 Subject: [PATCH 11/11] final checkers --- 05week/checkers.js | 233 ++++++++++++++++++++++-------------- 07week/API.html | 22 ++++ 07week/api.js | 62 ++++++++++ 08week/fetch/index.html | 59 +++++++-- 09week/hackernews/script.js | 50 ++++++++ 5 files changed, 324 insertions(+), 102 deletions(-) create mode 100644 07week/API.html create mode 100644 07week/api.js 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/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 += ` + +
    +
  • Title: ${post.title}
  • +
  • Body: ${post.title}
  • +
+ `; + }); + + 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 += ' + +//
    +//
  • col
  • + + + +// '; +// }); +// } +// } +// } + +function getAPI(){ + fetch("https://randomuser.me/api/") + .then((res)=> res.json()) + .then((data)=>{ + let output = '

    Api Posts

    ' + data.forEach(function(post){ + output += ' + +
      +
    • col