diff --git a/03week/PigLatin.css b/03week/PigLatin.css
new file mode 100644
index 000000000..263157bd8
--- /dev/null
+++ b/03week/PigLatin.css
@@ -0,0 +1,61 @@
+body {
+ background: sandybrown;
+}
+
+div.title {
+ display: flex;
+ justify-content: center;
+ grid-area: title;
+ background: red;
+ width: auto;
+ height: auto;
+ margin: 10px;
+}
+
+input.input {
+ padding: 10px;
+ font-size: 25px;
+}
+
+p {
+ font-size: 25px;
+}
+
+h1 {
+ font-family: Arial, Helvetica, sans-serif;
+}
+
+div.input {
+ display: flex;
+ justify-content: center;
+ grid-area: input;
+}
+
+div.button {
+ display: flex;
+ justify-content: center;
+ grid-area: button;
+}
+div.output {
+ display: flex;
+ justify-content: center;
+ grid-area: output;
+}
+
+#pigLatinText {
+ color: red;
+ font-family: "Times New Roman", Times, serif;
+ padding: 10px;
+ font-size: 50px;
+}
+
+main {
+ display: grid;
+ grid-row-gap: 35px;
+ grid-template-columns: 1 fr;
+ grid-template-areas:
+ "title"
+ "input"
+ "button"
+ "output";
+}
diff --git a/03week/PigLatin.html b/03week/PigLatin.html
new file mode 100644
index 000000000..bdcb4e9be
--- /dev/null
+++ b/03week/PigLatin.html
@@ -0,0 +1,25 @@
+
+
+
+
+
+
+ Document
+
+
+
+
+
+ Pig Latin Translator
+
+
+
+
+
+
+
+
+
+
+
+
diff --git a/03week/PigLatin.js b/03week/PigLatin.js
new file mode 100644
index 000000000..6c420ebda
--- /dev/null
+++ b/03week/PigLatin.js
@@ -0,0 +1,119 @@
+"use strict";
+
+// const assert = require("assert");
+// const readline = require("readline");
+// const rl = readline.createInterface({
+// input: process.stdin,
+// output: process.stdout
+// });
+
+//RULES OF PIG LATIN:
+//if starts with a vowel add "yay" to end
+//if word does not have a vowel add "ay" to the end
+//if word has vowel, split word before first vowel, switch halves, and add "ay" to the end
+
+function pigLatin(word) {
+ word = word.trim().toLowerCase(); //sets word to lowercase
+ let vowels = ["a", "e", "i", "o", "u"]; //array is created to compare with characters of word
+ let i; //variables are declared to run tests
+ let hasvowel = false;
+ let substring;
+
+ if (
+ //tests to see if first character of word is vowel
+ word[0] == vowels[0] ||
+ word[0] == vowels[1] ||
+ word[0] == vowels[2] ||
+ word[0] == vowels[3] ||
+ word[0] == vowels[4]
+ ) {
+ word = word.concat("yay");
+ hasvowel = true;
+ } else {
+ //runs if first character is not a vowerl
+ for (i = 0; i < word.length && hasvowel == false; i++) {
+ if (
+ //tests to see if any character in string is a vowel
+ word[i] == vowels[0] ||
+ word[i] == vowels[1] ||
+ word[i] == vowels[2] ||
+ word[i] == vowels[3] ||
+ word[i] == vowels[4]
+ ) {
+ //if test returns true substring gets valued assigned and is concated to word. Word is then sliced as needed and concated with 'ay'
+ substring = word.substring(0, i);
+ word = word.concat(substring);
+ word = word.slice(i, word.length);
+ word = word.concat("ay");
+ hasvowel = true;
+ }
+ }
+ for (i = 0; i < word.length && hasvowel == false; i++) {
+ if (
+ //tests to see if no characters are vowels, which should run if the first two test return false. Will concate 'ay' if test returns true
+ word[i] !== vowels[0] &&
+ word[i] !== vowels[1] &&
+ word[i] !== vowels[2] &&
+ word[i] !== vowels[3] &&
+ word[i] !== vowels[4]
+ ) {
+ word = word.concat("ay");
+ hasvowel = true;
+ }
+ }
+ }
+ //modified word gets returned
+ return word;
+
+ // Your code here
+}
+
+function getPrompt() {
+ rl.question("word ", answer => {
+ console.log(pigLatin(answer));
+ getPrompt();
+ });
+}
+
+function handleTranslate() {
+ console.log("I am inside handleTranslate()");
+
+ //1. get the input value from the inputbox
+ var inputBox = document.getElementById("plainText");
+ console.log(inputBox);
+ var englishWord = inputBox.value;
+ console.log("english word", englishWord);
+
+ //2. call the pigLatin function with this value
+ var pigLatinWord = pigLatin(englishWord);
+ console.log("pig latin word ", pigLatinWord);
+ //3. write teh result that the piglatinfunction returns to the screen
+ var spanElement = document.getElementById("pigLatinText");
+ console.log("span element", spanElement);
+ spanElement.innerText = pigLatinWord;
+}
+
+// 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");
+ });
+ });
+} else {
+ getPrompt();
+}
diff --git a/03week/rockPaperScissors.js b/03week/rockPaperScissors.js
new file mode 100644
index 000000000..b8bfbc927
--- /dev/null
+++ b/03week/rockPaperScissors.js
@@ -0,0 +1,78 @@
+"use strict";
+
+const assert = require("assert");
+const readline = require("readline");
+const rl = readline.createInterface({
+ input: process.stdin,
+ output: process.stdout
+});
+
+function rockPaperScissors(hand1, hand2) {
+ // Write code here
+ hand1 = hand1.trim().toLowerCase();
+ hand2 = hand2.trim().toLowerCase();
+
+ if (hand1 === hand2) {
+ return "It's a tie!";
+ }
+
+ if (hand1 === "rock" && hand2 === "scissors") {
+ return "Hand one wins!";
+ }
+
+ if (hand1 === "rock" && hand2 === "paper") {
+ return "Hand two wins!";
+ }
+
+ if (hand1 === "paper" && hand2 === "rock") {
+ return "Hand one wins!";
+ }
+
+ if (hand1 === "paper" && hand2 === "scissors") {
+ return "Hand two wins!";
+ }
+
+ if (hand1 === "scissors" && hand2 === "paper") {
+ return "Hand one wins!";
+ }
+
+ if (hand1 === "scissors" && hand2 === "rock") {
+ return "Hand two wins!";
+ }
+}
+
+function getPrompt() {
+ rl.question("hand1: ", answer1 => {
+ rl.question("hand2: ", answer2 => {
+ console.log(rockPaperScissors(answer1, answer2));
+ getPrompt();
+ });
+ });
+}
+
+// Tests
+
+if (typeof describe === "function") {
+ describe("#rockPaperScissors()", () => {
+ it("should detect a tie", () => {
+ assert.equal(rockPaperScissors("rock", "rock"), "It's a tie!");
+ assert.equal(rockPaperScissors("paper", "paper"), "It's a tie!");
+ assert.equal(rockPaperScissors("scissors", "scissors"), "It's a tie!");
+ });
+ it("should detect which hand won", () => {
+ assert.equal(rockPaperScissors("rock", "paper"), "Hand two wins!");
+ assert.equal(rockPaperScissors("rock", "scissors"), "Hand one wins!");
+ assert.equal(rockPaperScissors("paper", "scissors"), "Hand two wins!");
+ assert.equal(rockPaperScissors("paper", "rock"), "Hand one wins!");
+ assert.equal(rockPaperScissors("scissors", "rock"), "Hand two wins!");
+ assert.equal(rockPaperScissors("scissors", "paper"), "Hand one wins!");
+ });
+ it('should scrub input to ensure lowercase with "trim"ed whitepace', () => {
+ assert.equal(rockPaperScissors("rOcK", " paper "), "Hand two wins!");
+ assert.equal(rockPaperScissors("Paper", "SCISSORS"), "Hand two wins!");
+ assert.equal(rockPaperScissors("rock ", "sCiSsOrs"), "Hand one wins!");
+ });
+ });
+} else {
+ getPrompt();
+}
diff --git a/03week/ticTacToe.css b/03week/ticTacToe.css
new file mode 100644
index 000000000..dc8dacf79
--- /dev/null
+++ b/03week/ticTacToe.css
@@ -0,0 +1,149 @@
+div {
+ font-family: Impact, Charcoal, sans-serif;
+}
+
+button {
+ align-self: center;
+ width: 100px;
+ height: 100px;
+ font-family: Impact, Charcoal, sans-serif;
+}
+
+div.zero {
+ grid-area: zero;
+ border-right: 5px solid black;
+ border-bottom: 5px solid black;
+ width: 200px;
+ height: 200px;
+ display: flex;
+ align-items: center;
+ justify-content: center;
+ font-size: 200px;
+}
+
+div.one {
+ grid-area: one;
+ border-bottom: 5px solid black;
+ width: 200px;
+ height: 200px;
+ margin-right: -5px;
+ display: flex;
+ align-items: center;
+ justify-content: center;
+ font-size: 200px;
+}
+
+div.two {
+ grid-area: two;
+ border-left: 5px solid black;
+ border-bottom: 5px solid black;
+ width: 200px;
+ height: 200px;
+ display: flex;
+ align-items: center;
+ justify-content: center;
+ font-size: 200px;
+}
+
+div.three {
+ grid-area: three;
+ border-right: 5px solid black;
+ border-bottom: 5px solid black;
+ width: 200px;
+ height: 200px;
+ display: flex;
+ align-items: center;
+ justify-content: center;
+ font-size: 200px;
+}
+
+div.four {
+ grid-area: four;
+ border-bottom: 5px solid black;
+ width: 200px;
+ height: 200px;
+ margin-right: -5px;
+ display: flex;
+ align-items: center;
+ justify-content: center;
+ font-size: 200px;
+}
+
+div.five {
+ grid-area: five;
+ border-left: 5px solid black;
+ border-bottom: 5px solid black;
+ width: 200px;
+ height: 200px;
+ display: flex;
+ align-items: center;
+ justify-content: center;
+ font-size: 200px;
+}
+
+div.six {
+ grid-area: six;
+ border-right: 5px solid black;
+ width: 200px;
+ height: 200px;
+ display: flex;
+ align-items: center;
+ justify-content: center;
+ font-size: 200px;
+}
+
+div.seven {
+ grid-area: seven;
+ width: 200px;
+ height: 200px;
+ margin-right: -5px;
+ display: flex;
+ align-items: center;
+ justify-content: center;
+ font-size: 200px;
+}
+
+div.eight {
+ grid-area: eight;
+ border-left: 5px solid black;
+ width: 200px;
+ height: 200px;
+ display: flex;
+ align-items: center;
+ justify-content: center;
+ font-size: 200px;
+}
+
+section.board {
+ width: 600px;
+ height: 600px;
+ margin-top: 30px;
+ display: grid;
+ grid-auto-columns: 1fr;
+ grid-template-areas:
+ "zero one two"
+ "three four five"
+ "six seven eight";
+}
+
+section.bottom {
+ width: 600px;
+ height: 100px;
+ display: flex;
+ justify-content: center;
+ flex-direction: column;
+}
+
+div.logo {
+ text-align: center;
+ padding-top: 20px;
+ padding-bottom: 20px;
+}
+
+main {
+ width: 750px;
+ margin: auto;
+ display: flex;
+ justify-content: center;
+ flex-direction: column;
+}
diff --git a/03week/ticTacToe.html b/03week/ticTacToe.html
new file mode 100644
index 000000000..2b150b371
--- /dev/null
+++ b/03week/ticTacToe.html
@@ -0,0 +1,32 @@
+
+
+
+
+
+
+ TicTacToe
+
+
+
+
+
+
+
+
+
+
+
+
diff --git a/03week/ticTacToe.js b/03week/ticTacToe.js
index 1abf5b900..539ce6035 100644
--- a/03week/ticTacToe.js
+++ b/03week/ticTacToe.js
@@ -1,93 +1,231 @@
-'use strict';
-
-const assert = require('assert');
-const readline = require('readline');
-const rl = readline.createInterface({
- input: process.stdin,
- output: process.stdout
-});
-let board = [
- [' ', ' ', ' '],
- [' ', ' ', ' '],
- [' ', ' ', ' ']
-];
-
-let playerTurn = 'X';
+"use strict";
+
+// const assert = require("assert");
+// const readline = require("readline");
+// const rl = readline.createInterface({
+// input: process.stdin,
+// output: process.stdout
+// });
+let board = [[" ", " ", " "], [" ", " ", " "], [" ", " ", " "]]; //board array is defined and empty in order to receive values from the user
+
+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(' | '));
+ // function 'prints' out board but is really just priting out the values of the board array and a few '-''s and '|' to build a board
+ 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
+ //checks to see if board array values satisfy a horizonal win, print out board, announce winning player, and return true
+ if (
+ (board[0][0] == playerTurn &&
+ board[0][1] == playerTurn &&
+ board[0][2] == playerTurn) ||
+ (board[1][0] == playerTurn &&
+ board[1][1] == playerTurn &&
+ board[1][2] == playerTurn) ||
+ (board[2][0] == playerTurn &&
+ board[2][1] == playerTurn &&
+ board[2][2] == playerTurn)
+ ) {
+ printBoard();
+ console.log("Player " + playerTurn + " wins!");
+ return true;
+ }
}
function verticalWin() {
- // Your code here
+ //checks to see if board array values satisfy a vertical win, print out board, announce winning player, and return true
+ if (
+ (board[0][0] == playerTurn &&
+ board[1][0] == playerTurn &&
+ board[2][0] == playerTurn) ||
+ (board[0][1] == playerTurn &&
+ board[1][1] == playerTurn &&
+ board[2][1] == playerTurn) ||
+ (board[0][2] == playerTurn &&
+ board[1][2] == playerTurn &&
+ board[2][2] == playerTurn)
+ ) {
+ printBoard();
+ console.log("Player " + playerTurn + " wins!");
+ return true;
+ }
}
function diagonalWin() {
- // Your code here
+ //checks to see if board array values satisfy a diagnonal win, print out board, announce winning player, and return true
+
+ if (
+ (board[0][0] == playerTurn &&
+ board[1][1] == playerTurn &&
+ board[2][2] == playerTurn) ||
+ (board[2][0] == playerTurn &&
+ board[1][1] == playerTurn &&
+ board[0][2] == playerTurn)
+ ) {
+ printBoard();
+ console.log("Player " + playerTurn + " wins!");
+ return true;
+ }
}
function checkForWin() {
- // Your code here
-}
+ //checkForWin merely checks to see if horizonalWin or verticalWin or diagonal win return true, and if so checkForWin returns true or false
-function ticTacToe(row, column) {
- // Your code here
+ if (horizontalWin() || verticalWin() || diagonalWin()) {
+ return true;
+ } else {
+ return false;
+ }
}
-function getPrompt() {
- printBoard();
- console.log("It's Player " + playerTurn + "'s turn.");
- rl.question('row: ', (row) => {
- rl.question('column: ', (column) => {
- ticTacToe(row, column);
- getPrompt();
- });
- });
-
+function checkForDraw() {
+ /**checkForDraw checks to see if the board is filled up with no clear winner,
+ * its important that its at the bottom so that the file can check for a win first before checking for a draw.
+ * If a draw is detected it will print the board announce the draw and return true or false
+ **/
+ if (
+ board[0][0] !== " " &&
+ board[0][1] !== " " &&
+ board[0][2] !== " " &&
+ board[1][0] !== " " &&
+ board[1][1] !== " " &&
+ board[1][2] !== " " &&
+ board[2][0] !== " " &&
+ board[2][1] !== " " &&
+ board[2][2] !== " "
+ ) {
+ printBoard();
+ console.log("Its a draw!");
+ return true;
+ } else {
+ return false;
+ }
}
+function ticTacToe(row, column, cellId) {
+ //This is where most of the magic happens. There is some quality control going on here.
+ if (row > 2 || column > 2) {
+ //checks to see if row and column values from the user are under 2 and anounces a message.
+ console.log("Cordiantes must be between 0 and 2. Try again.");
+ } else if (row.length > 1 || column.length > 1) {
+ //checkes to see if row and column value length are over 1 character and announces a message.
+ console.log("Single digits please");
+ } //most of the work gets done here
+ else if (board[row][column] == " ") {
+ //checks to see if the board array cordinates are empty, everything within this else if statement will not run if that condition is not satisfied
+ board[row][column] = playerTurn; //assigns value if empty.
+ let cell;
+ cell = document.getElementById(cellId);
+ console.log(cell);
+ cell.innerText = playerTurn;
+ console.log("I am trying to assign value to " + cellId);
+
+ if (checkForWin() || checkForDraw()) {
+ //after player 'move' has been made this checks to see if there is a win or a draw and restarts the game as needed.
+ alert("Game Over");
+ board[0][0] = " ";
+ board[0][1] = " ";
+ board[0][2] = " ";
+ board[1][0] = " ";
+ board[1][1] = " ";
+ board[1][2] = " ";
+ board[2][0] = " ";
+ board[2][1] = " ";
+ board[2][2] = " ";
+
+ document.getElementById("00").innerText = "";
+ document.getElementById("01").innerText = "";
+ document.getElementById("02").innerText = "";
+ document.getElementById("10").innerText = "";
+ document.getElementById("11").innerText = "";
+ document.getElementById("12").innerText = "";
+ document.getElementById("20").innerText = "";
+ document.getElementById("21").innerText = "";
+ document.getElementById("22").innerText = "";
+
+ playerTurn = "X";
+ } else if (playerTurn == "X") {
+ playerTurn = "O";
+ } else if (playerTurn == "O") {
+ playerTurn = "X";
+ }
+ }
+}
+function handleInput(row, column) {
+ let rowString;
+ let columnString;
+ let cellId;
+ rowString = row.toString();
+ columnString = column.toString();
+ cellId = rowString + columnString;
+ ticTacToe(row, column, cellId);
+}
+function reset() {
+ board[0][0] = " ";
+ board[0][1] = " ";
+ board[0][2] = " ";
+ board[1][0] = " ";
+ board[1][1] = " ";
+ board[1][2] = " ";
+ board[2][0] = " ";
+ board[2][1] = " ";
+ board[2][2] = " ";
+
+ document.getElementById("00").innerText = "";
+ document.getElementById("01").innerText = "";
+ document.getElementById("02").innerText = "";
+ document.getElementById("10").innerText = "";
+ document.getElementById("11").innerText = "";
+ document.getElementById("12").innerText = "";
+ document.getElementById("20").innerText = "";
+ document.getElementById("21").innerText = "";
+ document.getElementById("22").innerText = "";
+}
// Tests
-if (typeof describe === 'function') {
-
- describe('#ticTacToe()', () => {
- it('should place mark on the board', () => {
+if (typeof describe === "function") {
+ describe("#ticTacToe()", () => {
+ it("should place mark on the board", () => {
ticTacToe(1, 1);
- assert.deepEqual(board, [ [' ', ' ', ' '], [' ', 'X', ' '], [' ', ' ', ' '] ]);
+ assert.deepEqual(board, [
+ [" ", " ", " "],
+ [" ", "X", " "],
+ [" ", " ", " "]
+ ]);
});
- it('should alternate between players', () => {
+ it("should alternate between players", () => {
ticTacToe(0, 0);
- assert.deepEqual(board, [ ['O', ' ', ' '], [' ', 'X', ' '], [' ', ' ', ' '] ]);
+ assert.deepEqual(board, [
+ ["O", " ", " "],
+ [" ", "X", " "],
+ [" ", " ", " "]
+ ]);
});
- it('should check for vertical wins', () => {
- board = [ [' ', 'X', ' '], [' ', 'X', ' '], [' ', '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'], [' ', ' ', ' '], [' ', ' ', ' '] ];
+ it("should check for horizontal wins", () => {
+ board = [["X", "X", "X"], [" ", " ", " "], [" ", " ", " "]];
assert.equal(horizontalWin(), true);
});
- it('should check for diagonal wins', () => {
- board = [ ['X', ' ', ' '], [' ', 'X', ' '], [' ', ' ', 'X'] ];
+ it("should check for diagonal wins", () => {
+ board = [["X", " ", " "], [" ", "X", " "], [" ", " ", "X"]];
assert.equal(diagonalWin(), true);
});
- it('should detect a win', () => {
+ it("should detect a win", () => {
assert.equal(checkForWin(), true);
});
});
} else {
-
- getPrompt();
-
+ // getPrompt();
}
diff --git a/04week/mastermind.js b/04week/mastermind.js
index 60e5cfa18..948f3892c 100644
--- a/04week/mastermind.js
+++ b/04week/mastermind.js
@@ -1,15 +1,15 @@
-'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
});
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++) {
@@ -28,50 +28,81 @@ function getRandomInt(min, max) {
return Math.floor(Math.random() * (max - min)) + min;
}
-function generateHint() {
+function generateHint(guess) {
// your code here
+ console.log(solution);
+ console.log(guess);
+ let XO = ["-", "-", "-", "-"];
+ let a = 0;
+ let b = 0;
+
+ for (let i = 0; i < solution.length; i++) {
+ if (solution[i] == guess[i]) {
+ XO[i] = "X";
+ } else {
+ for (let y = 0; y < solution.length; y++) {
+ if (solution[i] == guess[y]) {
+ XO[i] = "O";
+ }
+ }
+ }
+ }
+
+ for (let i = 0; i < XO.length; i++) {
+ if (XO[i] === "X") {
+ a++;
+ } else if (XO[i] === "O") {
+ b++;
+ }
+ }
+ let hint = a + "-" + b;
+ return hint;
}
function mastermind(guess) {
- solution = 'abcd'; // Comment this out to generate a random solution
+ solution = "abcd"; // Comment this out to generate a random solution
+ if (guess == solution) {
+ return "You guessed it!";
+ }
+ board.push(guess);
+ var hint = generateHint(guess);
+ console.log(hint);
// your code here
}
-
function getPrompt() {
- rl.question('guess: ', (guess) => {
+ rl.question("guess: ", guess => {
+ generateSolution();
mastermind(guess);
printBoard();
+
getPrompt();
});
}
// Tests
-if (typeof describe === 'function') {
- solution = 'abcd';
- describe('#mastermind()', () => {
- it('should register a guess and generate hints', () => {
- mastermind('aabb');
+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!');
+ 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');
+ 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');
+ it("should generate hints if solution has duplicates", () => {
+ assert.equal(generateHint("aabb"), "1-1");
});
-
});
-
} else {
-
generateSolution();
getPrompt();
}
diff --git a/05week/spaceTravelToMars.js b/05week/spaceTravelToMars.js
index ce258a382..29777a18f 100644
--- a/05week/spaceTravelToMars.js
+++ b/05week/spaceTravelToMars.js
@@ -1,51 +1,94 @@
-'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!"
};
+class Ship {
+ constructor(name, type, ability) {
+ //template that accepts info for each ship
+ this.name = name;
+ this.type = type;
+ this.ability = ability;
+ this.crew = [];
+ }
+
+ missionStatement() {
+ //function taht tests weather a ship can perform a mission, it needs at least 1 crew member
+ if (this.crew.length < 1) {
+ //if the crew array is less than one, that means there is no crew and the ship can't take off.
+ return "Can't perform a mission yet.";
+ } else return this.ability;
+ }
+}
+
+class CrewMember {
+ constructor(name, job, specialSkill) {
+ //template that accepts info through the constructor to establish a CrewMember
+ this.name = name;
+ this.job = job;
+ this.specialSkill = specialSkill;
+ this.ship = null;
+ }
+
+ enterShip(Ship) {
+ //Takes in Ship class into constructor
+ this.ship = Ship; //Assigns ship value from Ship Class
+ console.log("I am inside enter ship", this); //console log test to show which ship crew memeber is in.
+ Ship.crew.push(this); // adds crew memeber to crew array, thus inrcreasing its length.
+ }
+}
+
// Your code here
//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');
+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');
+ 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);
+ assert.equal(crewMember1.ship, mav); //does crew ship match ship
+ assert.equal(mav.crew.length, 1); //does crew length or crew total equal one
+ assert.equal(mav.crew[0], crewMember1); //does crew equal crewmember name
});
});
- 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');
+ 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');
+ 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.");