├── .circleci
└── config.yml
├── .eslintrc.json
├── .github
└── PULL_REQUEST_TEMPLATE.md
├── .gitignore
├── .htmllintrc
├── .stylelintrc
├── .vscode
└── launch.json
├── 01week
├── datatypes.js
├── javascripting
│ └── introduction.js
└── rockPaperScissors.js
├── 02week
├── pigLatin.js
└── tests.js
├── 03week
├── ticTacToe.js
└── towersOfHanoi.js
├── 04week
├── functional-javascript
│ └── helloWorld.js
├── loop.js
└── mastermind.js
├── 05week
├── checkers.js
└── spaceTravelToMars.js
├── 06week
└── higherOrder.js
├── 07week
├── ticTacToe
│ ├── index.html
│ ├── script.js
│ └── style.css
└── towersOfHanoi
│ ├── index.html
│ ├── script.js
│ └── style.css
├── 08week
├── bootstrap
│ ├── index.html
│ ├── script.js
│ └── style.css
└── fetch
│ ├── index.html
│ ├── script.js
│ └── style.css
├── 09week
└── hackernews
│ ├── index.html
│ └── script.js
├── 10week
└── algorithms.js
├── README.md
├── extra-challenges
├── 01challenge.js
├── 02challenge.js
├── 03challenge.js
├── 04challenge.js
├── 05challenge.js
├── 06challenge.js
├── 07challenge.js
├── 08challenge.js
├── 09challenge.js
├── 10challenge.js
├── 11challenge.js
├── 12challenge.js
├── 13challenge.js
├── 14challenge.js
├── 15challenge.js
└── 16challenge.js
├── index.html
├── package-lock.json
└── package.json
/.circleci/config.yml:
--------------------------------------------------------------------------------
1 | version: 2
2 | jobs:
3 | build:
4 | docker:
5 | - image: circleci/node:8.9.4
6 | working_directory: ~/repo
7 |
8 | steps:
9 | - checkout
10 |
11 | - restore_cache:
12 | keys:
13 | - npm-packages-v1-{{ .Branch }}-{{ checksum "package-lock.json" }}
14 | - npm-packages-v1-{{ .Branch }}-
15 | - npm-packages-v1-
16 | - run: npm install
17 | - save_cache:
18 | paths:
19 | - node_modules
20 | key: npm-packages-v1-{{ .Branch }}-{{ checksum "package-lock.json" }}
21 | - run: 'npm run lint'
22 |
--------------------------------------------------------------------------------
/.eslintrc.json:
--------------------------------------------------------------------------------
1 | {
2 | "extends": "",
3 | "rules": {
4 | "indent": ["error", 2]
5 | },
6 | "env": {
7 | "es6": true,
8 | "mocha": true,
9 | "node": true
10 | },
11 | "parserOptions": {
12 | "ecmaFeatures": {
13 | "jsx": true
14 | }
15 | }
16 | }
17 |
--------------------------------------------------------------------------------
/.github/PULL_REQUEST_TEMPLATE.md:
--------------------------------------------------------------------------------
1 | ## Checkpoint Rubric
2 | This is the rubric that your instructor will use to grade your checkpoints. Please do not edit.
3 |
4 | **Checkpoint 1**
5 | - [ ] All tests passed: 40 points
6 | - [ ] Proper use of documentation (commenting on code): 15 points
7 | - [ ] Properly indented code: 15 points
8 | - [ ] Demonstrated effective use of JavaScript: 30 points
9 |
10 | **Checkpoint 2**
11 | - [ ] The application works as it should: 40 points
12 | - [ ] Proper use of documentation (commenting on code): 15 points
13 | - [ ] Properly indented code: 15 points
14 | - [ ] Demonstrated effective use of JavaScript and the DOM API: 30 points
15 |
16 | **Checkpoint 3**
17 | - [ ] Use of React: 25 points
18 | - [ ] Accesses an API: 25 points
19 | - [ ] Proper use of documentation (commenting on code): 25 points
20 | - [ ] The application functions as it should: 25 points
21 |
--------------------------------------------------------------------------------
/.gitignore:
--------------------------------------------------------------------------------
1 | # Dependencies
2 | node_modules
3 |
4 | # Logs
5 | logs
6 | *.log
7 | npm-debug.log*
8 |
9 | # OS artifacts
10 | *.DS_Store
11 |
--------------------------------------------------------------------------------
/.htmllintrc:
--------------------------------------------------------------------------------
1 | {
2 | // names of npm modules to load into htmllint
3 | "plugins": [],
4 | // https://github.com/htmllint/htmllint/wiki/Options
5 | "indent-width": 2,
6 | "line-end-style": false,
7 | "indent-style": "spaces",
8 | "doctype-first": "smart",
9 | "head-req-title": false,
10 | "attr-name-style": "dash",
11 | "class-style": "dash",
12 | "id-class-style": "dash",
13 | "tag-bans": false,
14 | "img-req-alt": false,
15 | "attr-bans": false,
16 | "tag-close": true,
17 | "tag-name-match": true
18 | }
19 |
--------------------------------------------------------------------------------
/.stylelintrc:
--------------------------------------------------------------------------------
1 | {
2 | "rules": {
3 | "indentation": 2
4 | }
5 | }
6 |
--------------------------------------------------------------------------------
/.vscode/launch.json:
--------------------------------------------------------------------------------
1 | {
2 | "version": "0.2.0",
3 | "configurations": [
4 | {
5 | "type": "node",
6 | "request": "launch",
7 | "name": "Run Program",
8 | "program": "${file}",
9 | "console": "integratedTerminal"
10 | },
11 | {
12 | "type": "node",
13 | "request": "launch",
14 | "name": "Test Program",
15 | "program": "${file}",
16 | "console": "integratedTerminal",
17 | "runtimeExecutable": "npm",
18 | "runtimeArgs": [ "test" ]
19 | }
20 | ]
21 | }
22 |
--------------------------------------------------------------------------------
/01week/datatypes.js:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/AustinCodingAcademy/javascript-workbook/8efeee630e047c7abb396dca9892bd2a52480583/01week/datatypes.js
--------------------------------------------------------------------------------
/01week/javascripting/introduction.js:
--------------------------------------------------------------------------------
1 | console.log('hello');
2 |
--------------------------------------------------------------------------------
/01week/rockPaperScissors.js:
--------------------------------------------------------------------------------
1 | // uses strict mode so strings are not coerced, variables are not hoisted, etc...
2 | 'use strict';
3 |
4 | // brings in the assert module for unit testing
5 | const assert = require('assert');
6 | // brings in the readline module to access the command line
7 | const readline = require('readline');
8 | // use the readline module to print out to the command line
9 | const rl = readline.createInterface({
10 | input: process.stdin,
11 | output: process.stdout
12 | });
13 |
14 | // the function that will be called by the unit test below
15 | const rockPaperScissors = (hand1, hand2) => {
16 |
17 | // Write code here
18 | // Use the unit test to see what is expected
19 |
20 | }
21 |
22 | // the first function called in the program to get an input from the user
23 | // to run the function use the command: node main.js
24 | // to close it ctrl + C
25 | function getPrompt() {
26 | rl.question('hand1: ', (answer1) => {
27 | rl.question('hand2: ', (answer2) => {
28 | console.log( rockPaperScissors(answer1, answer2) );
29 | getPrompt();
30 | });
31 | });
32 | }
33 |
34 | // Unit Tests
35 | // You use them run the command: npm test main.js
36 | // to close them ctrl + C
37 | if (typeof describe === 'function') {
38 |
39 | // most are notes for human eyes to read, but essentially passes in inputs then compares if the function you built return the expected output.
40 | describe('#rockPaperScissors()', () => {
41 | it('should detect a tie', () => {
42 | assert.equal(rockPaperScissors('rock', 'rock'), "It's a tie!");
43 | assert.equal(rockPaperScissors('paper', 'paper'), "It's a tie!");
44 | assert.equal(rockPaperScissors('scissors', 'scissors'), "It's a tie!");
45 | });
46 | it('should detect which hand won', () => {
47 | assert.equal(rockPaperScissors('rock', 'paper'), "Hand two wins!");
48 | assert.equal(rockPaperScissors('paper', 'scissors'), "Hand two wins!");
49 | assert.equal(rockPaperScissors('rock', 'scissors'), "Hand one wins!");
50 | });
51 | it('should scrub input to ensure lowercase with "trim"ed whitepace', () => {
52 | assert.equal(rockPaperScissors('rOcK', ' paper '), "Hand two wins!");
53 | assert.equal(rockPaperScissors('Paper', 'SCISSORS'), "Hand two wins!");
54 | assert.equal(rockPaperScissors('rock ', 'sCiSsOrs'), "Hand one wins!");
55 | });
56 | });
57 | } else {
58 |
59 | // always returns ask the user for another input
60 | getPrompt();
61 |
62 | }
63 |
--------------------------------------------------------------------------------
/02week/pigLatin.js:
--------------------------------------------------------------------------------
1 | 'use strict';
2 |
3 | const assert = require('assert');
4 | const readline = require('readline');
5 | const rl = readline.createInterface({
6 | input: process.stdin,
7 | output: process.stdout
8 | });
9 |
10 |
11 | const pigLatin = (word) => {
12 |
13 | // Your code here
14 |
15 | }
16 |
17 |
18 | const getPrompt = () => {
19 | rl.question('word ', (answer) => {
20 | console.log( pigLatin(answer) );
21 | getPrompt();
22 | });
23 | }
24 |
25 | // Tests
26 |
27 | if (typeof describe === 'function') {
28 |
29 | describe('#pigLatin()', () => {
30 | it('should translate a simple word', () => {
31 | assert.equal(pigLatin('car'), 'arcay');
32 | assert.equal(pigLatin('dog'), 'ogday');
33 | });
34 | it('should translate a complex word', () => {
35 | assert.equal(pigLatin('create'), 'eatecray');
36 | assert.equal(pigLatin('valley'), 'alleyvay');
37 | });
38 | it('should attach "yay" if word begins with vowel', () => {
39 | assert.equal(pigLatin('egg'), 'eggyay');
40 | assert.equal(pigLatin('emission'), 'emissionyay');
41 | });
42 | it('should lowercase and trim word before translation', () => {
43 | assert.equal(pigLatin('HeLlO '), 'ellohay');
44 | assert.equal(pigLatin(' RoCkEt'), 'ocketray');
45 | });
46 | });
47 | } else {
48 |
49 | getPrompt();
50 |
51 | }
52 |
--------------------------------------------------------------------------------
/02week/tests.js:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/AustinCodingAcademy/javascript-workbook/8efeee630e047c7abb396dca9892bd2a52480583/02week/tests.js
--------------------------------------------------------------------------------
/03week/ticTacToe.js:
--------------------------------------------------------------------------------
1 | 'use strict';
2 |
3 | const assert = require('assert');
4 | const readline = require('readline');
5 | const rl = readline.createInterface({
6 | input: process.stdin,
7 | output: process.stdout
8 | });
9 | let board = [
10 | [' ', ' ', ' '],
11 | [' ', ' ', ' '],
12 | [' ', ' ', ' ']
13 | ];
14 |
15 | let playerTurn = 'X';
16 |
17 | function printBoard() {
18 | console.log(' 0 1 2');
19 | console.log('0 ' + board[0].join(' | '));
20 | console.log(' ---------');
21 | console.log('1 ' + board[1].join(' | '));
22 | console.log(' ---------');
23 | console.log('2 ' + board[2].join(' | '));
24 | }
25 |
26 | function horizontalWin() {
27 | // Your code here
28 | }
29 |
30 | function verticalWin() {
31 | // Your code here
32 | }
33 |
34 | function diagonalWin() {
35 | // Your code here
36 | }
37 |
38 | function checkForWin() {
39 | // Your code here
40 | }
41 |
42 | function ticTacToe(row, column) {
43 | // Your code here
44 | }
45 |
46 | function getPrompt() {
47 | printBoard();
48 | console.log("It's Player " + playerTurn + "'s turn.");
49 | rl.question('row: ', (row) => {
50 | rl.question('column: ', (column) => {
51 | ticTacToe(row, column);
52 | getPrompt();
53 | });
54 | });
55 |
56 | }
57 |
58 |
59 |
60 | // Tests
61 |
62 | if (typeof describe === 'function') {
63 |
64 | describe('#ticTacToe()', () => {
65 | it('should place mark on the board', () => {
66 | ticTacToe(1, 1);
67 | assert.deepEqual(board, [ [' ', ' ', ' '], [' ', 'X', ' '], [' ', ' ', ' '] ]);
68 | });
69 | it('should alternate between players', () => {
70 | ticTacToe(0, 0);
71 | assert.deepEqual(board, [ ['O', ' ', ' '], [' ', 'X', ' '], [' ', ' ', ' '] ]);
72 | });
73 | it('should check for vertical wins', () => {
74 | board = [ [' ', 'X', ' '], [' ', 'X', ' '], [' ', 'X', ' '] ];
75 | assert.equal(verticalWin(), true);
76 | });
77 | it('should check for horizontal wins', () => {
78 | board = [ ['X', 'X', 'X'], [' ', ' ', ' '], [' ', ' ', ' '] ];
79 | assert.equal(horizontalWin(), true);
80 | });
81 | it('should check for diagonal wins', () => {
82 | board = [ ['X', ' ', ' '], [' ', 'X', ' '], [' ', ' ', 'X'] ];
83 | assert.equal(diagonalWin(), true);
84 | });
85 | it('should detect a win', () => {
86 | assert.equal(checkForWin(), true);
87 | });
88 | });
89 | } else {
90 |
91 | getPrompt();
92 |
93 | }
94 |
--------------------------------------------------------------------------------
/03week/towersOfHanoi.js:
--------------------------------------------------------------------------------
1 | 'use strict';
2 |
3 | const assert = require('assert');
4 | const readline = require('readline');
5 | const rl = readline.createInterface({
6 | input: process.stdin,
7 | output: process.stdout
8 | });
9 |
10 | let stacks = {
11 | a: [4, 3, 2, 1],
12 | b: [],
13 | c: []
14 | };
15 |
16 | function printStacks() {
17 | console.log("a: " + stacks.a);
18 | console.log("b: " + stacks.b);
19 | console.log("c: " + stacks.c);
20 | }
21 |
22 | function movePiece() {
23 | // Your code here
24 |
25 | }
26 |
27 | function isLegal() {
28 | // Your code here
29 |
30 | }
31 |
32 | function checkForWin() {
33 | // Your code here
34 |
35 | }
36 |
37 | function towersOfHanoi(startStack, endStack) {
38 | // Your code here
39 |
40 | }
41 |
42 | function getPrompt() {
43 | printStacks();
44 | rl.question('start stack: ', (startStack) => {
45 | rl.question('end stack: ', (endStack) => {
46 | towersOfHanoi(startStack, endStack);
47 | getPrompt();
48 | });
49 | });
50 | }
51 |
52 | // Tests
53 |
54 | if (typeof describe === 'function') {
55 |
56 | describe('#towersOfHanoi()', () => {
57 | it('should be able to move a block', () => {
58 | towersOfHanoi('a', 'b');
59 | assert.deepEqual(stacks, { a: [4, 3, 2], b: [1], c: [] });
60 | });
61 | });
62 |
63 | describe('#isLegal()', () => {
64 | it('should not allow an illegal move', () => {
65 | stacks = {
66 | a: [4, 3, 2],
67 | b: [1],
68 | c: []
69 | };
70 | assert.equal(isLegal('a', 'b'), false);
71 | });
72 | it('should allow a legal move', () => {
73 | stacks = {
74 | a: [4, 3, 2, 1],
75 | b: [],
76 | c: []
77 | };
78 | assert.equal(isLegal('a', 'c'), true);
79 | });
80 | });
81 | describe('#checkForWin()', () => {
82 | it('should detect a win', () => {
83 | stacks = { a: [], b: [4, 3, 2, 1], c: [] };
84 | assert.equal(checkForWin(), true);
85 | stacks = { a: [1], b: [4, 3, 2], c: [] };
86 | assert.equal(checkForWin(), false);
87 | });
88 | });
89 |
90 | } else {
91 |
92 | getPrompt();
93 |
94 | }
95 |
--------------------------------------------------------------------------------
/04week/functional-javascript/helloWorld.js:
--------------------------------------------------------------------------------
1 | function upperCaser(input) {
2 | return input.toUpperCase();
3 | }
4 |
5 | module.exports = upperCaser
6 |
--------------------------------------------------------------------------------
/04week/loop.js:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/AustinCodingAcademy/javascript-workbook/8efeee630e047c7abb396dca9892bd2a52480583/04week/loop.js
--------------------------------------------------------------------------------
/04week/mastermind.js:
--------------------------------------------------------------------------------
1 | 'use strict';
2 |
3 | const assert = require('assert');
4 | const readline = require('readline');
5 | const rl = readline.createInterface({
6 | input: process.stdin,
7 | output: process.stdout
8 | });
9 |
10 | let board = [];
11 | let solution = '';
12 | let letters = ['a', 'b', 'c', 'd', 'e', 'f', 'g', 'h'];
13 |
14 | function printBoard() {
15 | for (let i = 0; i < board.length; i++) {
16 | console.log(board[i]);
17 | }
18 | }
19 |
20 | function generateSolution() {
21 | for (let i = 0; i < 4; i++) {
22 | const randomIndex = getRandomInt(0, letters.length);
23 | solution += letters[randomIndex];
24 | }
25 | }
26 |
27 | function getRandomInt(min, max) {
28 | return Math.floor(Math.random() * (max - min)) + min;
29 | }
30 |
31 | function generateHint() {
32 | // your code here
33 | }
34 |
35 | function mastermind(guess) {
36 | solution = 'abcd'; // Comment this out to generate a random solution
37 | // your code here
38 | }
39 |
40 |
41 | function getPrompt() {
42 | rl.question('guess: ', (guess) => {
43 | mastermind(guess);
44 | printBoard();
45 | getPrompt();
46 | });
47 | }
48 |
49 | // Tests
50 |
51 | if (typeof describe === 'function') {
52 | solution = 'abcd';
53 | describe('#mastermind()', () => {
54 | it('should register a guess and generate hints', () => {
55 | mastermind('aabb');
56 | assert.equal(board.length, 1);
57 | });
58 | it('should be able to detect a win', () => {
59 | assert.equal(mastermind(solution), 'You guessed it!');
60 | });
61 | });
62 |
63 | describe('#generateHint()', () => {
64 | it('should generate hints', () => {
65 | assert.equal(generateHint('abdc'), '2-2');
66 | });
67 | it('should generate hints if solution has duplicates', () => {
68 | assert.equal(generateHint('aabb'), '1-1');
69 | });
70 |
71 | });
72 |
73 | } else {
74 |
75 | generateSolution();
76 | getPrompt();
77 | }
78 |
--------------------------------------------------------------------------------
/05week/checkers.js:
--------------------------------------------------------------------------------
1 | 'use strict';
2 |
3 | const assert = require('assert');
4 | const readline = require('readline');
5 | const rl = readline.createInterface({
6 | input: process.stdin,
7 | output: process.stdout
8 | });
9 |
10 |
11 | function Checker() {
12 | // Your code here
13 | }
14 |
15 | class Board {
16 | constructor() {
17 | this.grid = []
18 | }
19 | // method that creates an 8x8 array, filled with null values
20 | createGrid() {
21 | // loop to create the 8 rows
22 | for (let row = 0; row < 8; row++) {
23 | this.grid[row] = [];
24 | // push in 8 columns of nulls
25 | for (let column = 0; column < 8; column++) {
26 | this.grid[row].push(null);
27 | }
28 | }
29 | }
30 | viewGrid() {
31 | // add our column numbers
32 | let string = " 0 1 2 3 4 5 6 7\n";
33 | for (let row = 0; row < 8; row++) {
34 | // we start with our row number in our array
35 | const rowOfCheckers = [row];
36 | // a loop within a loop
37 | for (let column = 0; column < 8; column++) {
38 | // if the location is "truthy" (contains a checker piece, in this case)
39 | if (this.grid[row][column]) {
40 | // push the symbol of the check in that location into the array
41 | rowOfCheckers.push(this.grid[row][column].symbol);
42 | } else {
43 | // just push in a blank space
44 | rowOfCheckers.push(' ');
45 | }
46 | }
47 | // join the rowOfCheckers array to a string, separated by a space
48 | string += rowOfCheckers.join(' ');
49 | // add a 'new line'
50 | string += "\n";
51 | }
52 | console.log(string);
53 | }
54 |
55 | // Your code here
56 | }
57 |
58 | class Game {
59 | constructor() {
60 | this.board = new Board;
61 | }
62 | start() {
63 | this.board.createGrid();
64 | }
65 | }
66 |
67 | function getPrompt() {
68 | game.board.viewGrid();
69 | rl.question('which piece?: ', (whichPiece) => {
70 | rl.question('to where?: ', (toWhere) => {
71 | game.moveChecker(whichPiece, toWhere);
72 | getPrompt();
73 | });
74 | });
75 | }
76 |
77 | const game = new Game();
78 | game.start();
79 |
80 |
81 | // Tests
82 | if (typeof describe === 'function') {
83 | describe('Game', () => {
84 | it('should have a board', () => {
85 | assert.equal(game.board.constructor.name, 'Board');
86 | });
87 | it('board should have 24 checkers', () => {
88 | assert.equal(game.board.checkers.length, 24);
89 | });
90 | });
91 |
92 | describe('Game.moveChecker()', () => {
93 | it('should move a checker', () => {
94 | assert(!game.board.grid[4][1]);
95 | game.moveChecker('50', '41');
96 | assert(game.board.grid[4][1]);
97 | game.moveChecker('21', '30');
98 | assert(game.board.grid[3][0]);
99 | game.moveChecker('52', '43');
100 | assert(game.board.grid[4][3]);
101 | });
102 | it('should be able to jump over and kill another checker', () => {
103 | game.moveChecker('30', '52');
104 | assert(game.board.grid[5][2]);
105 | assert(!game.board.grid[4][1]);
106 | assert.equal(game.board.checkers.length, 23);
107 | });
108 | });
109 | } else {
110 | getPrompt();
111 | }
112 |
--------------------------------------------------------------------------------
/05week/spaceTravelToMars.js:
--------------------------------------------------------------------------------
1 | 'use strict';
2 |
3 | let assert = require('assert');
4 |
5 | let jobTypes = {
6 | pilot: 'MAV',
7 | mechanic: 'Repair Ship',
8 | commander: 'Main Ship',
9 | programmer: 'Any Ship!'
10 | };
11 |
12 | // Your code here
13 |
14 | //tests
15 | if (typeof describe === 'function'){
16 | describe('CrewMember', function(){
17 | it('should have a name, a job, a specialSkill and ship upon instantiation', function(){
18 | var crewMember1 = new CrewMember('Rick Martinez', 'pilot', 'chemistry');
19 | assert.equal(crewMember1.name, 'Rick Martinez');
20 | assert.equal(crewMember1.job, 'pilot');
21 | assert.equal(crewMember1.specialSkill, 'chemistry');
22 | assert.equal(crewMember1.ship, null);
23 | });
24 |
25 | it('can enter a ship', function(){
26 | let mav = new Ship('Mars Ascent Vehicle', 'MAV', 'Ascend into low orbit');
27 | let crewMember1 = new CrewMember('Rick Martinez', 'pilot', 'chemistry');
28 | crewMember1.enterShip(mav);
29 | assert.equal(crewMember1.ship, mav);
30 | assert.equal(mav.crew.length, 1);
31 | assert.equal(mav.crew[0], crewMember1);
32 | });
33 | });
34 |
35 | describe('Ship', function(){
36 | it('should have a name, a type, an ability and an empty crew upon instantiation', function(){
37 | let mav = new Ship('Mars Ascent Vehicle', 'MAV', 'Ascend into low orbit');
38 | assert.equal(mav.name, 'Mars Ascent Vehicle');
39 | assert.equal(mav.type, 'MAV');
40 | assert.equal(mav.ability, 'Ascend into low orbit');
41 | assert.equal(mav.crew.length, 0);
42 | });
43 |
44 | it('can return a mission statement correctly', function(){
45 | let mav = new Ship('Mars Ascent Vehicle', 'MAV', 'Ascend into low orbit');
46 | let crewMember1 = new CrewMember('Rick Martinez', 'pilot', 'chemistry');
47 | let hermes = new Ship('Hermes', 'Main Ship', 'Interplanetary Space Travel');
48 | let crewMember2 = new CrewMember('Commander Lewis', 'commander', 'geology');
49 | assert.equal(mav.missionStatement(), "Can't perform a mission yet.");
50 | assert.equal(hermes.missionStatement(), "Can't perform a mission yet.");
51 |
52 | crewMember1.enterShip(mav);
53 | assert.equal(mav.missionStatement(), "Ascend into low orbit");
54 |
55 | crewMember2.enterShip(hermes);
56 | assert.equal(hermes.missionStatement(), "Interplanetary Space Travel");
57 | });
58 | });
59 | }
60 |
--------------------------------------------------------------------------------
/06week/higherOrder.js:
--------------------------------------------------------------------------------
1 | 'use strict';
2 |
3 | const assert = require('assert');
4 |
5 | function forEach(arr, callback) {
6 | // Your code here
7 | }
8 |
9 | function map(arr, callback) {
10 | // Your code here
11 | }
12 |
13 | function filter(arr, callback) {
14 | // Your code here
15 | }
16 |
17 | function some(arr, callback) {
18 | // Your code here
19 | }
20 |
21 | function every(arr, callback) {
22 | // Your code here
23 | }
24 |
25 | if (typeof describe === 'function') {
26 |
27 | describe('#forEach()', () => {
28 | it('should call the callback the array.length number of times', () => {
29 | let count = 0;
30 | forEach([1, 2, 3], () => {
31 | count++;
32 | });
33 | assert.equal(count, 3);
34 | });
35 | });
36 |
37 | describe('#map()', () => {
38 | const arr = [1, 2, 3];
39 | const mapped = map(arr, (num) => {
40 | return num * num;
41 | });
42 | it('should return new array with mapped items', () => {
43 | assert.deepEqual(mapped, [1, 4, 9]);
44 | });
45 | it('should not affect the original array', () => {
46 | assert.deepEqual(arr, [1, 2, 3]);
47 | })
48 | });
49 |
50 | describe('#filter()', () => {
51 | it('should return an array of items that pass the predicate test', () => {
52 | const filtered = filter([1, 2, 3], (num) => {
53 | return num % 2 === 0;
54 | });
55 | assert.deepEqual(filtered, [2]);
56 | });
57 | });
58 |
59 | describe('#some()', () => {
60 | let count = 0;
61 | const somed = some([1, 2, 3, 4], (num) => {
62 | count++;
63 | return num % 2 === 0;
64 | });
65 | it('should return true if at least one item passes the predicate test', () => {
66 | assert.equal(somed, true);
67 | });
68 | it('should stop at the first item that passes the predicate test', () => {
69 | assert.equal(count, 2);
70 | });
71 | it('should return false if no items pass the predicate test', () => {
72 | const somed = some([1, 3, 5], (num) => {
73 | return num % 2 === 0;
74 | });
75 | assert.equal(somed, false);
76 | });
77 | });
78 |
79 | describe('#every()', () => {
80 | it('should return true if at all passes the predicate test', () => {
81 | const everied = every([2, 4, 6], (num) => {
82 | return num % 2 === 0;
83 | });
84 | assert.equal(everied, true);
85 | });
86 | let count = 0;
87 | const everied = every([2, 3, 4, 5], (num) => {
88 | count++;
89 | return num % 2 === 0;
90 | });
91 | it('should return false if any item fails the predicate test', () => {
92 | assert.equal(everied, false);
93 | });
94 | it('should stop at the first item that fails the predicate test', () => {
95 | assert.equal(count, 2);
96 | });
97 | });
98 |
99 | } else {
100 |
101 | console.log('Only run the tests on this one!')
102 |
103 | }
104 |
--------------------------------------------------------------------------------
/07week/ticTacToe/index.html:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 | Tic Tac Toe
6 |
7 |
8 |
9 |
10 |
11 |
12 |
13 |
14 |
15 |
16 |
--------------------------------------------------------------------------------
/07week/ticTacToe/script.js:
--------------------------------------------------------------------------------
1 | 'use strict';
2 |
3 | class TicTacToe extends React.Component {
4 | constructor(props) {
5 | super(props);
6 | }
7 |
8 | render() {
9 | return (
10 |
27 | );
28 | }
29 | }
30 |
31 | ReactDOM.render(, document.getElementById('tic-tac-toe'));
32 |
--------------------------------------------------------------------------------
/07week/ticTacToe/style.css:
--------------------------------------------------------------------------------
1 | div[data-cell] {
2 | width: 100px;
3 | height: 100px;
4 | background-color: #f2f2f2;
5 | float: left;
6 | border: 1px solid #808080;
7 | font-size: 100px;
8 | text-align: center;
9 | }
10 |
11 | .row {
12 | clear: both;
13 | }
14 |
15 | #announce-winner {
16 | clear: both;
17 | font-size: 50px;
18 | }
19 |
--------------------------------------------------------------------------------
/07week/towersOfHanoi/index.html:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 | Towers of Hanoi
6 |
7 |
8 |
9 |
10 |
11 |
12 |
13 |
14 |
15 |
16 |
--------------------------------------------------------------------------------
/07week/towersOfHanoi/script.js:
--------------------------------------------------------------------------------
1 | 'use strict';
2 |
3 | class TowersOfHanoi extends React.Component {
4 | constructor(props) {
5 | super(props);
6 | }
7 |
8 | render() {
9 | return (
10 |
11 |
17 |
18 |
19 |
20 |
21 |
22 | );
23 | }
24 | }
25 |
26 | ReactDOM.render(, document.getElementById('towers-of-hanoi'));
27 |
--------------------------------------------------------------------------------
/07week/towersOfHanoi/style.css:
--------------------------------------------------------------------------------
1 | [data-stack] {
2 | display: flex;
3 | justify-content: flex-start;
4 | align-items: center;
5 | height: 101px;
6 | background-color: aliceblue;
7 | margin: 25px;
8 | }
9 |
10 | [data-block] {
11 | width: 25px;
12 | float: left;
13 | }
14 |
15 | [data-block="25"] {
16 | height: 25px;
17 | background-color: blue;
18 | }
19 |
20 | [data-block="50"] {
21 | height: 50px;
22 | background-color: green;
23 | }
24 |
25 | [data-block="75"] {
26 | height: 75px;
27 | background-color: red;
28 | }
29 |
30 | [data-block="100"] {
31 | height: 100px;
32 | background-color: yellow;
33 | }
34 |
35 | #announce-game-won {
36 | font-size: 50px;
37 | text-align: center;
38 | }
39 |
--------------------------------------------------------------------------------
/08week/bootstrap/index.html:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 | Bootstrap
6 |
7 |
8 |
9 |
10 |
11 |
12 |
13 |
14 |
15 |
16 |
17 |
--------------------------------------------------------------------------------
/08week/bootstrap/script.js:
--------------------------------------------------------------------------------
1 | 'use strict';
2 |
--------------------------------------------------------------------------------
/08week/bootstrap/style.css:
--------------------------------------------------------------------------------
1 |
2 |
--------------------------------------------------------------------------------
/08week/fetch/index.html:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 | Fetch
6 |
7 |
8 |
9 |
10 |
11 |
12 |
13 |
14 |
15 |
16 |
17 |
--------------------------------------------------------------------------------
/08week/fetch/script.js:
--------------------------------------------------------------------------------
1 | 'use strict';
2 |
--------------------------------------------------------------------------------
/08week/fetch/style.css:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/AustinCodingAcademy/javascript-workbook/8efeee630e047c7abb396dca9892bd2a52480583/08week/fetch/style.css
--------------------------------------------------------------------------------
/09week/hackernews/index.html:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 | Hacker News
6 |
7 |
8 |
9 |
10 |
11 |
12 |
13 |
14 |
15 |
--------------------------------------------------------------------------------
/09week/hackernews/script.js:
--------------------------------------------------------------------------------
1 | 'use strict';
2 |
--------------------------------------------------------------------------------
/10week/algorithms.js:
--------------------------------------------------------------------------------
1 | 'use strict';
2 |
3 | const assert = require('assert');
4 |
5 | function getRandomInt(min, max) {
6 | min = Math.ceil(min);
7 | max = Math.floor(max);
8 | return Math.floor(Math.random() * (max - min)) + min;
9 | }
10 |
11 | let arr = [];
12 |
13 | for (let i = 0; i < 1000; i++) {
14 | arr.push(getRandomInt(0, 1000));
15 | }
16 |
17 | function bubbleSort(arr) {
18 | // Your code here
19 | }
20 |
21 | function mergeSort(arr) {
22 | // Your code here
23 | }
24 |
25 | function binarySearch(arr, item) {
26 | // Your code here
27 | }
28 |
29 | // Tests
30 |
31 | if (typeof describe === 'function') {
32 |
33 | function comparator(a, b) {
34 | if (Number(a) < Number(b)) return -1;
35 | if (Number(a) > Number(b)) return 1;
36 | return 0;
37 | }
38 |
39 | describe('#bubbleSort()', () => {
40 | it('should sort array', () => {
41 | const sorted = bubbleSort(arr);
42 | assert.deepEqual(sorted, arr.sort(comparator));
43 | });
44 | });
45 |
46 | describe('#mergeSort()', () => {
47 | it('should sort array', () => {
48 | const sorted = mergeSort(arr);
49 | assert.deepEqual(sorted, arr.sort(comparator));
50 | });
51 | });
52 |
53 | describe('#binarySearch()', () => {
54 | it('should return the index of given item if sorted array contains it', () => {
55 | const idx = binarySearch([1, 2, 3, 4], 3);
56 | assert.equal(idx, 2);
57 | });
58 | it('should return false if item not in sorted array', () => {
59 | const idx = binarySearch([1, 2, 3, 4], 5);
60 | assert.equal(idx, false);
61 | });
62 | });
63 |
64 | } else {
65 |
66 | console.log('Run the tests!')
67 |
68 | }
69 |
--------------------------------------------------------------------------------
/README.md:
--------------------------------------------------------------------------------
1 | [](https://circleci.com/gh/AustinCodingAcademy/javascript-workbook/tree/gh-pages)
2 |
3 | 
4 | # Austin Coding Academy
5 |
6 | ## JavaScript Workbook
7 |
8 | ### Claiming your workbook
9 |
10 | 1. Click the 'Fork' button (choose your account if prompted).
11 | 1. Copy HTTPS URL from your forked repository
12 | 1. In your terminal (or in git bash, for Windows people), navigate (using `cd`)
13 | into a directory where you want to start keeping your repositories.
14 | 1. Clone your new repository by typing `git clone ` (the HTTPS
15 | URL you copied above)
16 | 
17 | 1. Now go into the new directory by using `cd javascript-workbook`
18 | 1. Add the base repository as an upstream
19 | `git remote add upstream https://github.com/AustinCodingAcademy/javascript-workbook.git`
20 | 1. Check the configuration of your remotes with `git remote -v`, it should look
21 | very similar to this (except it'll be YOUR username)
22 |
23 | ```bash
24 | $ git remote -v
25 |
26 | origin git@github.com:username/javascript-workbook.git (fetch)
27 | origin git@github.com:username/javascript-workbook.git (push)
28 | upstream git@github.com:AustinCodingAcademy/javascript-workbook.git (fetch)
29 | upstream git@github.com:AustinCodingAcademy/javascript-workbook.git (push)
30 | ```
31 |
32 | ### Push to Github and create a PR
33 |
34 | 1. From your project directory, run `npm install` to tell NPM to install all the
35 | node modules we use in this class
36 | 1. Use Atom (or another editor) to make the change to the `index.html` file in
37 | the top level directory. Change `Hello World!` to `Hello !`
38 | 1. When you're finished, stage your file, commit your changes, and push to
39 | GitHub using the following commands:
40 | ```bash
41 | git status
42 | git add .
43 | git commit -m "Initial Commit"
44 | git push origin gh-pages
45 | ```
46 |
47 | 1. Now go to your forked repository on GitHub (at
48 | https://github.com/your-username/javascript-workbook). A little yellow box
49 | should have popped up asking you to make a Pull Request. Click to review.
50 |
51 | 1. Click "Create Pull Request"
52 |
53 | 1. Every time you make a change *and push to GitHub*, this PR will automatically
54 | update. No need to do it more than once.
55 |
56 | #### Get latest workbook updates
57 |
58 | 1. To get the latest code/homework/test updates, be sure to have a "clean
59 | working directory" by committing or removing all of your changes. You check for
60 | a "clean working environment" by running `git status` and making sure no files
61 | show up.
62 |
63 | 1. Run `git pull upstream gh-pages`
64 |
65 | 
66 |
67 | ### Running the apps
68 | Simply run `node path/to/file.js`
69 |
70 | example `node 01week/rockPaperScissors.js`
71 |
72 | ### Running Tests
73 | Tests are a great way to make sure you code works the way you planned it would,
74 | and to make sure you don't break something in the future. We will be using them
75 | to test our understanding of the lesson. It's also our main way to assign grades
76 | for an assignment.
77 |
78 | To run a the tests on a file run `npm test path/to/file.js`, etc.
79 |
80 | ### Running the Linter
81 | Simply run `npm run lint`
82 |
83 | #### Running the Server
84 | 1. Run `npm start`
85 | 1. To break out of the server, press `ctrl` + `c`
86 |
--------------------------------------------------------------------------------
/extra-challenges/01challenge.js:
--------------------------------------------------------------------------------
1 | 'use strict';
2 |
3 | var assert = require('assert');
4 |
5 | // ****
6 | // Basic Data Types
7 | // ****
8 |
9 | // Problem 0:
10 | // To start out we are declaring a variable named myUndefined
11 | // Note that we are not assigning a value, so it is undefined.
12 |
13 | var myUndefined;
14 |
15 | // Problem 1:
16 | // Let's create a new variable named myNull and give it the value null.
17 | //
18 | // What is the difference between null and undefined?
19 |
20 | var myNull;
21 |
22 | // Problem 2:
23 | // Let's create a new variable named myTrue and give it the value true.
24 |
25 | var myTrue;
26 |
27 | // Problem 3:
28 | // Let's create a new variable named myFalse and give it the value false.
29 |
30 | var myFalse;
31 |
32 | // Problem 4:
33 | // Let's create a new variable named myNumber. Assign it a number.
34 |
35 | var myNumber;
36 |
37 | // Problem 5:
38 | // Let's create a new variable named myString. Assign it a string.
39 |
40 | var myString;
41 |
42 | // ****
43 | // Boolean Operators
44 | // ****
45 |
46 | // Problem 6:
47 | // What is the value of true && true
48 |
49 | var trueAndTrue;
50 |
51 | // Problem 7:
52 | // What is the value of false && true
53 |
54 | var falseAndTrue;
55 |
56 | // Problem 8:
57 | // What is the value of true && false
58 |
59 | var trueAndFalse;
60 |
61 | // Problem 9:
62 | // What is the value of false && false
63 |
64 | var falseAndFalse;
65 |
66 | // Problem 10:
67 | // What is the value of true || true
68 |
69 | var trueOrTrue;
70 |
71 | // Problem 11:
72 | // What is the value of false || true
73 |
74 | var falseOrTrue;
75 |
76 | // Problem 12:
77 | // What is the value of true || false
78 |
79 | var trueOrFalse;
80 |
81 | // Problem 13:
82 | // What is the value of false || false
83 |
84 | var falseOrFalse;
85 |
86 | // Problem 14:
87 | // What is the value of !false
88 |
89 | var notFalse;
90 |
91 | // Problem 15:
92 | // What is the value of !true
93 |
94 | var notTrue;
95 |
96 | // Problem 16:
97 | // What is the value of !!true
98 |
99 | var notNotTrue;
100 |
101 | // ****
102 | // Concept Checkpoint
103 | //
104 | // Write your answer in comments
105 | //
106 | // What is the difference between the "and" and the "or" operators? Explain why you would use each of them.
107 | //
108 | // Your Answer Goes Here:
109 | //
110 | // ****
111 |
112 | // ****
113 | // Truthiness
114 | // ****
115 |
116 | var bob = 'bob';
117 | var emptyString = '';
118 |
119 | // Problem 17:
120 | // What is the value of !!bob
121 |
122 | var notNotBob;
123 |
124 | // Problem 18:
125 | // What is the value of !!emptyString
126 |
127 | var notNotEmptyString;
128 |
129 | // Problem 19:
130 | // What is the value of !null
131 |
132 | var notNull;
133 |
134 | // Problem 20:
135 | // What is the value of !!undefined
136 |
137 | var notNotUndefined;
138 |
139 | // ****
140 | // Concept Checkpoint
141 | //
142 | // Write your answer in comments
143 | //
144 | // Explain truthiness and falsiness in your own words. Provide an example for each.
145 | //
146 | // Your Answer Goes Here:
147 | //
148 | // ****
149 |
150 | // ****
151 | // Comparison Operators
152 | // ****
153 |
154 | // Problem 21
155 | // What is the value of 4 === 4
156 | var fourEqualTofour;
157 |
158 | // Problem 22:
159 | // What is the value of 4 !== 4
160 | var fourNotEqualTofour;
161 |
162 | // Problem 23:
163 | // What is the value of -3 === 10
164 | var negativeThreeEqualToTen;
165 |
166 | // Problem 24:
167 | // What is the value of -3 < 10
168 | var negativeThreeLessThanTen;
169 |
170 | // Problem 25:
171 | // What is the value of -3 <= 10
172 | var negativeThreeLessThanOrEqualToTen;
173 |
174 | // Problem 26:
175 | // What is the value of -3 > 10
176 | var negativeThreeGreaterThanTen;
177 |
178 | // Problem 27:
179 | // What is the value of -3 >= 10
180 | var negativeThreeGreaterThanOrEqualToTen;
181 |
182 | // Problem 28:
183 | // What is the value of '4' == 4
184 | var stringFourEqualsNumberFour;
185 |
186 | // Problem 29:
187 | // What is the value of '4' != 4
188 | var stringFourNotEqualsNumberFour;
189 |
190 | // Problem 30:
191 | // What is the value of '4' === 4
192 | var stringFourStrictEqualsNumberFour;
193 |
194 | // Problem 31:
195 | // What is the value of '4' !== 4
196 | var stringFourStrictNotEqualsNumberFour;
197 |
198 | // ****
199 | // Concept Checkpoint
200 | //
201 | // Write your answer in comments
202 | //
203 | // What’s the difference between == and ===?
204 | //
205 | // Your Answer Goes Here:
206 | //
207 | //
208 | // What’s the difference between != and !==?
209 | //
210 | // Your Answer Goes Here:
211 | //
212 | // ****
213 |
214 |
215 | // ****
216 | // Tests
217 | // ****
218 |
219 | describe('Lesson 1 Homework', function () {
220 |
221 | describe('Data Type Problems', function () {
222 | describe('Problem 0: undefined variable myUndefined', function () {
223 | it('should be undefined', function () {
224 | assert.equal(typeof myUndefined, 'undefined');
225 | });
226 | });
227 |
228 | describe('Problem 1: null variable myNull', function () {
229 | it('should be null', function () {
230 | assert(myNull === null);
231 | });
232 | });
233 |
234 | describe('Problem 2: true variable myTrue', function () {
235 | it('should be true', function () {
236 | assert.equal(myTrue, true);
237 | });
238 | });
239 |
240 | describe('Problem 3: false variable myFalse', function () {
241 | it('should be false', function () {
242 | assert.equal(myFalse, false);
243 | });
244 | });
245 |
246 | describe('Problem 4: number variable myNumber', function () {
247 | it('should be a number', function () {
248 | assert.equal(typeof myNumber, 'number');
249 | });
250 | });
251 |
252 | describe('Problem 5: string variable myString', function () {
253 | it('should be a string', function () {
254 | assert.equal(typeof myString, 'string');
255 | });
256 | });
257 | });
258 |
259 | describe('Boolean Operators', function () {
260 | describe('Problem 6: true && true', function () {
261 | it('should be true', function () {
262 | assert.equal(trueAndTrue, true && true);
263 | });
264 | });
265 |
266 | describe('Problem 7: false && true', function () {
267 | it('should be false', function () {
268 | assert.equal(falseAndTrue, false && true);
269 | });
270 | });
271 |
272 | describe('Problem 8: true && false', function () {
273 | it('should be false', function () {
274 | assert.equal(trueAndFalse, true && false);
275 | });
276 | });
277 |
278 | describe('Problem 9: false && false', function () {
279 | it('should be false', function () {
280 | assert.equal(falseAndFalse, false && false);
281 | });
282 | });
283 |
284 | describe('Problem 10: true || true', function () {
285 | it('should be true', function () {
286 | assert.equal(trueOrTrue, true || true);
287 | });
288 | });
289 |
290 | describe('Problem 11: false || true', function () {
291 | it('should be true', function () {
292 | assert.equal(falseOrTrue, false || true);
293 | });
294 | });
295 |
296 | describe('Problem 12: true || false', function () {
297 | it('should be true', function () {
298 | assert.equal(trueOrFalse, true || false);
299 | });
300 | });
301 |
302 | describe('Problem 13: false || false', function () {
303 | it('should be false', function () {
304 | assert.equal(falseOrFalse, false || false);
305 | });
306 | });
307 |
308 | describe('Problem 14: !false', function () {
309 | it('should be true', function () {
310 | assert.equal(notFalse, !false);
311 | });
312 | });
313 |
314 | describe('Problem 15: !true', function () {
315 | it('should be false', function () {
316 | assert.equal(notTrue, !true);
317 | });
318 | });
319 |
320 | describe('Problem 16: !!true', function () {
321 | it('should be true', function () {
322 | assert.equal(notNotTrue, !!true);
323 | });
324 | });
325 | });
326 |
327 | describe('Truthiness', function () {
328 |
329 | describe('Problem 17: !!bob', function () {
330 | it('should be true', function () {
331 | assert.equal(notNotBob, !!bob);
332 | });
333 | });
334 |
335 | describe('Problem 18: !!emptyString', function () {
336 | it('should be false', function () {
337 | assert.equal(notNotEmptyString, !!emptyString);
338 | });
339 | });
340 |
341 | describe('Problem 19: !null', function () {
342 | it('should be true', function () {
343 | assert.equal(notNull, !null);
344 | });
345 | });
346 |
347 | describe('Problem 20: !!undefined', function () {
348 | it('should be false', function () {
349 | assert.equal(notNotUndefined, !!undefined);
350 | });
351 | });
352 | });
353 |
354 | describe('Comparison Operators', function () {
355 | describe('Problem 21: 4 === 4', function () {
356 | it('should be true', function () {
357 | assert.equal(fourEqualTofour, 4 === 4);
358 | });
359 | });
360 |
361 | describe('Problem 22: 4 !== 4', function () {
362 | it('should be false', function () {
363 | assert.equal(fourNotEqualTofour, 4 !== 4);
364 | });
365 | });
366 |
367 | describe('Problem 23: -3 === 10', function () {
368 | it('should be false', function () {
369 | assert.equal(negativeThreeEqualToTen, -3 === 10);
370 | });
371 | });
372 |
373 | describe('Problem 24: -3 < 10', function () {
374 | it('should be true', function () {
375 | assert.equal(negativeThreeLessThanTen, -3 < 10);
376 | });
377 | });
378 |
379 | describe('Problem 25: -3 <= 10', function () {
380 | it('should be true', function () {
381 | assert.equal(negativeThreeLessThanOrEqualToTen, -3 <= 10);
382 | });
383 | });
384 |
385 | describe('Problem 26: -3 > 10', function () {
386 | it('should be false', function () {
387 | assert.equal(negativeThreeGreaterThanTen, -3 > 10);
388 | });
389 | });
390 |
391 | describe('Problem 27: -3 >= 10', function () {
392 | it('should be false', function () {
393 | assert.equal(negativeThreeGreaterThanOrEqualToTen, -3 >= 10);
394 | });
395 | });
396 |
397 | describe('Problem 28: \'4\' == 4', function () {
398 | it('should be true', function () {
399 | assert.equal(stringFourEqualsNumberFour, '4' == 4);
400 | });
401 | });
402 |
403 | describe('Problem 29: \'4\' != 4', function () {
404 | it('should be false', function () {
405 | assert.equal(stringFourNotEqualsNumberFour, '4' != 4);
406 | });
407 | });
408 |
409 | describe('Problem 30: \'4\' === 4', function () {
410 | it('should be false', function () {
411 | assert.equal(stringFourStrictEqualsNumberFour, '4' === 4);
412 | });
413 | });
414 |
415 | describe('Problem 31: \'4\' !== 4', function () {
416 | it('should be true', function () {
417 | assert.equal(stringFourStrictNotEqualsNumberFour, '4' !== 4);
418 | });
419 | });
420 | });
421 |
422 | });
423 |
--------------------------------------------------------------------------------
/extra-challenges/02challenge.js:
--------------------------------------------------------------------------------
1 | 'use strict';
2 |
3 | var assert = require('assert');
4 |
5 | // ****
6 | // Functions
7 | // ****
8 |
9 | // Problem 0:
10 | // alwaysFalse() is a function that always
11 | // returns the boolean value false
12 |
13 | function alwaysFalse() {
14 | return false;
15 | }
16 |
17 | // You can also define functions this way,
18 | // by assigning function definitions to variable
19 | var alwaysTrue = function () {
20 | return true;
21 | };
22 |
23 | // Problem 1:
24 | // equals(argument1, argument2) is an empty function
25 | // return a boolean expression that is true when
26 | // argument1 is equal to argument2
27 |
28 | function equals(argument1, argument2) {
29 | }
30 |
31 | // Problem 2:
32 | // lessThanOrEqualTo(parameter1, parameter2) is an empty function
33 | // return a boolean expression that is true when
34 | // parameter1 is less than or equal to parameter2
35 |
36 | function lessThanOrEqualTo(parameter1, parameter2) {
37 | }
38 |
39 | // Problem 3:
40 | // write a function named add(number1, number2)
41 | // add will add two numbers and return the result
42 |
43 | // Problem 4:
44 | // write a function named addThree(number1, number2, number3)
45 | // this function will add three numbers
46 | // you must call your function add() in addThree()
47 |
48 |
49 | // ****
50 | // Concept Checkpoint
51 | //
52 | // Write your answer in comments
53 | //
54 | // What is a function? How do you define a function in Javascript?
55 | //
56 | // Your Answer Goes Here:
57 | //
58 | //
59 | // What is a return value?
60 | //
61 | // Your Answer Goes Here:
62 | //
63 | //
64 | // How do you define a named function?
65 | //
66 | // Your Answer Goes Here:
67 | //
68 | //
69 | // What is a parameter? What is an argument? Is there a difference between the two?
70 | //
71 | // Your Answer Goes Here:
72 | //
73 | // ****
74 |
75 |
76 | // ****
77 | // Modulo % Operator
78 | // ****
79 |
80 | // Problem 5:
81 | // isEven(number) is a function that
82 | // returns true if number is even (divisible by 2),
83 | // else returns false
84 | // complete isEven() by returning a boolean expression
85 |
86 | function isEven(number) {
87 | }
88 |
89 | // Problem 6:
90 | // isDivisibleByThree(number) is a function that
91 | // returns true if number is divisible by 3,
92 | // else returns false
93 | // complete isDivisibleByThree() by returning a boolean expression
94 |
95 | function isDivisibleByThree(number) {
96 | }
97 |
98 | // ****
99 | // Conditionals
100 | // ****
101 |
102 |
103 | // Problem 7:
104 | // whichSpecies(character) is a function that
105 | // should return "dog" when character is 'scooby'
106 | // should return "cat" when character is 'garfield'
107 | // should return "fish" when character is 'nemo'
108 | // should return false if character is anything else
109 |
110 | function whichSpecies(character) {
111 | }
112 |
113 | // Problem 8:
114 | // write a function named testNumber(number) with the following requirements.
115 | // The function should:
116 | // return the string "divisible by 4" when number % 4 === 0
117 | // return the string "divisible by 2" when number % 2 === 0
118 | // return the string "divisible by 3" when number % 3 === 0
119 | // return the string "divisible by 5" when number % 5 === 0
120 |
121 |
122 | // ****
123 | // Concept Checkpoint
124 | //
125 | // Write your answer in comments
126 | //
127 | // In your own words, explain what conditionals do.
128 | //
129 | // Your Answer Goes Here:
130 | //
131 | //
132 | // ****
133 |
134 | // ****
135 | // Tests
136 | // ****
137 |
138 | describe('Lesson 2 Homework', function () {
139 |
140 | describe('Functions', function () {
141 | describe('Problem 0: alwaysFalse()', function () {
142 | it('should return false', function () {
143 | assert.equal(alwaysFalse(), false);
144 | });
145 | });
146 |
147 | describe('Problem 0: alwaysTrue()', function () {
148 | it('should return true', function () {
149 | assert.equal(alwaysTrue(), true);
150 | });
151 | });
152 |
153 | describe('Problem 1: equals()', function () {
154 | it('should return true when argument 1 equals argument 2, else return false', function () {
155 | assert.equal(equals(3, 3), true);
156 | assert.equal(equals(3, null), false);
157 | assert.equal(equals('bob', ''), false);
158 | assert.equal(equals('bob', 'bob'), true);
159 | });
160 | });
161 |
162 | describe('Problem 2: lessThanOrEqualTo()', function () {
163 | it('should return true when parameter 1 is less than or equal to parameter 2, else return false', function () {
164 | assert.equal(lessThanOrEqualTo(3, 3), true);
165 | assert.equal(lessThanOrEqualTo(3, 4), true);
166 | assert.equal(lessThanOrEqualTo(4, 1), false);
167 | });
168 | });
169 |
170 | describe('Problem 3: add(number1, number2)', function () {
171 | it('should be defined and of type function', function () {
172 | assert(!(typeof add === 'undefined'));
173 | assert(typeof add === 'function');
174 | });
175 |
176 | it('should add two numbers and return the result', function () {
177 | assert.equal(add(3, 3), 6);
178 | assert.equal(add(3, 7), 10);
179 | });
180 | });
181 |
182 | describe('Problem 4: addThree(number1, number2, number3)', function () {
183 | it('should be defined and of type function', function () {
184 | assert(!(typeof addThree === 'undefined'));
185 | assert(typeof addThree === 'function');
186 | });
187 |
188 | it('should add three numbers and return the result', function () {
189 | assert.equal(addThree(3, 3, 3), 9);
190 | });
191 | });
192 | });
193 |
194 | describe('Modulo % operator', function () {
195 | describe('Problem 5: isEven(number)', function () {
196 | it('should return true if number is even, else false', function () {
197 | assert.equal(isEven(4), true);
198 | assert.equal(isEven(3), false);
199 | });
200 | });
201 |
202 | describe('Problem 6: isDivisibleByThree(number)', function () {
203 | it('should return true if number is divisible by 3, else false', function () {
204 | assert.equal(isDivisibleByThree(3), true);
205 | assert.equal(isDivisibleByThree(4), false);
206 | });
207 | });
208 | });
209 |
210 | describe('Conditionals', function() {
211 | describe('Problem 7: whichSpecies(character)', function () {
212 | it('should return "dog" when character is scooby', function () {
213 | assert.equal(whichSpecies('scooby'), 'dog');
214 | });
215 | it('should return "cat" when character is garfield', function () {
216 | assert.equal(whichSpecies('garfield'), 'cat');
217 | });
218 | it('should return "fish" when character is nemo', function () {
219 | assert.equal(whichSpecies('nemo'), 'fish');
220 | });
221 | it('should return false if character is anything else', function () {
222 | assert.equal(whichSpecies('stitch'), false);
223 | });
224 | });
225 |
226 | describe('Problem 8: testNumber(number)', function () {
227 | it('should be defined and of type function', function () {
228 | assert(!(typeof testNumber === 'undefined'));
229 | assert(typeof testNumber === 'function');
230 | });
231 |
232 | it('should return "divisible by 4" when number is divisible by 4', function () {
233 | assert.equal(testNumber(4), 'divisible by 4');
234 | });
235 | it('should return "divisible by 2" when number is divisible by 2', function () {
236 | assert.equal(testNumber(2), 'divisible by 2');
237 | });
238 | it('should return "divisible by 3" when number is divisible by 3', function () {
239 | assert.equal(testNumber(3), 'divisible by 3');
240 | });
241 | it('should return "divisible by 5" when number is divisible by 5', function () {
242 | assert.equal(testNumber(5), 'divisible by 5');
243 | });
244 | });
245 | });
246 |
247 | });
248 |
--------------------------------------------------------------------------------
/extra-challenges/03challenge.js:
--------------------------------------------------------------------------------
1 | 'use strict';
2 |
3 | var assert = require('assert');
4 |
5 | // ****
6 | // Scope
7 | // ****
8 |
9 | // DO NOT MODIFY
10 | var lastName = 'plaid';
11 |
12 | // DO NOT MODIFY
13 | function printFullName() {
14 | var firstName = 'bob';
15 | return firstName + lastName;
16 | }
17 |
18 | // DO NOT MODIFY
19 | var firstName = 'susan';
20 |
21 | // Problem 1:
22 | // What is the value of firstName at this point in the file?
23 | var valueOfFirstName;
24 |
25 | // Problem 2:
26 | // What is the value of lastName at this point in the file?
27 | var valueOfLastName;
28 |
29 | // Problem 3:
30 | // Fix the following function so that it returns the first argument
31 | function returnTheFirstArgument(firstArgument) {
32 | var firstArgument = 'bob';
33 | return firstArgument;
34 | }
35 |
36 | // ****
37 | // Concept Checkpoint
38 | //
39 | // Write your answer in comments
40 | //
41 | // What is scope?
42 | //
43 | // Your Answer Goes Here:
44 | //
45 | //
46 |
47 |
48 | // ****
49 | // Ternary Operator
50 | // ****
51 |
52 | // DO NOT MODIFY
53 | var ternaryResult1 = true ? 'first' : 'second';
54 | var ternaryResult2 = false ? 'first' : 'second';
55 | var ternaryResult3 = 4 ? 'first' : 'second';
56 | var ternaryResult4 = "" ? 'first' : 'second';
57 |
58 | // Problem 4:
59 | // What is the value of ternaryResult1
60 | var problemFourAnswer;
61 |
62 | // Problem 5:
63 | // What is the value of ternaryResult2
64 | var problemFiveAnswer;
65 |
66 | // Problem 6:
67 | // What is the value of ternaryResult3
68 | var problemSixAnswer;
69 |
70 | // Problem 7:
71 | // What is the value of ternaryResult4
72 | var problemSevenAnswer;
73 |
74 | // ****
75 | // Concept Checkpoint
76 | //
77 | // Write your answer in comments
78 | //
79 | // What is the ternary operator? How does it differ from normal conditional statements?
80 | //
81 | // Your Answer Goes Here:
82 | //
83 | //
84 |
85 |
86 | // ****
87 | // Arrays
88 | // ****
89 |
90 | // Problem 8:
91 | // Create an empty array
92 | var emptyArray;
93 |
94 | // Problem 9:
95 | // Create an array with 5 elements in it
96 | var lengthFiveArray;
97 |
98 | // DO NOT MODIFY
99 | var nameArray = ['bob', 'fred', 'susan'];
100 |
101 | // Problem 10:
102 | // Replace the value 'fred' in nameArray with 'george'
103 |
104 | // DO NOT MODIFY
105 | var threeByThreeArray = [
106 | [1, 2, 3],
107 | [4, 5, 6],
108 | [7, 8, 9]
109 | ];
110 |
111 | // Problem 11:
112 | // Replace the center element of threeByThreeArray, which is 5, with something else.
113 |
114 | // Problem 12:
115 | // create a 2 by 2 (2 rows, 2 columns) nested array
116 | var twoByTwoArray;
117 |
118 | // ****
119 | // Tests
120 | // DO NOT MODIFY CODE BELOW!!!!!
121 | // ****
122 |
123 | describe('Lesson 3 Homework', function () {
124 |
125 | describe('Scope', function () {
126 | describe('Problem 1: firstName', function () {
127 | it('should be susan', function () {
128 | assert.equal(firstName, valueOfFirstName);
129 | });
130 | });
131 |
132 | describe('Problem 2: lastName', function () {
133 | it('should be plaid', function () {
134 | assert.equal(lastName, valueOfLastName);
135 | });
136 | });
137 |
138 | describe('Problem 3: returnTheFirstArgument()', function () {
139 | it('should return the first argument', function () {
140 | assert.equal(returnTheFirstArgument('bob'), 'bob');
141 | assert.equal(returnTheFirstArgument(4), 4);
142 | assert.equal(returnTheFirstArgument(null), null);
143 | });
144 | });
145 | });
146 |
147 | describe('Ternary Operator', function () {
148 | describe('Problem 4: ternaryResult1', function () {
149 | it('should be \'first\'', function () {
150 | assert.equal(ternaryResult1, problemFourAnswer);
151 | });
152 | });
153 |
154 | describe('Problem 5: ternaryResult2', function () {
155 | it('should be \'second\'', function () {
156 | assert.equal(ternaryResult2, problemFiveAnswer);
157 | });
158 | });
159 |
160 | describe('Problem 6: ternaryResult3', function () {
161 | it('should be \'first\'', function () {
162 | assert.equal(ternaryResult3, problemSixAnswer);
163 | });
164 | });
165 |
166 | describe('Problem 7: ternaryResult4', function () {
167 | it('should be \'second\'', function () {
168 | assert.equal(ternaryResult4, problemSevenAnswer);
169 | });
170 | });
171 | });
172 |
173 | describe('Arrays', function () {
174 | describe('Problem 8: emptyArray', function () {
175 | it('should be an empty array', function () {
176 | assert.equal(emptyArray.length, 0);
177 | });
178 | });
179 |
180 | describe('Problem 9: lengthFiveArray', function () {
181 | it('should have 5 elements', function () {
182 | assert.equal(lengthFiveArray.length, 5);
183 | });
184 | });
185 |
186 | describe('Problem 10: replace \'fred\' with \'george\'', function () {
187 | it('should be \'george\'', function () {
188 | assert.equal(nameArray[1], 'george');
189 | });
190 | });
191 |
192 | describe('Problem 11: replace the center element', function () {
193 | it('should not equal 5', function () {
194 | assert(threeByThreeArray[1][1] !== 5);
195 | });
196 | });
197 |
198 | describe('Problem 12: twoByTwoArray', function () {
199 | it('should be a 2x2 array', function () {
200 | assert(twoByTwoArray.length === 2);
201 | assert(twoByTwoArray[0].length === 2);
202 | assert(twoByTwoArray[1].length === 2);
203 | });
204 | });
205 | });
206 | });
207 |
--------------------------------------------------------------------------------
/extra-challenges/04challenge.js:
--------------------------------------------------------------------------------
1 | 'use strict';
2 |
3 | var assert = require('assert');
4 |
5 | // ****
6 | // Popular Array Methods
7 | //
8 | // Refer to your textbook, MDN, and other good documentation online.
9 | // https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array
10 | // ****
11 |
12 | // DO NOT MODIFY
13 | var numberArray = [1, 2, 3, 4, 5];
14 |
15 | // Problem 1:
16 | // Show what numberArray would look like if we called numberArray.pop()
17 | var numberArrayAfterPop = [];
18 |
19 | // Problem 2:
20 | // Show what numberArray would look like if we called numberArray.shift()
21 | var numberArrayAfterShift = [];
22 |
23 | // Problem 3:
24 | // Show what numberArray would look like if we called numberArray.push(6)
25 | var numberArrayAfterPush = [];
26 |
27 | // Problem 4:
28 | // Show what numberArray would look like if we called numberArray.unshift(0)
29 | var numberArrayAfterUnshift = [];
30 |
31 | // Problem 5:
32 | // Use pop() and shift() to make the array bravestWarriors look like this:
33 | // ['Danny', 'Chris', 'Beth', 'Wallow']
34 | var bravestWarriors = ['Catbug', 'Danny', 'Chris', 'Beth', 'Wallow', 'Impossibear'];
35 |
36 | // Problem 6:
37 | // Use push() and unshift to make the array fruit look like this:
38 | // ['banana', 'kiwi', 'apple', 'orange', 'grapes', 'mango']
39 | var fruit = ['kiwi', 'apple', 'orange', 'grapes'];
40 |
41 | // ****
42 | // Objects (Associative Arrays)
43 | // ****
44 |
45 | // Problem 7:
46 | // Create an empty object
47 | var emptyObject;
48 |
49 | // Problem 8:
50 | // Create an object with the following key, value pairs:
51 | // 1) emptyObject: {}
52 | // 2) emptyArray: []
53 | // 3) name: 'bob'
54 | // 4) number: 42
55 | var problemEightObject;
56 |
57 | // Problem 9:
58 | // DON'T EDIT problemNineObject!!!!
59 | var problemNineObject = {
60 | 'fav food': 'pizza',
61 | city: 'houston'
62 | };
63 | // update 'fav food' so that its value is tacos
64 | // update city so that its value is austin
65 |
66 | // Problem 10:
67 | // DON'T EDIT nestedObjects!!!!
68 | var nestedObjects = {
69 | someNumbers: [1, 2, 3.14159, 4, 5, 6],
70 | users: {
71 | 'fred astaire': {
72 | hometown: 'Omaha'
73 | },
74 | 'bob roberts': {
75 | starring: 'John Cusack'
76 | }
77 | }
78 | };
79 | // update the starring property to have the value 'Tim Robbins'
80 |
81 |
82 | // ****
83 | // Concept Checkpoint
84 | //
85 | // Write your answer in comments
86 | //
87 | // What is an associative array? What is the difference between an array and an associative array?
88 | //
89 | // Your Answer Goes Here:
90 | //
91 | //
92 |
93 | // ****
94 | // Tests
95 | // DO NOT MODIFY CODE BELOW!!!!!
96 | // ****
97 |
98 | describe('Lesson 4 Homework', function () {
99 |
100 | describe('Popular Array Methods', function () {
101 |
102 | var newNumberArray;
103 | beforeEach(function () {
104 | newNumberArray = numberArray.map(function (number) { return number; });
105 | });
106 |
107 | describe('Problem 1: numberArray after pop()', function () {
108 | it('should be missing the last element', function () {
109 | newNumberArray.pop();
110 | assert.deepStrictEqual(numberArrayAfterPop, newNumberArray);
111 | });
112 | });
113 |
114 | describe('Problem 2: numberArray after shift()', function () {
115 | it('should be missing the first element', function () {
116 | newNumberArray.shift();
117 | assert.deepStrictEqual(numberArrayAfterShift, newNumberArray);
118 | });
119 | });
120 |
121 | describe('Problem 3: numberArray after push(6)', function () {
122 | it('should be the same array with 6 added at the end', function () {
123 | newNumberArray.push(6);
124 | assert.deepStrictEqual(numberArrayAfterPush, newNumberArray);
125 | });
126 | });
127 |
128 | describe('Problem 4: numberArray after unshift(0)', function () {
129 | it('should be the same array with zero added at the beggining', function () {
130 | newNumberArray.unshift(0);
131 | assert.deepStrictEqual(numberArrayAfterUnshift, newNumberArray);
132 | });
133 | });
134 |
135 | describe('Problem 5: bravestWarriors pop() and shift()', function () {
136 | it('should be missing Impossibear and Catbug', function () {
137 | assert.deepStrictEqual(bravestWarriors, ['Danny', 'Chris', 'Beth', 'Wallow']);
138 | });
139 | });
140 |
141 | describe('Problem 6: fruit push() and unshift()', function () {
142 | it('should have added mango and banana', function () {
143 | assert.deepStrictEqual(fruit, ['banana', 'kiwi', 'apple', 'orange', 'grapes', 'mango']);
144 | });
145 | });
146 | });
147 |
148 |
149 | describe('Objects (Associative Arrays)', function () {
150 |
151 | describe('Problem 7: create empty object', function () {
152 | it('should be an empty object', function () {
153 | assert.deepStrictEqual(emptyObject, {});
154 | });
155 | });
156 |
157 | describe('Problem 8: create an object with keys and values', function () {
158 | it('should be an object with the right keys and values', function () {
159 | assert.deepStrictEqual(problemEightObject, {
160 | emptyObject: {},
161 | emptyArray: [],
162 | name: 'bob',
163 | number: 42
164 | });
165 | });
166 | });
167 |
168 | describe('Problem 9: update an object', function () {
169 | it('should have fav food as tacos, city as austin', function () {
170 | assert.deepStrictEqual(problemNineObject, {
171 | 'fav food': 'tacos',
172 | city: 'austin'
173 | });
174 | });
175 | });
176 |
177 | describe('Problem 10: update properties in a nested object', function () {
178 | it('should should have the key starring with value Tim Robbins', function () {
179 | assert.deepStrictEqual(nestedObjects, {
180 | someNumbers: [1, 2, 3.14159, 4, 5, 6],
181 | users: {
182 | 'fred astaire': {
183 | hometown: 'Omaha'
184 | },
185 | 'bob roberts': {
186 | starring: 'Tim Robbins'
187 | }
188 | }
189 | });
190 | });
191 | });
192 | });
193 |
194 | });
195 |
--------------------------------------------------------------------------------
/extra-challenges/05challenge.js:
--------------------------------------------------------------------------------
1 | 'use strict';
2 |
3 | var assert = require('assert');
4 |
5 | // ****
6 | // More Operators
7 | // ****
8 |
9 | // DO NOT MODIFY
10 | var one = 1;
11 | var two = 2;
12 | var three = 3;
13 | var four = 4;
14 | var five = 5;
15 | var six = 6;
16 |
17 | // Problem 1:
18 | // What is the result of applying the increment (++) operator to var one?
19 | var onePlusPlus;
20 |
21 | // Problem 2:
22 | // What is the result of applying the decrement (--) operator to var two?
23 | var twoMinusMinus;
24 |
25 | // Problem 3:
26 | // What is the result of three += 3?
27 | var threePlusAssignmentThree;
28 |
29 | // Problem 4:
30 | // What is the result of four -= 3?
31 | var fourMinusAssignmentThree;
32 |
33 | // Problem 5:
34 | // What is the result of five *= 2?
35 | var fiveMultiplicationAssignmentTwo;
36 |
37 | // Problem 6:
38 | // What is the result of six /= 3?
39 | var sixDivisionAssignmentThree;
40 |
41 | // ****
42 | // Loops
43 | // ****
44 |
45 | // DO NOT MODIFY
46 | var whileLoopArray = [];
47 | var whileLoopCounter = 0;
48 | while (whileLoopCounter < 10) {
49 | whileLoopArray.push(whileLoopCounter);
50 | whileLoopCounter++;
51 | }
52 |
53 | // Problem 7:
54 | // Fill in whileLoopArrayResult so that it matches whileLoopArray
55 | var whileLoopArrayResult = [];
56 |
57 | // DO NOT MODIFY
58 | var forLoopArray = [];
59 | var forLoopCounter;
60 | for (forLoopCounter = 0; forLoopCounter > -10; forLoopCounter--) {
61 | forLoopArray.push(forLoopCounter);
62 | }
63 |
64 | // Problem 8:
65 | // Fill in forLoopArrayResult so that it matches forLoopArray
66 | var forLoopArrayResult = [];
67 |
68 | // ****
69 | // Concept Checkpoint
70 | //
71 | // Write your answer in comments
72 | //
73 | // What are loops? Why do we use them?
74 | //
75 |
76 | // ****
77 | // Tests
78 | // DO NOT MODIFY CODE BELOW!!!!!
79 | // ****
80 |
81 | describe('Lesson 5 Homework', function () {
82 |
83 | describe('More Operators', function () {
84 |
85 | describe('Problem 1: increment operator, one plus plus', function () {
86 | it('should add one to the original number', function () {
87 | assert.equal(onePlusPlus, 2);
88 | });
89 | });
90 |
91 | describe('Problem 2: decrement operator, two minus minus', function () {
92 | it('should subtract one from the original number', function () {
93 | assert.equal(twoMinusMinus, 1);
94 | });
95 | });
96 |
97 | describe('Problem 3: plus assigment operator', function () {
98 | it('should add 3 to the original number', function () {
99 | assert.equal(threePlusAssignmentThree, 6);
100 | });
101 | });
102 |
103 | describe('Problem 4: minus assigment operator', function () {
104 | it('should subtract 3 from the original number', function () {
105 | assert.equal(fourMinusAssignmentThree, 1);
106 | });
107 | });
108 |
109 | describe('Problem 5: multiplication assigment operator', function () {
110 | it('should multiply the original number by two', function () {
111 | assert.equal(fiveMultiplicationAssignmentTwo, 10);
112 | });
113 | });
114 |
115 | describe('Problem 6: division assigment operator', function () {
116 | it('should divide the original number by three', function () {
117 | assert.equal(sixDivisionAssignmentThree, 2);
118 | });
119 | });
120 | });
121 |
122 | describe('Loops', function () {
123 |
124 | describe('Problem 7: while loop array push result', function () {
125 | it('should match the result of the while loop', function () {
126 | assert.deepStrictEqual(whileLoopArray, whileLoopArrayResult);
127 | });
128 | });
129 |
130 | describe('Problem 8: for loop array push result', function () {
131 | it('should match the result of the for loop', function () {
132 | assert.deepStrictEqual(forLoopArray, forLoopArrayResult);
133 | });
134 | });
135 |
136 | });
137 |
138 | });
139 |
--------------------------------------------------------------------------------
/extra-challenges/06challenge.js:
--------------------------------------------------------------------------------
1 | 'use strict';
2 |
3 | var assert = require('assert');
4 |
5 | // ****
6 | // Are you down with OOP?
7 | // ****
8 |
9 |
10 | // Problem 1:
11 | // Associative Array Refresh
12 | // Add properties x: 1, y: 2 to point to make it a point
13 | // in two dimensional space.
14 | var point = {
15 | };
16 |
17 | // Problem 2:
18 | // Fill in this Point constructor function so that it defines
19 | // a class of points with properties x and y.
20 | // In order to do this, you should add parameters x and y
21 | // as properties to "this".
22 | // example: this.propName = propValue;
23 | function Point(x, y) {
24 | }
25 |
26 | // Problem 3:
27 | // Create a new point using the class constructor Point.
28 | // Set x to 5, and y to -3
29 | // This can be done as follows: new Point(someX, someY)
30 | var anotherPoint;
31 |
32 | // ****
33 | // Concept Checkpoint
34 | //
35 | // Write your answer in comments
36 | //
37 | // What is the difference between point (an object literal, or associative array)
38 | // and anotherPoint (a point object constructed from the Point class)?
39 | //
40 | //
41 |
42 | // ****
43 | // Methods
44 | // ****
45 |
46 | // DO NOT MODIFY THIS CLASS!!
47 | // ConferenceRoom() is a class that models a conference room.
48 | // It has some data, this.people, which contains the people in the room.
49 | //
50 | // ConferenceRoom() also has three methods:
51 | // this.enter(): which adds people to the room
52 | // this.clearRoom(): which clears the room
53 | // this.sayHi(): which calls person.sayHi() for every person in this.people
54 | //
55 | // Note how methods in one class can call methods in another class
56 | function ConferenceRoom() {
57 | this.people = [];
58 |
59 | this.enter = function(person) {
60 | this.people.push(person);
61 | };
62 |
63 | this.clearRoom = function() {
64 | this.people = [];
65 | };
66 |
67 | this.sayHi = function() {
68 | for(var index = 0; index < this.people.length; index++) {
69 | console.log(this.people[index].sayHi());
70 | }
71 | };
72 | }
73 |
74 | // Problem 4:
75 | // finish the definition of class Person()
76 | // Add a method called sayHi() that returns "Hi, I'm " + this.name + '!';
77 | function Person(name) {
78 | this.name = name;
79 | }
80 |
81 | // Problem 5:
82 | // create a new Person named Jen
83 | var jen;
84 |
85 | // Problem 6:
86 | // add jen to the conferenceRoom
87 | var conferenceRoom = new ConferenceRoom();
88 | // you can do this by calling the method enter() as follows:
89 | // conferenceRoom.enter(somePerson);
90 | // add your code for Problem 6 here
91 |
92 |
93 | // ****
94 | // Concept Checkpoint
95 | //
96 | // Write your answer in comments
97 | //
98 | // What is a method?
99 | //
100 | //
101 |
102 | // ****
103 | // Tests
104 | // DO NOT MODIFY CODE BELOW!!!!!
105 | // ****
106 |
107 | describe('Lesson 6 Homework', function () {
108 |
109 | describe('Are you down with OOP?', function () {
110 |
111 | describe('Problem 1: Associative Array Refresh', function () {
112 | it('should be { x: 1, y: 2 }', function () {
113 | assert.deepStrictEqual(point, { x: 1, y: 2 });
114 | });
115 | });
116 |
117 | describe('Problem 2: Finish Point class', function () {
118 | it('should generate points with properties x and y', function () {
119 | var myPoint = new Point(4, 4);
120 | assert.equal(myPoint.x, 4);
121 | assert.equal(myPoint.y, 4);
122 | });
123 | });
124 |
125 | describe('Problem 3: another good point', function () {
126 | it('should be anotherPoint.x === 5, anotherPoint.y === -3', function () {
127 | assert.equal(anotherPoint.x, 5);
128 | assert.equal(anotherPoint.y, -3);
129 | });
130 | });
131 |
132 | });
133 |
134 | describe('Methods', function () {
135 |
136 | describe('Problem 4: Finish Person class', function () {
137 | it('should have method sayHi()', function () {
138 | var instructor = new Person('Teach');
139 | assert(typeof instructor.sayHi === 'function');
140 | assert(typeof instructor.sayHi() === 'string');
141 | });
142 | });
143 |
144 | describe('Problem 5: new Person Jen', function () {
145 | it('should be a new Person Jen', function () {
146 | assert.equal(jen.name.toLowerCase(), 'jen');
147 | });
148 | });
149 |
150 | describe('Problem 6: Conference of One', function () {
151 | it('should be the case that conferenceRoom contains jen', function () {
152 | assert.equal(conferenceRoom.people.length, 1);
153 | assert.deepStrictEqual(jen, conferenceRoom.people[0]);
154 | conferenceRoom.sayHi();
155 | });
156 | });
157 |
158 | });
159 |
160 |
161 | });
162 |
--------------------------------------------------------------------------------
/extra-challenges/07challenge.js:
--------------------------------------------------------------------------------
1 | 'use strict';
2 |
3 | var assert = require('assert');
4 |
5 | // You goal is to return a string that says "Hello!"
6 |
7 | function sayHello() {
8 | // Your code here
9 |
10 | }
11 |
12 |
13 | // Tests
14 |
15 | describe('#sayHello()', function () {
16 | it('says hello', function () {
17 | assert.equal(sayHello(), "Hello!");
18 | });
19 | });
20 |
--------------------------------------------------------------------------------
/extra-challenges/08challenge.js:
--------------------------------------------------------------------------------
1 | 'use strict';
2 |
3 | var assert = require('assert');
4 |
5 | // Your task is to sort a given string. Each word in the String will contain a single number. This number is the position the word should have in the result.
6 | // Note: Numbers can be from 1 to 9. So 1 will be the first word (not 0).
7 | // If the input String is empty, return an empty String. The words in the input String will only contain valid consecutive numbers.
8 | // For an input: "is2 Thi1s T4est 3a" the function should return "Thi1s is2 3a T4est"
9 |
10 | function order(words) {
11 | // Your code here
12 | }
13 |
14 |
15 | // Tests
16 |
17 | describe('#order()', function () {
18 | it('Sort a given string. Each word in the String will contain a single number. This number is the position the word should have in the result', function () {
19 | assert.equal(order("is2 Thi1s T4est 3a"), "Thi1s is2 3a T4est");
20 | assert.equal(order("4of Fo1r pe6ople g3ood th5e the2"), "Fo1r the2 g3ood 4of th5e pe6ople");
21 | });
22 | it('If the input String is empty, return an empty String. The words in the input String will only contain valid consecutive numbers.', function () {
23 | assert.equal(order(""), "");
24 | });
25 | });
26 |
--------------------------------------------------------------------------------
/extra-challenges/09challenge.js:
--------------------------------------------------------------------------------
1 | 'use strict';
2 |
3 | var assert = require('assert');
4 |
5 | // Given an array A, find the int that appears an odd number of times.
6 | // There will always be only one integer that appears an odd number of times.
7 |
8 | function findOdd(arr) {
9 | // Your code here
10 | }
11 |
12 |
13 | // Tests
14 |
15 | describe('#findOdd()', function () {
16 | it('should find the int that appears an odd number of times', function () {
17 | assert.equal(findOdd([20,1,-1,2,-2,3,3,5,5,1,2,4,20,4,-1,-2,5]), 5);
18 | assert.equal(findOdd([1,1,2,-2,5,2,4,4,-1,-2,5]), -1);
19 | assert.equal(findOdd([20,1,1,2,2,3,3,5,5,4,20,4,5]), 5);
20 | assert.equal(findOdd([10]), 10);
21 | assert.equal(findOdd([1,1,1,1,1,1,10,1,1,1,1]), 10);
22 | assert.equal(findOdd([5,4,3,2,1,5,4,3,2,10,10]), 1);
23 | });
24 | });
25 |
--------------------------------------------------------------------------------
/extra-challenges/10challenge.js:
--------------------------------------------------------------------------------
1 | 'use strict';
2 |
3 | var assert = require('assert');
4 |
5 | function returnTrue() {
6 | // should return true
7 | return false;
8 | }
9 |
10 |
11 | // Tests
12 |
13 | describe('#returnTrue()', function () {
14 | it('should return true', function () {
15 | assert.equal(returnTrue(), true);
16 | });
17 | });
18 |
--------------------------------------------------------------------------------
/extra-challenges/11challenge.js:
--------------------------------------------------------------------------------
1 | 'use strict';
2 |
3 | var assert = require('assert');
4 |
5 |
6 | function returnTrue() {
7 | // should return true
8 |
9 | }
10 |
11 | function returnFalse() {
12 | // should return false
13 |
14 | }
15 |
16 | function greaterThan(big, small) {
17 | // should return true if the first argument is greater than the second argument
18 | // and return false if the first argument is less than the second argument
19 |
20 | }
21 |
22 | function lessThan(small, big) {
23 | // should return true if the first argument is less than the second argument
24 | // and return false if the first argument is greater than the second argument
25 |
26 | }
27 |
28 | function equalTo(a, b) {
29 | // should return true if the first argument is equal to the second argument
30 | // and should return true if the first argument is equal to the second argument
31 |
32 | }
33 |
34 | function notEqualTo(a, b) {
35 | // should return true if the first argument is not equal to the second argument
36 | // and should return false if the first argument is equal to the second argument
37 |
38 | }
39 |
40 |
41 | // Tests
42 |
43 | describe('#returnTrue()', function () {
44 | it('should return true', function () {
45 | assert.equal(returnTrue(), true);
46 | });
47 | });
48 |
49 | describe('#returnFalse()', function () {
50 | it('should return false', function () {
51 | assert.equal(returnFalse(), false);
52 | });
53 | });
54 |
55 | describe('#greaterThan()', function () {
56 | it('should return true if the first argument is greater than the second argument', function () {
57 | assert.equal(greaterThan(10, 4), true);
58 | });
59 | it('should return false if the first argument is less than the second argument', function () {
60 | assert.equal(greaterThan(4, 10), false);
61 | });
62 | });
63 |
64 | describe('#lessThan()', function () {
65 | it('should return true if the first argument is less than the second argument', function () {
66 | assert.equal(lessThan(3, 5), true);
67 | });
68 | it('should return false if the first argument is greater than the second argument', function () {
69 | assert.equal(lessThan(6, 3), false);
70 | });
71 | });
72 |
73 | describe('#equalTo()', function () {
74 | it('should return true if the first argument is equal to the second argument', function () {
75 | assert.equal(equalTo(6, 6), true);
76 | });
77 | it('should return false if the first argument is not equal to the second argument', function () {
78 | assert.equal(equalTo(6, 7), false);
79 | });
80 | it('should return false if not using ===', function () {
81 | assert.equal(equalTo(6, '6'), false);
82 | });
83 | });
84 |
85 | describe('#notEqualTo()', function () {
86 | it('should return false if the first argument is equal to the second argument', function () {
87 | assert.equal(notEqualTo(6, 6), false);
88 | });
89 | it('should return true if the first argument is not equal to the second argument', function () {
90 | assert.equal(notEqualTo(6, 7), true);
91 | });
92 | it('should return true if not using ===', function () {
93 | assert.equal(notEqualTo(6, '6'), true);
94 | });
95 | });
96 |
--------------------------------------------------------------------------------
/extra-challenges/12challenge.js:
--------------------------------------------------------------------------------
1 | 'use strict';
2 |
3 | var assert = require('assert');
4 |
5 | function whichSpecies(character) {
6 | // should return "dog" when character is 'scooby'
7 | // should return "cat" when character is 'garfield'
8 | // should return "fish" when character is 'nemo'
9 | // should return false if character is anything else
10 |
11 | }
12 |
13 | function isEven(number) {
14 | // should return true is number is even (divisible by 2)
15 |
16 | }
17 |
18 |
19 | // Tests
20 |
21 | describe('#whichSpecies()', function () {
22 | it('should return "dog" when character is scooby', function () {
23 | assert.equal(whichSpecies('scooby'), 'dog');
24 | });
25 | it('should return "cat" when character is garfield', function () {
26 | assert.equal(whichSpecies('garfield'), 'cat');
27 | });
28 | it('should return "fish" when character is nemo', function () {
29 | assert.equal(whichSpecies('nemo'), 'fish');
30 | });
31 | it('should return false if character is anything else', function () {
32 | assert.equal(whichSpecies('stitch'), false);
33 | });
34 | });
35 |
36 | describe('#isEven()', function () {
37 | it('should return true is number is even (divisible by 2)', function () {
38 | assert.equal(isEven(4), true);
39 | });
40 | it('should return false when number is not even', function () {
41 | assert.equal(isEven(5), false);
42 | });
43 | });
44 |
--------------------------------------------------------------------------------
/extra-challenges/13challenge.js:
--------------------------------------------------------------------------------
1 | 'use strict';
2 |
3 | var assert = require('assert');
4 |
5 |
6 | function buildArray(first, second, third) {
7 | // return array with the items first, second, and third in an array.
8 |
9 | }
10 |
11 | function returnThirdItem(arr) {
12 | // should return the third item in the array
13 |
14 | }
15 |
16 | function setFirstItem(arr, newFirstItem) {
17 | // should set the first item in the array with newFirstItem
18 |
19 | }
20 |
21 | function returnCenterItem(fiveByFiveArray) {
22 | // returns the "center" item in a 5 x 5 array
23 | // ex. 3 x 3 array [[1, 2, 3], [4, 5, 6], [7, 8, 9]] the center item is 5
24 |
25 | }
26 |
27 | function arrayJoin(arr) {
28 | // should return a string of the joined array items, separated by a space
29 |
30 | }
31 |
32 | function stringSplit(str) {
33 | // should return an array of the words in a string, delimited by a space
34 |
35 | }
36 |
37 |
38 | // Tests
39 |
40 | describe('#buildArray()', function () {
41 | it('return array with the items first, second, and third in an array.', function () {
42 | assert.deepEqual(buildArray('a', 'b', 'c'), ['a', 'b', 'c']);
43 | assert.deepEqual(buildArray('d', 'e', 'f'), ['d', 'e', 'f']);
44 | });
45 | });
46 |
47 | describe('#returnThirdItem()', function () {
48 | it('should return the third item in the array', function () {
49 | assert.deepEqual(returnThirdItem(['a', 'b', 'c']), 'c');
50 | assert.deepEqual(returnThirdItem(['d', 'e', 'f']), 'f');
51 | });
52 | });
53 |
54 | describe('#setFirstItem()', function () {
55 | it('should set the first item in the array with newFirstItem', function () {
56 | assert.deepEqual(setFirstItem(['a', 'b', 'c'], 'g'), ['g', 'b', 'c']);
57 | assert.deepEqual(setFirstItem(['d', 'e', 'f'], 'h'), ['h', 'e', 'f']);
58 | });
59 | });
60 |
61 | describe('#returnCenterItem()', function () {
62 | it('returns the "center" item in a 5 x 5 array', function () {
63 | var arr = [
64 | [1, 2, 1, 4, 5],
65 | [1, 2, 2, 4, 5],
66 | [1, 2, 3, 4, 5],
67 | [1, 2, 4, 4, 5],
68 | [1, 2, 5, 4, 5]
69 | ];
70 | assert.equal(returnCenterItem(arr), 3);
71 | });
72 | });
73 |
74 | describe('#arrayJoin()', function () {
75 | it('should return a string of the joined array items, separated by a space', function () {
76 | assert.equal(arrayJoin(['a', 'b', 'c']), 'a b c');
77 | assert.equal(arrayJoin(['e', 'f', 'g']), 'e f g');
78 | });
79 | });
80 |
81 | describe('#stringSplit()', function () {
82 | it('should return an array of the words in a string, delimited by a space', function () {
83 | assert.deepEqual(stringSplit('a b c'), ['a', 'b', 'c']);
84 | assert.deepEqual(stringSplit('e f g'), ['e', 'f', 'g']);
85 | });
86 | });
87 |
--------------------------------------------------------------------------------
/extra-challenges/14challenge.js:
--------------------------------------------------------------------------------
1 | 'use strict';
2 |
3 | var assert = require('assert');
4 |
5 | function arrayPop(arr) {
6 | // should remove the last item in the array, then return the arr
7 |
8 | }
9 |
10 | function arrayPush(arr, item1, item2, item3) {
11 | // should add these items onto the end of the array, then return the array
12 |
13 | }
14 |
15 | function arrayShift(arr) {
16 | // should remove the first item in the array, then return the array
17 |
18 | }
19 |
20 | function arrayUnshift(arr, item1, item2, item3) {
21 | // should add these items onto the front of the array, then return the array
22 |
23 | }
24 |
25 | function createObject() {
26 | // should return an object with keys 'first', 'second', 'third' mapped to
27 | // values 1, 2, 3
28 |
29 | }
30 |
31 | function returnValueByKey(object, key) {
32 | // given an object and a key, return the value assigned to the key
33 |
34 | }
35 |
36 | function assignKeyValue(object, key, value) {
37 | // given an object, key, and value, add the key/value pair
38 | // to the object. return the object
39 | }
40 |
41 |
42 | // Tests
43 |
44 | describe('#arrayPop', function () {
45 | it('should remove the last item in the array, then return the array', function () {
46 | assert.deepEqual(arrayPop(['a', 'b', 'c']), ['a', 'b']);
47 | assert.deepEqual(arrayPop(['d', 'e', 'f']), ['d', 'e']);
48 | });
49 | });
50 |
51 | describe('#arrayPush', function () {
52 | it('should add these items onto the end of the array, then return the array', function () {
53 | assert.deepEqual(arrayPush(['a'], 'b', 'c', 'd'), ['a', 'b', 'c', 'd']);
54 | assert.deepEqual(arrayPush(['d'], 'e', 'f', 'g'), ['d', 'e', 'f', 'g']);
55 | });
56 | });
57 |
58 | describe('#arrayShift', function () {
59 | it('should remove the first item in the array, then return the array', function () {
60 | assert.deepEqual(arrayShift(['a', 'b', 'c']), ['b', 'c']);
61 | assert.deepEqual(arrayShift(['d', 'e', 'f']), ['e', 'f']);
62 | });
63 | });
64 |
65 | describe('#arrayUnshift', function () {
66 | it('should add these items onto the front of the array, then return the array', function () {
67 | assert.deepEqual(arrayUnshift(['a'], 'b', 'c', 'd'), ['b', 'c', 'd', 'a']);
68 | assert.deepEqual(arrayUnshift(['d'], 'e', 'f', 'g'), ['e', 'f', 'g', 'd']);
69 | });
70 | });
71 |
72 | describe('#createObject', function () {
73 | it('should return an object with keys "first", "second", "third" mapped to values 1, 2, 3', function () {
74 | assert.deepEqual(createObject(), { first: 1, second: 2, third: 3 });
75 | });
76 | });
77 |
78 | describe('#returnValueByKey', function () {
79 | it('given an object and a key, should return the value assigned to the key', function () {
80 | assert.equal(returnValueByKey({ 'a': 1, 'b': 2, 'c': 3}, 'a'), 1);
81 | assert.equal(returnValueByKey({ 'a': 1, 'b': 2, 'c': 3}, 'b'), 2);
82 | assert.equal(returnValueByKey({ 'a': 1, 'b': 2, 'c': 3}, 'c'), 3);
83 | });
84 | });
85 |
86 | describe('#assignKeyValue', function () {
87 | it('given an object, key, and value, add the key/value pair to the object. return the object', function () {
88 | assert.deepEqual(assignKeyValue({}, 'a', 1), { a: 1 });
89 | assert.deepEqual(assignKeyValue({}, 'b', 2), { b: 2 });
90 | });
91 | });
92 |
--------------------------------------------------------------------------------
/extra-challenges/15challenge.js:
--------------------------------------------------------------------------------
1 | 'use strict';
2 |
3 | var assert = require('assert');
4 |
5 | function loopIt() {
6 | // should return an array with numbers 0 - 99
7 |
8 | }
9 |
10 | function onlyEvens() {
11 | // should return an array with all even numbers between 1 - 99
12 |
13 | }
14 |
15 | function fizzBuzz() {
16 | // should return an array of numbers between 0 - 99 where the numbers
17 | // divisible by 3 are replaced by the string "fizz", numbers divisible by 5
18 | // are replaced by the string "buzz", and the numbers divisble by both 3 and
19 | // 5 are replaced by fizzbuzz
20 |
21 | }
22 |
23 |
24 | // Tests
25 |
26 | describe('#loopIt', function () {
27 | it('should return an array with numbers 0 - 99', function () {
28 | var array = [ 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31, 32, 33, 34, 35, 36, 37, 38, 39, 40, 41, 42, 43, 44, 45, 46, 47, 48, 49, 50, 51, 52, 53, 54, 55, 56, 57, 58, 59, 60, 61, 62, 63, 64, 65, 66, 67, 68, 69, 70, 71, 72, 73, 74, 75, 76, 77, 78, 79, 80, 81, 82, 83, 84, 85, 86, 87, 88, 89, 90, 91, 92, 93, 94, 95, 96, 97, 98, 99 ];
29 | assert.deepEqual(loopIt(), array);
30 | });
31 | });
32 |
33 | describe('#onlyEvens', function () {
34 | it('should return an array with all even numbers between 1 - 99', function () {
35 | var array = [ 2, 4, 6, 8, 10, 12, 14, 16, 18, 20, 22, 24, 26, 28, 30, 32, 34, 36, 38, 40, 42, 44, 46, 48, 50, 52, 54, 56, 58, 60, 62, 64, 66, 68, 70, 72, 74, 76, 78, 80, 82, 84, 86, 88, 90, 92, 94, 96, 98 ];
36 | assert.deepEqual(onlyEvens(), array);
37 | });
38 | });
39 |
40 | describe('#fizzBuzz', function () {
41 | it('should return an array of numbers between 0 - 99 where the numbers divisible by 3 are replaced by the string "fizz", numbers divisible by 5 are replaced by the string "buzz", and the numbers divisble by both 3 and 5 are replaced by fizzbuzz', function () {
42 | var array = [ 'fizzbuzz', 1, 2, 'fizz', 4, 'buzz', 'fizz', 7, 8, 'fizz', 'buzz', 11, 'fizz', 13, 14, 'fizzbuzz', 16, 17, 'fizz', 19, 'buzz', 'fizz', 22, 23, 'fizz', 'buzz', 26, 'fizz', 28, 29, 'fizzbuzz', 31, 32, 'fizz', 34, 'buzz', 'fizz', 37, 38, 'fizz', 'buzz', 41, 'fizz', 43, 44, 'fizzbuzz', 46, 47, 'fizz', 49, 'buzz', 'fizz', 52, 53, 'fizz', 'buzz', 56, 'fizz', 58, 59, 'fizzbuzz', 61, 62, 'fizz', 64, 'buzz', 'fizz', 67, 68, 'fizz', 'buzz', 71, 'fizz', 73, 74, 'fizzbuzz', 76, 77, 'fizz', 79, 'buzz', 'fizz', 82, 83, 'fizz', 'buzz', 86, 'fizz', 88, 89, 'fizzbuzz', 91, 92, 'fizz', 94, 'buzz', 'fizz', 97, 98, 'fizz'];
43 | assert.deepEqual(fizzBuzz(), array);
44 | });
45 | });
46 |
--------------------------------------------------------------------------------
/extra-challenges/16challenge.js:
--------------------------------------------------------------------------------
1 | 'use strict';
2 |
3 | var assert = require('assert');
4 |
5 | // Create two classes, Car and Garage
6 | // The Car class should take one parameter, color. Set the passed in color to be an attribute of the object
7 | // The Garage should also take one parameter, size. The size will be an integer, and set it to an attribute
8 | // Give the Garage object an attribute, this.cars, and set it to an empty array
9 | // The Garage class should have two methods, .add and .remove
10 | // .add should take one argument, car. If the length of this.cars is less than this.size, push the car into this.cars, else return "Not enough space!"
11 | // .remove should also take one argument, car. look for the index of the car in this.cars. If it is found, splice it out of this.cars. If it isn't found, return "That car isn't here!"
12 |
13 | // Your code here
14 |
15 | // Tests
16 |
17 | var redCar, blueCar, greenCar, yellowCar, twoCarGarage, threeCarGarage;
18 |
19 | it('should be able to instatiate car objects', function () {
20 | redCar = new Car('red');
21 | assert.equal(redCar.color, 'red');
22 |
23 | blueCar = new Car('blue');
24 | assert.equal(blueCar.color, 'blue');
25 |
26 | greenCar = new Car('green');
27 | assert.equal(greenCar.color, 'green');
28 |
29 | yellowCar = new Car('yellow');
30 | assert.equal(yellowCar.color, 'yellow');
31 | });
32 |
33 | it('should be able to instatiate garage objects', function () {
34 | twoCarGarage = new Garage(2);
35 | assert.equal(twoCarGarage.size, 2);
36 |
37 | threeCarGarage = new Garage(3);
38 | assert.equal(threeCarGarage.size, 3);
39 | });
40 |
41 | it('should be able to add cars to a garage', function () {
42 | twoCarGarage.add(redCar);
43 | twoCarGarage.add(blueCar);
44 | assert.equal(twoCarGarage.cars.length, 2);
45 |
46 | threeCarGarage.add(greenCar);
47 | threeCarGarage.add(yellowCar);
48 | assert.equal(threeCarGarage.cars.length, 2);
49 | });
50 |
51 | it('should be able to remove cars from a garage', function () {
52 | twoCarGarage.remove(redCar);
53 | assert.equal(twoCarGarage.cars.length, 1);
54 |
55 | threeCarGarage.add(redCar);
56 | assert.equal(threeCarGarage.cars.length, 3);
57 | });
58 |
59 | it('should be able to detect of a garage is full', function () {
60 | twoCarGarage.remove(blueCar);
61 | assert.equal(twoCarGarage.cars.length, 0);
62 |
63 | threeCarGarage.add(blueCar);
64 | assert.equal(threeCarGarage.add(blueCar), 'Not enough space!');
65 | });
66 |
67 | it('should be able to detect if a car is not in a garage', function () {
68 | assert.equal(twoCarGarage.remove(blueCar), "That car isn't here!");
69 | });
70 |
--------------------------------------------------------------------------------
/index.html:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 | Hello World!
9 |
10 |
11 |
--------------------------------------------------------------------------------
/package.json:
--------------------------------------------------------------------------------
1 | {
2 | "name": "javascript-workbook",
3 | "version": "1.0.0",
4 | "description": "Austin Coding Academy - JavaScript Workbook",
5 | "repository": {
6 | "type": "git",
7 | "url": "git+https://github.com/AustinCodingAcademy/javascript-workbook.git"
8 | },
9 | "scripts": {
10 | "lint": "htmllint {*.html,./**/*.html} && stylelint ./**/*.css && eslint .",
11 | "test": "mocha --no-timeouts",
12 | "start": "cd . && http-server -c-1",
13 | "javascripting": "javascripting",
14 | "functional-javascript": "functional-javascript"
15 | },
16 | "author": "Kevin Colten",
17 | "bugs": {
18 | "url": "https://github.com/AustinCodingAcademy/javascript-workbook/issues"
19 | },
20 | "homepage": "https://github.com/AustinCodingAcademy/javascript-workbook#readme",
21 | "dependencies": {
22 | "eslint": "^3.19.0",
23 | "functional-javascript-workshop": "^1.0.6",
24 | "htmllint-cli": "github:kevincolten/htmllint-cli",
25 | "http-server": "^0.11.1",
26 | "javascripting": "^2.6.1",
27 | "jsdom": "^11.6.2",
28 | "mocha": "^5.0.0",
29 | "postcss-html": "^0.34.0",
30 | "stylelint": "^7.13.0"
31 | }
32 | }
33 |
--------------------------------------------------------------------------------