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
65 changes: 65 additions & 0 deletions 02week/arrayspj.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
'use strict'

//length
let cars = ['Ford','Toyota','Cadillac','Hyundai'];
console.log(cars.length);

//concat
let moreCars = ['Aston Martin','Bugatti','Bentley','Honda'];
let totalCars = cars.concat(moreCars);
console.log(totalCars);

//indexOf
console.log(totalCars.indexOf("Honda"));

//lastIndexOf
console.log(totalCars.lastIndexOf("Ford"));

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

//split
totalCars = stringOfCars.split(',');
console.log(totalCars);

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

//sort
carsInReverse.sort();
alert(carsInReverse.indexOf('Aston Martin'));
console.log(carsInReverse);

//slice
let removedCars = carsInReverse.slice(4, 6);
console.log(removedCars);

//splice
carsInReverse.splice(1, 1, 'Ford');
carsInReverse.splice(2, 1, 'Honda');
console.log(carsInReverse);

//push
carsInReverse.push('Ford', 'Honda');
console.log(carsInReverse);

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

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

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

//forEach
var numbers = [23, 45, 0, 2];
function addTwo(item) {
console.log(item + 2);
}
numbers.forEach(addTwo)
42 changes: 36 additions & 6 deletions 02week/ticTacToe.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,21 @@
'use strict';


//if no, push that player marker to that index
//make a copy to the board
//const updatedBoard = [...board];
//slice the row, store to const, (not splice)
//const updatedRow = board.slice(row, row+1) [0];
//console.log(updatedRow, 'Row')

/*Check it marker exists at row/columns
If no wins, switch player, display the updated boardIf any wins come back return the player winner, clear the board*/

//Horizontal Win [0,1,2], [3,4,5], [6,7,8]
// Vertical Win: [0,3,6], [1,4,7], [2,5,8]
// Diagonal Win: [0,4,8], [0,2,6]
// Only way to win is if the total is 0 or if the total is 3. X are worth 1 point and O are worth 0 points

const assert = require('assert');
const readline = require('readline');
const rl = readline.createInterface({
Expand All @@ -23,17 +39,31 @@ function printBoard() {
console.log('2 ' + board[2].join(' | '));
}

// Horizontal Win: [0,1,2], [3,4,5], [6,7,8]
function horizontalWin() {
// Your code here
}
if ('a win in a row') {
[ { x: 0, o: 6 }, { x: 1, o: 7 }, { x: 2, o: 8 }] || [ { x: 3, o: 0 }, {x: 4, o: 1 }, { x: 5, o: 2 }] || [ { x: 6, o: 3 }, { x: 7, o: 4 }, { x: 8, o: 5 }]
};
return ('player " " wins!');
};

// Vertical Win: [0,3,6], [1,4,7], [2,5,8]
function verticalWin() {
// Your code here
}
if ('a win in a column') {
[ { x: 0, o: 1 }, { x: 3, o: 4 }, { x: 6, o: 7 }] || [ { x: 2, o: 0 }, { x: 5, o: 3 }, { x: 8, o: 6 }] || [ { x: 1, o: 2 }, { x: 4, o: 5 }, { x: 7, o: 8 }]

};
return ('player " " wins!');
};

// Diagonal Win: [0,4,8], [2,4,6]
function diagonalWin() {
// Your code here
}
if ('a win diagonally') {
[ { x: 0, o: 2 }, { x: 4, o: 4 }, { x: 8, o: 6 }] || [ { x: 2, o: 0 }, { x: 4, o: 4 }, { x: 6, o: 8 }]

};
return ('player " " wins!');
};

function checkForWin() {
// Your code here
Expand Down
38 changes: 38 additions & 0 deletions 03week/forLoops.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
const carsInReverse = ['Fiat', 'Ford'];
console.log(carsInReverse);

for (let i = 0; i < carsInReverse.length; i++){
console.log(carsInReverse[i]);
}

const persons = {
firstName: "Jane",
lastName: "Doe",
birthDate: "Jan 5, 1925",
gender: "female"
};

let key;
for (key in persons) {
console.log(key);
}

for (key in persons) {
if (key ==='birthDate') {
console.log(persons['birthDate']);
}
};


let n = 0;
while (n < 1001) {
console.log(n);
n++
};

/*
A "for loop" is better than a "while loop" when you know the exact number of iterations you need to do for a specific problem.

The difference between a for loop and a for...in loop is a for loop is used to iterate through an array and a for..in loop is to iterate over the properties of an object.

The difference between a while loop and a do...while loop is a while loop keeps going until something rings true. The do...while loop when some sort of task or function needs to be done first before you start running that loop.
24 changes: 24 additions & 0 deletions 03week/partnerChallenge.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
'use strict'

const partnerObj = {
firstName: "Renata",
lastName: "Estes",
age:27,
eyeColor: "brown",
talk: () => {
return "Hello Renee!"
},
};

partnerObj.lastName = "cars";
console.log(partnerObj['firstName']);
console.log(partnerObj.lastName);
console.log(partnerObj.talk());

const partnerArr = Object.keys(partnerObj);
console.log(partnerArr);

for (var i in partnerArr){
console.log(partnerArr[i])
console.log(partnerObj[partnerArr[i]])
}
76 changes: 71 additions & 5 deletions 03week/towersOfHanoi.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,50 @@
'use strict';

//Create three CoRs with arrays
//The first CoR is full
let stacks = {
a: [4, 3, 2, 1],
b: [],
c: []
};
//You click on the first CoR to remove a stack (pop)
//You click on one of the other CoR to add that stack you removed (movePiece)
//~>You must check the CoR to see if there is already a stack there.
//(push)//
function movePiece() {
if (stacks == null) {
stacks.pop();
} else {
if (last < last) {
alert("Invalid Move");
} else {
stacks.push();
stacks = null;
}
}
//(Compare array values). If there is, you need to check the value of that stack to make sure it is bigger than the one you want to drop.
//You win whenever you get the entire stack on one of the other CoRs (stack.b or stack.c)

var clicker = function() {
//
var row = null;
var m = 0;
stack.click(function(){
m = m +1;
$("#counter").html(m);
var stack = $(this);
var children = stack.children();
var lastChild = children.last();

if ((stack ='2').children().length >= 4 || (stack ='3').children().length >= 4)
{
alert("You Win!!");
}

});
}


const assert = require('assert');
const readline = require('readline');
const rl = readline.createInterface({
Expand All @@ -13,25 +58,39 @@ let stacks = {
c: []
};

let first = stacks[0];
console.log(first);

let last = stacks[stacks.length - 1];
console.log(last);

function printStacks() {
console.log("a: " + stacks.a);
console.log("b: " + stacks.b);
console.log("c: " + stacks.c);
}

function movePiece() {
// Your code here

}
if (stacks == null) {
stacks.pop();
} else {
if (last < last) {
alert("Invalid Move");
} else {
stacks.push();
stacks = null;
}
}

function isLegal() {
// Your code here

}

function checkForWin() {
// Your code here

if (stacks.b.length === 4 || stacks.c.length === 4) {
console.log("You win");
}
}

function towersOfHanoi(startStack, endStack) {
Expand Down Expand Up @@ -91,3 +150,10 @@ if (typeof describe === 'function') {
getPrompt();

}


/*function towersOfHanoi (startStack, endStack)
if sourceStack arry.last < targetStack array.last then
return true
end if
return false*/