Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
29 changes: 27 additions & 2 deletions 01week/rockPaperScissors.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,32 @@ const rl = readline.createInterface({

function rockPaperScissors(hand1, hand2) {

// Write code here

// Rock paper Scissors function, below:

if (hand1 === hand2){
console.log("It's a tie.")
};
if (hand1 === 'rock' && hand2 === 'scissor') {
console.log("User1 wins.")
};
if (hand1 ==='rock'&& hand2 === 'paper'){
console.log("User2 wins.")
};
if (hand1 === 'paper'&& hand2 === 'rock') {
console.log("User1 wins.")
};
if (hand1 === 'paper' && hand2 === 'scissors'){
console.log("User2 wins.")
};
if (hand1 === 'scissors' && hand2 === 'paper'){
console.log("User1 wins.")
};
if (hand1 === 'scissors'&& hand2 === 'rock'){
console.log("User2 wins.")
};
}
rockPaperScissors("rock","paper");


function getPrompt() {
rl.question('hand1: ', (answer1) => {
Expand Down Expand Up @@ -48,4 +71,6 @@ if (typeof describe === 'function') {

getPrompt();



}
8 changes: 6 additions & 2 deletions 02week/pigLatin.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,16 @@ const rl = readline.createInterface({
output: process.stdout
});

//added pigLatin code

function pigLatin(word) {

// Your code here

}
word= word.toLowerCase();
let vowels = word.search(/[aeiuo]/);
console.log(word.substring(vowels) + word.substring(0,vowels) + "ay")
}
pigLatin("car");


function getPrompt() {
Expand Down
41 changes: 41 additions & 0 deletions 02week/tests.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
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('paper', 'scissors'), "Hand two wins!");
assert.equal(rockPaperScissors('scissors', 'rock'), "Hand two wins!");
assert.equal(rockPaperScissors('rock', 'scissors'), "Hand one wins!");
assert.equal(rockPaperScissors('scissors','paper'), "Hand one wins!");
assert.equal(rockPaperScissors('paper', 'rock'), "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!");
});

it('should detect if input is valid', () =>{
assert.equal(rockPaperScissors('cat', ' 3 '), "Invalid Entry");
assert.equal(rockPaperScissors('rock', ' Cat '), "Invalid Entry");
assert.equal(rockPaperScissors('', ''), "Invalid Entry");
assert.equal(rockPaperScissors('#', 'rock'), "Invalid Entry");
assert.equal(rockPaperScissors('=', 'paper!'), "Invalid Entry");
assert.equal(rockPaperScissors('rock2', 'rock?'), "Invalid Entry");


})
});
} else {

getPrompt();

}



55 changes: 55 additions & 0 deletions 03week/exercises.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
// week 3 array exercises:

//length
let cars = ["Ford","Chevy","Dodge","Toyota"];
console.log(cars.length);

//concat
let moreCars = ["Subaru","Mazda","Bmw","Honda"];
let totalCars = cars.concat(moreCars);
console.log(totalCars);

//indexOf/lastIndexOf:
console.log(moreCars.indexOf("Honda"))
console.log(cars.lastIndexOf("Ford"));

//join
let stringOfCars = totalCars.join();
console.log(stringOfCars);

//split
console.log(stringOfCars.split());

//reverse
let carsInReverse = totalCars.reverse();
console.log(carsInReverse);

//sort,
console.log(carsInReverse.sort());
//slice
let removedCars = carsInReverse.slice(3,5);
console.log(removedCars);

//splice
console.log("my new array: " + carsInReverse.splice(1, 5, "Ford", "Honda"));
console.log(carsInReverse);

//push
console.log(carsInReverse.push("Dodge", "Mazda"));
console.log(carsInReverse);

//pop
console.log(carsInReverse.pop());

//shift
console.log(carsInReverse.shift());

//unshift
console.log(carsInReverse.unshift("Jeep"));
console.log(carsInReverse);

//forEach
let numbers = [23, 45, 0, 2];
numbers.forEach(function(number) {
console.log(number + 2);
})
83 changes: 66 additions & 17 deletions 03week/ticTacToe.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@ const rl = readline.createInterface({
input: process.stdin,
output: process.stdout
});
'use strict';

let board = [
[' ', ' ', ' '],
[' ', ' ', ' '],
Expand All @@ -22,25 +24,73 @@ function printBoard() {
console.log(' ---------');
console.log('2 ' + board[2].join(' | '));
}

function horizontalWin() {
// Your code here
// stipulates winning combinations to return 'true'
let horizontalWin= ()=> {
if(
(board[0][0] == playerTurn && board[0][1] == playerTurn && board[0][2] == playerTurn) ||
(board[1][0] == playerTurn && board[1][0] == playerTurn && board[1][2] == playerTurn) ||
(board[2][0] == playerTurn && board[2][1] == playerTurn && board[2][2] == playerTurn)
) {
return true;
}
else{
return false;
}
}

function verticalWin() {
// Your code here
}

function diagonalWin() {
// Your code here
// stipulates winning combinations to return 'true'
let verticalWin = ()=> {
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)
) {
return true;
}
else
return false;
}

// stipulates winning combinations to return 'true'
let diagonalWin=()=> {
if(
(board[0][0] == playerTurn && board[1][1] == playerTurn && board[2][2] == playerTurn) ||
(board[0][2] == playerTurn && board[1][1] == playerTurn && board[2][0] == playerTurn)
) {
return true;
}
else return false;
}

//checks for winning conditions, above;
function checkForWin() {
// Your code here
}

function ticTacToe(row, column) {
// Your code here
if (diagonalWin() || verticalWin() || horizontalWin()) {
console.log("WINNER!!");
return true;
}
else {
return false
}
}

//if there is an empty space, places "X" or "O" on board in alternating turns; executes CheckForWin
function ticTacToe(row, column) {
if (board[row][column] === ' ') {
board[row][column] = playerTurn;
if (checkForWin())
{
console.log("START NEW GAME")
}
else {
if (playerTurn === 'X') {
playerTurn = 'O';
} else {
playerTurn = 'X';
}
}
} else {
console.log('SPOT TAKEN')
}
return playerTurn;
}

function getPrompt() {
Expand All @@ -56,8 +106,7 @@ function getPrompt() {
}



// Tests
// Tests for game

if (typeof describe === 'function') {

Expand Down
Loading