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

let jobTypes = {
pilot: 'MAV',
mechanic: 'Repair Ship',
commander: 'Main Ship',
programmer: 'Any Ship!'
};

class CrewMember {
constructor (name, job, specialSkill, ship) {
this.name = name;
this.job = job;
this.specialSkill = specialSkill;
this.ship = null;
}
enterShip (shipObj) {
//shipObj.crew.push(this);
this.ship = shipObj;
this.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) {
return this.ability;
} else {
return 'Can\'t perform a mission yet.';
}
}
}



// tests

let assert = require('assert');

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);
console.log('mav? ' + crewMember1.ship);
assert.equal(crewMember1.ship, mav);
console.log('1? ' + mav.crew.length);
assert.equal(mav.crew.length, 1);
console.log('crewMember1? ' + mav.crew[0]);
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');
});
});
}
35 changes: 35 additions & 0 deletions 05week/changeOrder.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@

append

getElementBy
listArr.length


document.getElementById()

create button





const lastElement = document.getElementById('list-container').lastChild;
const arrow = document.createAttribute("id");
arrow.value = 'Arrow' + listArr.length;
lastElement.setAttributeNode(arrow);

document.lastElement.setAttributeNode
document.lastElement.addEventListener('click', () => {
let ArrowId = this.getAttribute('id');



const index = parseInt(this.getElementById('id');
let lowerNumber = listArr[index].order;
let higherNumber = lowerNumber - 1;
});


// Create a "class" attribute
// Set the value of the class attribute
h1.
120 changes: 58 additions & 62 deletions 05week/checkers.js
Original file line number Diff line number Diff line change
@@ -1,110 +1,106 @@
'use strict';

const assert = require('assert');
const readline = require('readline');
const rl = readline.createInterface({
input: process.stdin,
output: process.stdout
});
class Game {
constructor () {
}

start () {
this.board = new Board();
this.board.createGrid();

function Checker() {
// Your code here
}
}

function Board() {
this.grid = [];
// creates an 8x8 array, filled with null values
this.createGrid = function() {
// 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);
class Board {
this.grid = [];
// creates an 8x8 array, filled with null values
this.createGrid = function () {
// loop to create the 8 rows
for (let row = 0; row < 8; row++) {
this.grid[row] = [];
// push in X's (red checkers), O's (black checkers), and null's (empty spaces)
for (let col = 0; col < 8; col++) {
// The checkers may only be placed on cells whose col and row add to an odd number
if (row < 3 && (row + col) % 2 !== 0) {
this.grid[row].push('X');
} else if (row > 4 && (row + col) % 2 !== 0) {
this.grid[row].push('O');
} else {
this.grid[row].push(null);
}
}
}
}
};
}

// prints out the board
this.viewGrid = function() {
// add our column numbers
let string = " 0 1 2 3 4 5 6 7\n";
viewGrid () {
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";
string += '\n';
}
console.log(string);
};
}

// Your code here
Checker () {
// Your code here
}
}
function Game() {

this.board = new Board();
const game = new Game();
game.start();

this.start = function() {
this.board.createGrid();
// Your code here
};
}
// Tests

const assert = require('assert');
const readline = require('readline');
const rl = readline.createInterface({
input: process.stdin,
output: process.stdout
});

function getPrompt() {
game.board.viewGrid();
game.board.viewGrid(); // ######################################
rl.question('which piece?: ', (whichPiece) => {
rl.question('to where?: ', (toWhere) => {
game.moveChecker(whichPiece, toWhere);
game.moveChecker(whichPiece, toWhere); // ######################################
getPrompt();
});
});
}

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');
assert.equal(game.board.constructor.name, 'Board'); // ######################################
});
it('board should have 24 checkers', () => {
assert.equal(game.board.checkers.length, 24);
assert.equal(game.board.checkers.length, 24); // ######################################
});
});

describe('Game.moveChecker()', function () {
it('should move a checker', function () {
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]);
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);
game.moveChecker('30', '52'); // ######################################
assert(game.board.grid[5][2]); // ######################################
assert(!game.board.grid[4][1]); // ######################################
assert.equal(game.board.checkers.length, 23); // ######################################
});
});
} else {
Expand Down
Loading