├── .gitignore
├── activities
├── activity6
│ ├── activity
│ │ ├── note.txt
│ │ ├── .gitignore
│ │ ├── index.html
│ │ ├── package.json
│ │ ├── src
│ │ │ └── index.js
│ │ ├── index.js
│ │ └── lib
│ │ │ └── index.js
│ └── solution
│ │ ├── note.txt
│ │ ├── .gitignore
│ │ ├── index.html
│ │ ├── package.json
│ │ ├── index.js
│ │ ├── src
│ │ └── index.js
│ │ └── lib
│ │ └── index.js
├── activity3
│ ├── package.json
│ ├── package-lock.json
│ └── activity.html
├── activity4
│ ├── index.js
│ ├── package.json
│ └── test.js
├── activity2
│ ├── simple_db.js
│ └── index.js
├── activity5
│ ├── activity-test.js
│ └── activity-solution.js
└── activity1
│ └── index.js
├── exercises
├── exercise35
│ ├── note.txt
│ ├── basic-express-server.js
│ ├── basic-http-server.js
│ ├── package.json
│ ├── index.js
│ ├── index.html
│ └── package-lock.json
├── exercise14
│ ├── .babelrc
│ ├── package.json
│ ├── app.js
│ └── app.transpiled.js
├── exercise8
│ └── index.js
├── exercise10
│ └── index.js
├── exercise27
│ ├── test.js
│ └── package.json
├── exercise32
│ ├── index.js
│ └── module.js
├── exercise9
│ └── index.js
├── exercise3
│ └── index.js
├── exercise5
│ └── index.js
├── exercise20
│ └── index.html
├── exercise15
│ └── index.js
├── exercise18
│ └── index.js
├── exercise12
│ └── index.js
├── exercise25
│ ├── exercise.js
│ └── solution.js
├── exercise22
│ └── index.html
├── exercise7
│ └── index.js
├── exercise34
│ └── index.js
├── exercise30
│ └── index.js
├── exercise6
│ └── index.js
├── exercise31
│ ├── exercise.js
│ └── solution.js
├── exercise23
│ ├── exercise.html
│ └── solution.html
├── exercise33
│ └── index.js
├── exercise1
│ └── index.js
├── exercise17
│ └── index.js
├── exercise13
│ └── index.js
├── exercise19
│ └── index.js
├── exercise4
│ ├── solution.js
│ └── exercise.js
├── exercise11
│ └── index.js
├── exercise24
│ └── index.js
├── exercise28
│ └── index.js
├── exercise29
│ ├── exercise-test.js
│ └── exercise-solution.js
├── exercise26
│ ├── exercise.html
│ ├── spec sheet and tests.txt
│ └── solution.html
├── exercise2
│ └── index.js
├── exercise21
│ ├── exercise.html
│ └── solution.html
├── Exercise Numbering
└── exercise16
│ └── index.js
├── babel-basic-config
├── .babelrc
└── package.json
├── code-snippets
├── lesson6
│ ├── 6_3.js
│ ├── 6_10.js
│ ├── 6_13.js
│ ├── 6_17.js
│ ├── 6_4.js
│ ├── 6_14.js
│ ├── 6_33.html
│ ├── 6_18.js
│ ├── 6_19.js
│ ├── 6_21.js
│ ├── 6_16.js
│ ├── 6_6.js
│ ├── 6_22.js
│ ├── 6_28.js
│ ├── 6_12.js
│ ├── 6_7.js
│ ├── 6_11.js
│ ├── 6_2.js
│ ├── 6_8.js
│ ├── 6_9.js
│ ├── 6_23.js
│ ├── 6_5.js
│ ├── 6_29.js
│ ├── 6_25.js
│ ├── 6_1.json
│ ├── 6_30.js
│ ├── 6_31.js
│ ├── 6_15.js
│ ├── 6_24.js
│ ├── 6_26.html
│ ├── 6_27.js
│ ├── 6_35.js
│ ├── 6_20.js
│ ├── 6_32.js
│ ├── 6_36.js
│ └── 6_34.js
├── lesson1
│ ├── 1_46.js
│ ├── 1_11.js
│ ├── 1_51.html
│ ├── 1_2.js
│ ├── 1_4.js
│ ├── 1_15.js
│ ├── 1_52.html
│ ├── 1_7.js
│ ├── 1_8.js
│ ├── 1_31.js
│ ├── 1_34.js
│ ├── 1_16.js
│ ├── 1_18.js
│ ├── 1_49.js
│ ├── 1_25.js
│ ├── 1_43.js
│ ├── 1_10.js
│ ├── 1_27.js
│ ├── 1_30.js
│ ├── 1_36.js
│ ├── 1_38.js
│ ├── 1_37.js
│ ├── 1_24.js
│ ├── 1_22.js
│ ├── 1_5.js
│ ├── 1_39.js
│ ├── 1_44.js
│ ├── 1_6.js
│ ├── 1_40.js
│ ├── 1_1.js
│ ├── 1_20.js
│ ├── 1_21.js
│ ├── 1_23.js
│ ├── 1_33.js
│ ├── 1_35.js
│ ├── 1_55.js
│ ├── 1_53.js
│ ├── 1_42.js
│ ├── 1_41.js
│ ├── 1_9.js
│ ├── 1_17.js
│ ├── 1_12.js
│ ├── 1_28.js
│ ├── 1_29.js
│ ├── 1_54.js
│ ├── 1_13.js
│ ├── 1_45.js
│ ├── 1_3.js
│ ├── 1_26.js
│ ├── 1_56.js
│ ├── 1_32.js
│ ├── 1_47.js
│ ├── 1_50.js
│ ├── 1_14.js
│ ├── 1_48.js
│ └── 1_19.js
├── lesson4
│ ├── 4_2.json
│ ├── 4_1.js
│ ├── 4_4.js
│ └── 4_3.js
├── lesson3
│ ├── 3_5.html
│ ├── 3_7.html
│ ├── 3_1.html
│ ├── 3_19.html
│ ├── 3_12.html
│ ├── 3_8.html
│ ├── 3_3.html
│ ├── 3_4.html
│ ├── 3_10.html
│ ├── 3_16.html
│ ├── 3_18.html
│ ├── 3_2.html
│ ├── 3_14.html
│ ├── 3_13.html
│ ├── 3_6.html
│ ├── 3_17.html
│ ├── 3_15.html
│ ├── 3_11.html
│ ├── 3_20.html
│ └── 3_9.html
├── lesson2
│ ├── 2_3.js
│ ├── 2_9.js
│ ├── 2_1.js
│ ├── 2_4.js
│ ├── 2_11.js
│ ├── 2_18.js
│ ├── 2_10.js
│ ├── 2_12.js
│ ├── 2_24.js
│ ├── 2_15.js
│ ├── 2_2.js
│ ├── 2_5.js
│ ├── 2_13.js
│ ├── 2_25.js
│ ├── 2_8.js
│ ├── 2_14.js
│ ├── 2_28.js
│ ├── 2_22.js
│ ├── 2_17.js
│ ├── 2_29.js
│ ├── 2_21.js
│ ├── 2_16.js
│ ├── 2_27.js
│ ├── 2_7.js
│ ├── 2_19.js
│ ├── 2_23.js
│ ├── 2_30.js
│ ├── 2_26.js
│ ├── 2_20.js
│ └── 2_6.js
└── lesson5
│ ├── 5_5.js
│ ├── 5_3.js
│ ├── 5_4.js
│ ├── 5_1.js
│ ├── 5_7.js
│ ├── 5_2.js
│ └── 5_6.js
├── LICENSE
└── README.md
/.gitignore:
--------------------------------------------------------------------------------
1 | .idea/*
2 | node_modules
--------------------------------------------------------------------------------
/activities/activity6/activity/note.txt:
--------------------------------------------------------------------------------
1 |
--------------------------------------------------------------------------------
/exercises/exercise35/note.txt:
--------------------------------------------------------------------------------
1 | test note
--------------------------------------------------------------------------------
/activities/activity6/solution/note.txt:
--------------------------------------------------------------------------------
1 | test note!
--------------------------------------------------------------------------------
/babel-basic-config/.babelrc:
--------------------------------------------------------------------------------
1 | {
2 | "presets": ["es2015"]
3 | }
--------------------------------------------------------------------------------
/code-snippets/lesson6/6_3.js:
--------------------------------------------------------------------------------
1 | const http = require( 'http' );
--------------------------------------------------------------------------------
/exercises/exercise14/.babelrc:
--------------------------------------------------------------------------------
1 | {
2 | "presets": ["es2015"]
3 | }
--------------------------------------------------------------------------------
/code-snippets/lesson6/6_10.js:
--------------------------------------------------------------------------------
1 | load( 'filePath' ).pipe( HTTP_Response );
--------------------------------------------------------------------------------
/code-snippets/lesson1/1_46.js:
--------------------------------------------------------------------------------
1 | class House {}
2 | class Mansion extends House {}
3 |
--------------------------------------------------------------------------------
/code-snippets/lesson4/4_2.json:
--------------------------------------------------------------------------------
1 | {
2 | "scripts": {
3 | "test": "mocha ./test.js"
4 | }
5 | }
--------------------------------------------------------------------------------
/code-snippets/lesson6/6_13.js:
--------------------------------------------------------------------------------
1 | app.get( '/', ( req, res ) => res.end( 'Working express server!' ) )
2 |
--------------------------------------------------------------------------------
/code-snippets/lesson3/3_5.html:
--------------------------------------------------------------------------------
1 |
4 |
--------------------------------------------------------------------------------
/code-snippets/lesson1/1_11.js:
--------------------------------------------------------------------------------
1 | // No arguments passed into the function
2 | ( ) => { /* Do function stuff here */ }
3 |
--------------------------------------------------------------------------------
/code-snippets/lesson6/6_17.js:
--------------------------------------------------------------------------------
1 | app.get( '/abc?de', ( req, res ) => {
2 | console.log( 'Matched /abde or /abcde' );
3 | } );
--------------------------------------------------------------------------------
/code-snippets/lesson6/6_4.js:
--------------------------------------------------------------------------------
1 | const http = require('http');
2 | const hostname = '127.0.0.1';
3 | const port = 8000;
4 |
--------------------------------------------------------------------------------
/exercises/exercise8/index.js:
--------------------------------------------------------------------------------
1 | const data = [ 1, 2, 3 ];
2 | const [ a, , b, c = 4 ] = data;
3 | console.log( a, b, c );
4 |
--------------------------------------------------------------------------------
/code-snippets/lesson3/3_7.html:
--------------------------------------------------------------------------------
1 |
4 |
--------------------------------------------------------------------------------
/exercises/exercise10/index.js:
--------------------------------------------------------------------------------
1 | const data = { arr: [ 1, 2, 3 ] };
2 | const { arr: [ , v2 ] } = data;
3 | console.log( v2 );
4 |
--------------------------------------------------------------------------------
/code-snippets/lesson1/1_51.html:
--------------------------------------------------------------------------------
1 |
4 |
--------------------------------------------------------------------------------
/code-snippets/lesson6/6_14.js:
--------------------------------------------------------------------------------
1 | app.listen( port, hostname, () => console.log( `Server running at http://${hostname}:${port}/` ) );
2 |
--------------------------------------------------------------------------------
/code-snippets/lesson6/6_33.html:
--------------------------------------------------------------------------------
1 | HTML
2 | JSX and React
--------------------------------------------------------------------------------
/code-snippets/lesson6/6_18.js:
--------------------------------------------------------------------------------
1 | app.get( '/fo+d', ( req, res ) => {
2 | console.log( 'Matched /fod, /food, /foood, /fooooooooood' );
3 | } );
--------------------------------------------------------------------------------
/code-snippets/lesson6/6_19.js:
--------------------------------------------------------------------------------
1 | app.get( '/fo*d', ( req, res ) => {
2 | console.log( 'Matched /fd, /fod, /food, /foooooooood' );
3 | } );
4 |
--------------------------------------------------------------------------------
/code-snippets/lesson6/6_21.js:
--------------------------------------------------------------------------------
1 | app.get( '/amazon/audible/:userId/books/:bookId', ( req, res ) => {
2 | console.log( req.params );
3 | } );
4 |
--------------------------------------------------------------------------------
/code-snippets/lesson1/1_2.js:
--------------------------------------------------------------------------------
1 | example = 5; // Assign value
2 | console.log( example ); // Expect output: 5
3 | var example; // Declare variable
4 |
--------------------------------------------------------------------------------
/code-snippets/lesson2/2_3.js:
--------------------------------------------------------------------------------
1 | TwitterAPI.listFollowers( { user_id: 'example_user' }, (err, result) => {
2 | console.log( err, result );
3 | } );
--------------------------------------------------------------------------------
/code-snippets/lesson6/6_16.js:
--------------------------------------------------------------------------------
1 | app.get( '/', ( req, res, next ) => next() );
2 | app.get( '/', ( req, res ) => res.end( 'Second handler!' ) );
3 |
--------------------------------------------------------------------------------
/code-snippets/lesson6/6_6.js:
--------------------------------------------------------------------------------
1 | server.listen( port, hostname, () => {
2 | console.log(`Server running at http://${hostname}:${port}/`);
3 | });
4 |
--------------------------------------------------------------------------------
/code-snippets/lesson1/1_4.js:
--------------------------------------------------------------------------------
1 | // Referenced before declaration
2 | console.log( example ); // Expect output: undefined
3 | var example = 'example';
4 |
--------------------------------------------------------------------------------
/code-snippets/lesson6/6_22.js:
--------------------------------------------------------------------------------
1 | app.get( /^web.*/, ( req, res ) => {
2 | console.log( 'Matched strings like web, website, and webmail' );
3 | } );
4 |
--------------------------------------------------------------------------------
/code-snippets/lesson6/6_28.js:
--------------------------------------------------------------------------------
1 | const elementJSX =
Hello, world!
;
2 | const elementJS = React.createElement( "div", null, "Hello, world!" );
3 |
--------------------------------------------------------------------------------
/exercises/exercise27/test.js:
--------------------------------------------------------------------------------
1 | 'use strict';
2 |
3 | describe( 'My first test!', () => {
4 |
5 | it( 'Passing test!', () => {} );
6 |
7 | } );
8 |
--------------------------------------------------------------------------------
/code-snippets/lesson6/6_12.js:
--------------------------------------------------------------------------------
1 | const express = require( 'express' );
2 | const hostname = '127.0.0.1';
3 | const port = 8000;
4 | const app = express();
5 |
--------------------------------------------------------------------------------
/exercises/exercise32/index.js:
--------------------------------------------------------------------------------
1 | const ourModule = require('./module.js');
2 | console.log( ourModule.exportedString );
3 | ourModule.exportedFunction();
4 |
--------------------------------------------------------------------------------
/code-snippets/lesson1/1_15.js:
--------------------------------------------------------------------------------
1 | // Arrow function with an object literal in the body
2 | ( num1, num2 ) => ( { prop1: num1, prop2: num2 } ) // Returns an object
3 |
--------------------------------------------------------------------------------
/code-snippets/lesson1/1_52.html:
--------------------------------------------------------------------------------
1 |
2 |
3 |
--------------------------------------------------------------------------------
/code-snippets/lesson2/2_9.js:
--------------------------------------------------------------------------------
1 | const myPromise = new Promise( ( resolve, reject ) => {
2 | // Do asynchronous work here and call resolve or reject
3 | } );
4 |
--------------------------------------------------------------------------------
/code-snippets/lesson3/3_1.html:
--------------------------------------------------------------------------------
1 | Some text here
2 |
5 |
--------------------------------------------------------------------------------
/exercises/exercise9/index.js:
--------------------------------------------------------------------------------
1 | const data = { f1: 'v1', f2: '2', f3: 'v3' };
2 | const { f1, f2: field2, f4 = 'v4' } = data;
3 | console.log( f1, field2, f4 );
4 |
--------------------------------------------------------------------------------
/code-snippets/lesson6/6_7.js:
--------------------------------------------------------------------------------
1 | const fs = require( 'fs' );
2 | fs.createReadStream( './path/to/files.ext' ).on( 'data', data => {
3 | console.log( data );
4 | } );
5 |
--------------------------------------------------------------------------------
/exercises/exercise3/index.js:
--------------------------------------------------------------------------------
1 | const fn1 = function( a, b ) { return a + b; };
2 | const fn2 = ( a, b ) => { return a + b; };
3 | console.log( fn1( 3 ,5 ), fn2( 3, 5 ) );
4 |
--------------------------------------------------------------------------------
/exercises/exercise32/module.js:
--------------------------------------------------------------------------------
1 | module.exports = {
2 | exportedString: 'An exported string!',
3 | exportedFunction(){ console.log( 'An exported function!' ) }
4 | };
5 |
--------------------------------------------------------------------------------
/exercises/exercise5/index.js:
--------------------------------------------------------------------------------
1 | let a = 5, b = 10;
2 | console.log( a + ' + ' + b + ' is equal to ' + ( a + b ) );
3 | console.log( `${a} + ${b} is equal to ${a + b}` );
4 |
--------------------------------------------------------------------------------
/code-snippets/lesson1/1_7.js:
--------------------------------------------------------------------------------
1 | // Referenced before declaration
2 | console.log( example ); // Expect ReferenceError because example is not defined
3 | let example = 'example';
4 |
--------------------------------------------------------------------------------
/code-snippets/lesson2/2_1.js:
--------------------------------------------------------------------------------
1 | function foo( x ) { return 2 * x; }
2 | function bar( y ) { return foo( y + 5 ) - 10; }
3 |
4 | console.log( bar( 15 ) ); // Expected output: 30
5 |
--------------------------------------------------------------------------------
/code-snippets/lesson1/1_8.js:
--------------------------------------------------------------------------------
1 | // Referenced before declaration
2 | console.log( example ); // Expect ReferenceError because example is not defined
3 | const example = 'example';
4 |
--------------------------------------------------------------------------------
/code-snippets/lesson3/3_19.html:
--------------------------------------------------------------------------------
1 |
2 |
6 |
--------------------------------------------------------------------------------
/code-snippets/lesson1/1_31.js:
--------------------------------------------------------------------------------
1 | let a = 10;
2 | let b = 5;
3 |
4 | [ a, b ] = [ b, a ];
5 |
6 | console.log( a ); // Expected output: 5
7 | console.log( b ); // Expected output: 10
8 |
--------------------------------------------------------------------------------
/code-snippets/lesson1/1_34.js:
--------------------------------------------------------------------------------
1 | function fn( n1, n2, n3 ) {
2 | console.log( n1, n2, n3 );
3 | }
4 |
5 | const values = [ 1, 2, 3 ];
6 | fn( ...values ); // Expected output: 1, 2, 3
7 |
--------------------------------------------------------------------------------
/code-snippets/lesson5/5_5.js:
--------------------------------------------------------------------------------
1 | const state = { age: 15 }
2 | function doSomething( name ) {
3 | return state.age > 13 ? `${name} is old enough` : `${name} is not old enough`;
4 | }
5 |
--------------------------------------------------------------------------------
/exercises/exercise20/index.html:
--------------------------------------------------------------------------------
1 |
2 |
3 | My title
4 |
5 |
6 | My link
7 | My header
8 |
9 |
10 |
--------------------------------------------------------------------------------
/code-snippets/lesson1/1_16.js:
--------------------------------------------------------------------------------
1 | const example = 'pretty';
2 | console.log( `Template literals are ${ example } useful!!!` );
3 | // Expected output: Template literals are pretty useful!!!
4 |
--------------------------------------------------------------------------------
/code-snippets/lesson1/1_18.js:
--------------------------------------------------------------------------------
1 | function javascriptOrCPlusPlus() { return 'JavaScript'; }
2 | const outputLiteral = `We are learning about ${ `Professional ${ javascriptOrCPlusPlus() }` }`
3 |
--------------------------------------------------------------------------------
/code-snippets/lesson4/4_1.js:
--------------------------------------------------------------------------------
1 | function adjustValue( value ) {
2 | if ( value > 5 ) {
3 | value--;
4 | } else if ( value < -5 ) {
5 | value++;
6 | }
7 | return value
8 | }
9 |
--------------------------------------------------------------------------------
/code-snippets/lesson1/1_49.js:
--------------------------------------------------------------------------------
1 | // HouseClass.js
2 | export default class() { /* Class body goes here */ }
3 |
4 | // myFunction.js
5 | export default function() { /* Function body goes here */ }
6 |
--------------------------------------------------------------------------------
/code-snippets/lesson6/6_11.js:
--------------------------------------------------------------------------------
1 | fs.existsSync( '/some/path/to/file.txt' );
2 | fs.existsSync( Buffer.from( '/some/path/to/file.txt' ) );
3 | fs.existsSync( new URL( 'file://some/path/to/file.txt' ) );
--------------------------------------------------------------------------------
/code-snippets/lesson1/1_25.js:
--------------------------------------------------------------------------------
1 | const varName = 'firstName';
2 | const person = {
3 | [ varName ]: 'John',
4 | lastName: 'Smith'
5 | };
6 | console.log( person.firstName ); // Expected output: John
7 |
--------------------------------------------------------------------------------
/code-snippets/lesson2/2_4.js:
--------------------------------------------------------------------------------
1 | TwitterAPI.listFollowers( { user_id: 'example_user' }, (err, result) => {
2 | if ( err ) {
3 | // HANDLE ERROR
4 | }
5 | console.log( err, result );
6 | } );
7 |
--------------------------------------------------------------------------------
/code-snippets/lesson3/3_12.html:
--------------------------------------------------------------------------------
1 |
2 |
6 |
--------------------------------------------------------------------------------
/code-snippets/lesson6/6_2.js:
--------------------------------------------------------------------------------
1 | module.exports = {
2 | exportedVariable,
3 | exportedFn
4 | };
5 |
6 | const exportedVariable = 10;
7 | function exportedFn( args ){ console.log( 'exportedFn' ) ;}
8 |
--------------------------------------------------------------------------------
/code-snippets/lesson6/6_8.js:
--------------------------------------------------------------------------------
1 | const fs = require( 'fs' );
2 | const writeable = fs.createWriteStream( './path/to/files.ext' );
3 | writeable.write( 'some data' );
4 | writeable.write( 'more data!' );
5 |
--------------------------------------------------------------------------------
/code-snippets/lesson6/6_9.js:
--------------------------------------------------------------------------------
1 | const fileSystemStream = load( 'filePath' );
2 | fileSystemStream.on( 'data', data => HTTP_Response.push( data ) );
3 | fileSystemStream.on( 'end', HTTP_Response.end() );
4 |
--------------------------------------------------------------------------------
/code-snippets/lesson6/6_23.js:
--------------------------------------------------------------------------------
1 | app.use( ( req, res, next ) => {
2 | req.currentTime = new Date();
3 | next();
4 | } );
5 | app.get( '/', ( req, res ) => {
6 | console.log( req.currentTime );
7 | } );
8 |
--------------------------------------------------------------------------------
/code-snippets/lesson6/6_5.js:
--------------------------------------------------------------------------------
1 | const server = http.createServer((req, res) => {
2 | res.statusCode = 200;
3 | res.setHeader('Content-Type', 'text/plain');
4 | res.end('Welcome to my server!\n');
5 | });
--------------------------------------------------------------------------------
/code-snippets/lesson1/1_43.js:
--------------------------------------------------------------------------------
1 | class House{
2 | constructor(address, floors = 1, garage = false) {
3 | this.address = address;
4 | this.floors = floors;
5 | this.garage = garage;
6 | }
7 | }
8 |
--------------------------------------------------------------------------------
/code-snippets/lesson2/2_11.js:
--------------------------------------------------------------------------------
1 | // Resolve the promise with a value
2 | const myPromise = new Promise( ( resolve, reject ) => {
3 | // Do asynchronous work here
4 | resolve( { key1: 'value1' } );
5 | } );
6 |
--------------------------------------------------------------------------------
/code-snippets/lesson2/2_18.js:
--------------------------------------------------------------------------------
1 | // Promise chain handles rejection and continues
2 | // apiCall1 returns a rejected promise
3 | myPromse.then( apiCall1 ).then( apiCall2 ).then( apiCall3 ).catch( errorHandler1 );
4 |
--------------------------------------------------------------------------------
/code-snippets/lesson6/6_29.js:
--------------------------------------------------------------------------------
1 | const name = "David";
2 | function multiplyBy2( num ) { return num * 2; }
3 | const element1 = Hello {name}!
;
4 | const element2 = 6 * 2 = {multiplyBy2(6)}
;
5 |
--------------------------------------------------------------------------------
/code-snippets/lesson1/1_10.js:
--------------------------------------------------------------------------------
1 | // Single argument arrow function
2 | arg1 => { /* Do function stuff here */ }
3 |
4 | // Non simple identifier function argument
5 | ( arg1 = 10 ) => { /* Do function stuff here */ }
6 |
--------------------------------------------------------------------------------
/code-snippets/lesson1/1_27.js:
--------------------------------------------------------------------------------
1 | let names = [ 'John', 'Michael' ];
2 | let [ name1, name2 ] = names;
3 |
4 | console.log( name1 ); // Expected output: 'John'
5 | console.log( name2 ); // Expected output: 'Michael'
6 |
--------------------------------------------------------------------------------
/code-snippets/lesson6/6_25.js:
--------------------------------------------------------------------------------
1 | app.get( '/', ( req, res ) => {
2 | throw new Error( 'OH NO AN ERROR!' );
3 | } );
4 | app.use( ( err, req, res, next ) => {
5 | req.json( 'Got an error!' + err.message );
6 | } );
7 |
--------------------------------------------------------------------------------
/code-snippets/lesson1/1_30.js:
--------------------------------------------------------------------------------
1 | let [ a = 1, b = 2, c = 3 ] = [ 'cat', null ];
2 | console.log( a ); // Expected output: 'cat'
3 | console.log( b ); // Expected output: null
4 | console.log( c ); // Expected output: 3
5 |
--------------------------------------------------------------------------------
/code-snippets/lesson3/3_8.html:
--------------------------------------------------------------------------------
1 |
2 |
7 |
--------------------------------------------------------------------------------
/code-snippets/lesson6/6_1.json:
--------------------------------------------------------------------------------
1 | {
2 | "dependencies": {
3 | "amqplib": "^0.5.2",
4 | "body-parser": "^1.18.3",
5 | "cookie-parser": "^1.4.3",
6 | "express": "^4.16.3",
7 | "uuid": "^3.3.2"
8 | }
9 | }
--------------------------------------------------------------------------------
/code-snippets/lesson6/6_30.js:
--------------------------------------------------------------------------------
1 | import ReactDOM from 'react-dom';
2 | const element = HELLO WORLD!!!
;
3 | ReactDOM.render( element, document.getElementById('root'), () => {
4 | console.log( 'Done rendering' );
5 | });
--------------------------------------------------------------------------------
/code-snippets/lesson2/2_10.js:
--------------------------------------------------------------------------------
1 | // Reject promise with an error
2 | const myPromise = new Promise( ( resolve, reject ) => {
3 | // Do asynchronous work here
4 | reject( new Error( 'Oh no! Promise was rejected' ) );
5 | } );
6 |
--------------------------------------------------------------------------------
/code-snippets/lesson3/3_3.html:
--------------------------------------------------------------------------------
1 | Some text here
2 |
3 |
4 |
7 |
--------------------------------------------------------------------------------
/code-snippets/lesson6/6_31.js:
--------------------------------------------------------------------------------
1 | class ConstructorExample extends React.Component{
2 | constructor( props ){
3 | super( props );
4 | this.variable = 'test';
5 | }
6 | render() { return Constructor Example
; }
7 | }
8 |
--------------------------------------------------------------------------------
/code-snippets/lesson1/1_36.js:
--------------------------------------------------------------------------------
1 | const obj = { firstName: 'Bob', lastName: 'Smith' };
2 | const { firstName, lastName } = obj;
3 |
4 | console.log( firstName ); // Expected output: 'Bob'
5 | console.log( lastName ); // Expected output: 'Smith'
6 |
--------------------------------------------------------------------------------
/code-snippets/lesson1/1_38.js:
--------------------------------------------------------------------------------
1 | const obj = { firstName: 'Bob', lastName: 'Smith' };
2 | const { firstName: first, lastName } = obj;
3 |
4 | console.log( first ); // Expected output: 'Bob'
5 | console.log( lastName ); // Expected output: 'Smith'
6 |
--------------------------------------------------------------------------------
/code-snippets/lesson5/5_3.js:
--------------------------------------------------------------------------------
1 | function notPure( input ) {
2 | input.prop2 = 'test';
3 | }
4 |
5 | function pure( input ) {
6 | input = JSON.parse( JSON.stringify( input ) );
7 | input.prop2 = 'test';
8 | return input;
9 | }
10 |
--------------------------------------------------------------------------------
/code-snippets/lesson1/1_37.js:
--------------------------------------------------------------------------------
1 | const obj = { firstName: 'Bob', lastName: 'Smith' };
2 | const { firstName, middleName } = obj;
3 |
4 | console.log( firstName ); // Expected output: 'Bob'
5 | console.log( middleName ); // Expected output: undefined
6 |
--------------------------------------------------------------------------------
/code-snippets/lesson3/3_4.html:
--------------------------------------------------------------------------------
1 | Some text here
2 |
3 |
7 |
--------------------------------------------------------------------------------
/code-snippets/lesson4/4_4.js:
--------------------------------------------------------------------------------
1 | describe( 'Array', () => {
2 | before( 'description', done => { } );
3 | after( 'description', done => { } );
4 | beforeEach( 'description', done => { } );
5 | afterEach( 'description', done => { } );
6 | } );
7 |
--------------------------------------------------------------------------------
/exercises/exercise15/index.js:
--------------------------------------------------------------------------------
1 | function *gen() {
2 | let i = 1;
3 | while (true){
4 | yield i;
5 | i = i * 2;
6 | }
7 | }
8 | const generator = gen();
9 | console.log( generator.next(), generator.next(), generator.next() );
10 |
--------------------------------------------------------------------------------
/code-snippets/lesson3/3_10.html:
--------------------------------------------------------------------------------
1 |
4 |
9 |
--------------------------------------------------------------------------------
/code-snippets/lesson3/3_16.html:
--------------------------------------------------------------------------------
1 |
--------------------------------------------------------------------------------
/code-snippets/lesson3/3_18.html:
--------------------------------------------------------------------------------
1 |
--------------------------------------------------------------------------------
/code-snippets/lesson3/3_2.html:
--------------------------------------------------------------------------------
1 | Some text here
2 | Some text here
3 | Some text here
4 |
7 |
--------------------------------------------------------------------------------
/code-snippets/lesson1/1_24.js:
--------------------------------------------------------------------------------
1 | function getPersionES6( name, age, height ) {
2 | return {
3 | name,
4 | height,
5 |
6 | getAge(){ return age; }
7 | };
8 | }
9 | getPersionES6( 'Zachary', 23, 195 ).getAge()
10 | // Expected output: 23
11 |
--------------------------------------------------------------------------------
/code-snippets/lesson3/3_14.html:
--------------------------------------------------------------------------------
1 | Click me!
2 |
8 |
--------------------------------------------------------------------------------
/code-snippets/lesson6/6_15.js:
--------------------------------------------------------------------------------
1 | app.get( '/', ( req, res ) => res.end('GET request at /') );
2 | app.post( '/user', ( req, res ) => res.end( 'POST request at /user') );
3 | app.delete( '/cart/item', ( req, res ) => res.end('DELETE request at /cart/item') );
4 |
--------------------------------------------------------------------------------
/exercises/exercise18/index.js:
--------------------------------------------------------------------------------
1 | const myPromise = new Promise( ( resolve, reject ) => {
2 | console.log( 'Starting asynchronous work!' );
3 | setTimeout( () => { resolve( 'Done!' ); }, 1000 );
4 | } );
5 | myPromise.then( value => console.log( value ) );
6 |
--------------------------------------------------------------------------------
/code-snippets/lesson1/1_22.js:
--------------------------------------------------------------------------------
1 | function getPersionES6( name, age, height ) {
2 | return {
3 | name,
4 | age,
5 | height
6 | };
7 | }
8 | getPersionES6( 'Zachary', 23, 195 )
9 | // Expected output: { name: 'Zachary', age: 23, height: 195 }
10 |
--------------------------------------------------------------------------------
/code-snippets/lesson1/1_5.js:
--------------------------------------------------------------------------------
1 | // Declared and assigned
2 | var example = { prop1: 'test' };
3 | console.log( 'example:', example ); // Expect output: example: {prop1: 'test'}
4 | // Value reassigned
5 | example = 5;
6 | console.log( example ); // Expect output: 5
7 |
--------------------------------------------------------------------------------
/code-snippets/lesson2/2_12.js:
--------------------------------------------------------------------------------
1 | // Resolve the promise with a value or reject with an error
2 | myPromise.then(
3 | ( result ) => { /* handle result */ }, // Promise fulfilled handler
4 | ( err ) => { /* handle error here */ } // Promise rejected handler
5 | ) ;
6 |
--------------------------------------------------------------------------------
/code-snippets/lesson5/5_4.js:
--------------------------------------------------------------------------------
1 | function sortObjField1( field ) {
2 | return function ( v1, v2 ) {
3 | return v1[ field ] > v2[ field ];
4 | }
5 | }
6 |
7 | function sortObjField2( field, v1, v2 ) {
8 | return v1[ field ] > v2[ field ];
9 | }
10 |
--------------------------------------------------------------------------------
/exercises/exercise12/index.js:
--------------------------------------------------------------------------------
1 | class Vehicle {
2 | constructor( wheels, topSpeed ) {
3 | this.wheels = wheels;
4 | this.topSpeed = topSpeed;
5 | }
6 | }
7 | const tricycle = new Vehicle( 3, 20 );
8 | console.log( tricycle.wheels, tricycle.topSpeed );
9 |
--------------------------------------------------------------------------------
/code-snippets/lesson1/1_39.js:
--------------------------------------------------------------------------------
1 | const obj = { firstName: 'Bob', lastName: 'Smith' };
2 | const { firstName = 'Samantha', middleName = 'Chris' } = obj;
3 |
4 | console.log( firstName ); // Expected output: 'Bob'
5 | console.log( middleName ); // Expected output: 'Chris'
6 |
--------------------------------------------------------------------------------
/code-snippets/lesson1/1_44.js:
--------------------------------------------------------------------------------
1 | class House{
2 | constructor(address, floors = 1) {
3 | this.address = address;
4 | this.floors = floors;
5 | }
6 | }
7 | // Instantiate the class
8 | let myHouse = new House( '1100 Fake St., San Francisco CA, USA', 2, false );
9 |
--------------------------------------------------------------------------------
/code-snippets/lesson1/1_6.js:
--------------------------------------------------------------------------------
1 | // Declared and initialized
2 | let example = { prop1: 'test' };
3 | console.log( 'example:', example ); // Expect output: example: {prop1: 'test'}
4 | // Value reassigned
5 | example = 5;
6 | console.log( example ); // Expect output: 5
7 |
--------------------------------------------------------------------------------
/code-snippets/lesson2/2_24.js:
--------------------------------------------------------------------------------
1 | async function example1( ){ return 'Hello'; }
2 | async function example2( ){ return Promise.resolve( 'World' ); }
3 | example1().then( console.log ); // Expected output: Hello
4 | example2().then( console.log ); // Expected output: World
5 |
--------------------------------------------------------------------------------
/code-snippets/lesson3/3_13.html:
--------------------------------------------------------------------------------
1 |
2 |
8 |
--------------------------------------------------------------------------------
/code-snippets/lesson6/6_24.js:
--------------------------------------------------------------------------------
1 | app.get( '/synchronousError', ( req, res ) => {
2 | throw new Error( 'Synchronous error' );
3 | } );
4 | app.get( '/asynchronousError', ( req, res, next ) => {
5 | setTimeout( () => next( new Error( 'Asynchronous error' ) ), 0 );
6 | } );
7 |
--------------------------------------------------------------------------------
/code-snippets/lesson1/1_40.js:
--------------------------------------------------------------------------------
1 | const obj = { firstName: 'Bob', lastName: 'Smith' };
2 | const { firstName: first = 'Samantha', middleName: middle = 'Chris' } = obj;
3 |
4 | console.log( first ); // Expected output: 'Bob'
5 | console.log( middle); // Expected output: 'Chris'
6 |
--------------------------------------------------------------------------------
/code-snippets/lesson3/3_6.html:
--------------------------------------------------------------------------------
1 |
4 |
9 |
--------------------------------------------------------------------------------
/code-snippets/lesson1/1_1.js:
--------------------------------------------------------------------------------
1 | var example = 5;
2 | function test() {
3 | var testVariable = 10;
4 | console.log( example ); // Expect output: 5
5 | console.log( testVariable ); // Expect output: 10
6 | }
7 | test();
8 | console.log( testVariable ); // Expect reference error
9 |
--------------------------------------------------------------------------------
/code-snippets/lesson1/1_20.js:
--------------------------------------------------------------------------------
1 | function tagFunction( strings ){ console.log( strings.raw[0] ); }
2 | tagFunction`This is line 1. \n This is line 2.`
3 | // Expected output: 'This is line 1. \n This is line 2.' The characters '\' and 'n' are not parsed into a newline character
4 |
--------------------------------------------------------------------------------
/code-snippets/lesson1/1_21.js:
--------------------------------------------------------------------------------
1 | function getPersionES5( name, age, height ) {
2 | return {
3 | name: name,
4 | age: age,
5 | height: height
6 | };
7 | }
8 | getPersionES5( 'Zachary', 23, 195 )
9 | // Expected output: { name: 'Zachary', age: 23, height: 195 }
10 |
--------------------------------------------------------------------------------
/code-snippets/lesson1/1_23.js:
--------------------------------------------------------------------------------
1 | function getPersonES5( name, age, height ) {
2 | return {
3 | name: name,
4 | height: height,
5 |
6 | getAge: function(){ return age; }
7 | };
8 | }
9 | getPersonES5( 'Zachary', 23, 195 ).getAge()
10 | // Expected output: 23
11 |
--------------------------------------------------------------------------------
/code-snippets/lesson4/4_3.js:
--------------------------------------------------------------------------------
1 | var assert = require('assert');
2 | describe('Array', function() {
3 | describe('#indexOf()', function() {
4 | it('should return -1 when the value is not present', function() {
5 | assert.equal([1,2,3].indexOf(4), -1);
6 | });
7 | });
8 | });
--------------------------------------------------------------------------------
/activities/activity3/package.json:
--------------------------------------------------------------------------------
1 | {
2 | "name": "",
3 | "version": "1.0.0",
4 | "description": "Lesson 3 Topic C Activity",
5 | "main": "index.js",
6 | "author": "Zachary Shute",
7 | "license": "ISC",
8 | "dependencies": {
9 | "jquery": "^3.3.1"
10 | }
11 | }
12 |
--------------------------------------------------------------------------------
/code-snippets/lesson1/1_33.js:
--------------------------------------------------------------------------------
1 | function fn( ...[ n1, n2, n3 ] ) {
2 | // Destructures an indefinite number of function parameters into the array args, which is destructured into 3 variables
3 | console.log( n1, n2, n3 );
4 | }
5 |
6 | fn( 1, 2 ); // Expected output: 1, 2, undefined
7 |
--------------------------------------------------------------------------------
/code-snippets/lesson1/1_35.js:
--------------------------------------------------------------------------------
1 | const [ n1, n2, n3, ...remaining ] = [ 1, 2, 3, 4, 5, 6 ];
2 | console.log( n1 ); // Expected output: 1
3 | console.log( n2 ); // Expected output: 2
4 | console.log( n3 ); // Expected output: 3
5 | console.log( remaining ); // Expected output: [ 4, 5, 6 ]
6 |
--------------------------------------------------------------------------------
/code-snippets/lesson1/1_55.js:
--------------------------------------------------------------------------------
1 | let sequence = gen();
2 | console.log(sequence.next()); //Expected output: { value: 0, done: false }
3 | console.log(sequence.next()); //Expected output: { value: 1, done: false }
4 | console.log(sequence.next()); //Expected output: { value: 2, done: false }
5 |
--------------------------------------------------------------------------------
/exercises/exercise25/exercise.js:
--------------------------------------------------------------------------------
1 | 'use strict';
2 |
3 | function fakeRounding( arg1 ) {
4 | const decimal = Math.abs(arg1) % 1;
5 | if ( decimal <= 0.5 ) {
6 | return Math.ceil( arg1 );
7 | }
8 | return Math.floor( arg1 );
9 | }
10 |
11 | // Write solution here...
12 |
--------------------------------------------------------------------------------
/code-snippets/lesson1/1_53.js:
--------------------------------------------------------------------------------
1 | function createIterator( array ){
2 | let currentIndex = 0;
3 | return {
4 | next(){
5 | return currentIndex < array.length ?
6 | { value: array[ currentIndex++ ], done: false} :
7 | { done: true };
8 | }
9 | };
10 | }
11 |
--------------------------------------------------------------------------------
/code-snippets/lesson1/1_42.js:
--------------------------------------------------------------------------------
1 | const obj = { firstName: 'Bob', middleName: 'Chris', lastName: 'Smith' };
2 | const { firstName, ...otherNames } = obj;
3 |
4 | console.log( firstName ); // Expected output: 'Bob'
5 | console.log( otherNames ); // Expected output: { middleName: 'Chris', lastName: 'Smith' }
6 |
--------------------------------------------------------------------------------
/activities/activity4/index.js:
--------------------------------------------------------------------------------
1 | 'use strict';
2 |
3 | module.exports = { fibonacci };
4 |
5 | function fibonacci( i ) {
6 | if ( i <= 0 ) {
7 | return 0;
8 | } else if ( i === 1 ) {
9 | return 1;
10 | } else {
11 | return fibonacci( i - 1 ) + fibonacci( i - 2 );
12 | }
13 | }
14 |
--------------------------------------------------------------------------------
/activities/activity4/package.json:
--------------------------------------------------------------------------------
1 | {
2 | "name": "testing-frameworks",
3 | "version": "1.0.0",
4 | "description": "",
5 | "main": "index.js",
6 | "scripts": {
7 | "test": "mocha ./test.js"
8 | },
9 | "author": "Zachary Shute ",
10 | "license": "MIT"
11 | }
12 |
--------------------------------------------------------------------------------
/code-snippets/lesson5/5_1.js:
--------------------------------------------------------------------------------
1 | function addImperative( arr ) {
2 | let result = 0;
3 | for ( let i = 0; i < arr.length; i++ ) {
4 | result += arr[ i ];
5 | }
6 | return result;
7 | }
8 |
9 | function addDeclarative( arr ) {
10 | return arr.reduce( ( red, val ) => red + val, 0 );
11 | }
12 |
--------------------------------------------------------------------------------
/code-snippets/lesson6/6_26.html:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
--------------------------------------------------------------------------------
/exercises/exercise27/package.json:
--------------------------------------------------------------------------------
1 | {
2 | "name": "testing-frameworks",
3 | "version": "1.0.0",
4 | "description": "",
5 | "main": "index.js",
6 | "scripts": {
7 | "test": "mocha ./test.js"
8 | },
9 | "author": "Zachary Shute ",
10 | "license": "MIT"
11 | }
12 |
--------------------------------------------------------------------------------
/code-snippets/lesson2/2_15.js:
--------------------------------------------------------------------------------
1 | // Resolve the promise with a value
2 | const myPromise = new Promise( ( resolve, reject ) => {
3 | resolve( 'Promise was resolved!' );
4 | } );
5 |
6 | myPromse.finally( value => {
7 | console.log( 'Finally!' );
8 | } );
9 |
10 | // Expected output:
11 | // Finally!
12 |
--------------------------------------------------------------------------------
/code-snippets/lesson2/2_2.js:
--------------------------------------------------------------------------------
1 | setTimeout( () => {
2 | // WARNING: this may take a long time to run on a slow computer
3 | // Try with smaller numbers first
4 | for( let i = 0; i < 2000000000; i++ ) {}
5 | console.log( 'done delaying' );
6 | }, 0 );
7 | setTimeout( () => { console.log( 'done!' ) }, 0 );
8 |
--------------------------------------------------------------------------------
/code-snippets/lesson2/2_5.js:
--------------------------------------------------------------------------------
1 | TwitterAPI.listFollowers( { user_id: 'example_user' }, (err, result) => {
2 | if ( err ) { throw err; }
3 | TwitterAPI.unfollow( { user_id: result[ 0 ].id }, ( err, result ) => {
4 | if ( err ) { throw err; }
5 | console.log( 'Unfollowed someone!' );
6 | } );
7 | } );
8 |
--------------------------------------------------------------------------------
/exercises/exercise22/index.html:
--------------------------------------------------------------------------------
1 |
2 |
3 | Click me!
4 |
10 |
11 |
12 |
--------------------------------------------------------------------------------
/code-snippets/lesson1/1_41.js:
--------------------------------------------------------------------------------
1 | const obj = { firstName: 'Bob', lastName: 'Smith' };
2 | let firstName, lastName;
3 |
4 | ( { firstName: first, lastName } = obj ); // Note parentheses around expression
5 |
6 | console.log( firstName ); // Expected output: 'Bob'
7 | console.log( lastName ); // Expected output: 'Smith'
8 |
--------------------------------------------------------------------------------
/code-snippets/lesson2/2_13.js:
--------------------------------------------------------------------------------
1 | // Resolve the promise with a value
2 | const myPromise = new Promise( ( resolve, reject ) => {
3 | // Do asynchronous work here
4 | resolve( 'Promise was resolved!' );
5 | } );
6 |
7 | myPromse.then( value => console.log( value ) );
8 | // Expected output: 'Promise was resolved'
9 |
--------------------------------------------------------------------------------
/code-snippets/lesson3/3_17.html:
--------------------------------------------------------------------------------
1 |
--------------------------------------------------------------------------------
/code-snippets/lesson1/1_9.js:
--------------------------------------------------------------------------------
1 | // Declared and initialized
2 | const example = { prop1: 'test' };
3 |
4 | // Variable reassigned
5 | example = 5; // Expect TypeError error because variable was declared with const
6 |
7 | // Object property updated
8 | example.prop1 = 5; // Expect no error because subproperty was modified
9 |
--------------------------------------------------------------------------------
/exercises/exercise7/index.js:
--------------------------------------------------------------------------------
1 | const PI = 3.1415;
2 | const INCHES_TO_FEET = 0.083333;
3 | const exportObject = {
4 | PI,
5 | INCHES_TO_FEET,
6 | sum( n1, n2 ) {
7 | return n1 + n2;
8 | },
9 | subtract( n1, n2 ) {
10 | return n1 - n2;
11 | }
12 | };
13 | console.log( exportObject );
14 |
15 |
16 |
--------------------------------------------------------------------------------
/code-snippets/lesson6/6_27.js:
--------------------------------------------------------------------------------
1 | class HelloWorld extends React.Component {
2 | render() {
3 | return (
4 |
5 | Hello World!!! Made by {this.props.by}!!!
6 |
7 | );
8 | }
9 | }
10 | ReactDOM.render(
11 | ,
12 | document.getElementById('root')
13 | );
14 |
--------------------------------------------------------------------------------
/code-snippets/lesson6/6_35.js:
--------------------------------------------------------------------------------
1 | class ListElement extends React.Component {
2 | render() {
3 | return (
4 | {this.props.items.map( i => {i} )}
5 | );
6 | }
7 | }
8 | ReactDOM.render(
9 | ,
10 | document.getElementById( 'root' )
11 | );
12 |
--------------------------------------------------------------------------------
/exercises/exercise34/index.js:
--------------------------------------------------------------------------------
1 | const express = require( 'express' );
2 | const hostname = '127.0.0.1';
3 | const port = 8000;
4 | const app = express();
5 | app.get( '/', ( req, res ) => res.end( 'Working express server!' ) );
6 | app.listen( port, hostname, () => console.log( `Server running at http://${hostname}:${port}/` ) );
7 |
--------------------------------------------------------------------------------
/code-snippets/lesson1/1_17.js:
--------------------------------------------------------------------------------
1 | // Using normal strings
2 | console.log( 'This is line 1\nThis is line 2' );
3 | // Expected output: This is line 1
4 | // This is line 2
5 |
6 | // Using template literals
7 | console.log( `This is line 1
8 | This is line 2` );
9 | // Expected output: This is line 1
10 | // This is line 2
11 |
--------------------------------------------------------------------------------
/code-snippets/lesson2/2_25.js:
--------------------------------------------------------------------------------
1 | async function awaitExample( /* arguments */ ){
2 | let promise = new Promise( ( resolve, reject ) => {
3 | setTimeout( () => resolve( 'done!'), 100 );
4 | });
5 | const result = await promise;
6 | console.log( result ); // Expected output: done!
7 | }
8 | awaitExample( /* arguments */ );
9 |
--------------------------------------------------------------------------------
/code-snippets/lesson5/5_7.js:
--------------------------------------------------------------------------------
1 | function multiplyBy2( c ) {
2 | return 2 * c;
3 | }
4 |
5 | function sumNumbers( a, b ) {
6 | return a + b;
7 | }
8 |
9 | const v1 = sumNumbers( 2, 4 ); // 2 + 4 = 6
10 | const v2 = multiplyBy2( v2 ); // 2 * 6 = 12
11 | const v3 = multiplyBy2( sumNumbers( 2, 4 ) ); // 2 * ( 2 + 4 ) = 12
12 |
--------------------------------------------------------------------------------
/code-snippets/lesson2/2_8.js:
--------------------------------------------------------------------------------
1 | function apiFunction( args, callback ){
2 | if ( !callback || !( typeof callback === 'function' ) ){
3 | throw new Error( 'Invalid callback. Provide a function.' );
4 | }
5 | let result = {};
6 | let err = null;
7 | // Do work
8 | // Set err and result
9 | cb( err, result );
10 | }
11 |
--------------------------------------------------------------------------------
/code-snippets/lesson5/5_2.js:
--------------------------------------------------------------------------------
1 | const state = { prop1: 5 };
2 |
3 | function notPure () {
4 | return state.prop1 > 0 ? 'Valid': 'Invalid';
5 | }
6 |
7 | function pure( val ) {
8 | return val > 0 ? 'Valid': 'Invalid';
9 | }
10 |
11 | notPure(); // Expected output: 'Valid'
12 | pure( state.prop ); // Expected output: 'Valid'
13 |
--------------------------------------------------------------------------------
/code-snippets/lesson3/3_15.html:
--------------------------------------------------------------------------------
1 | Click me!
2 |
8 |
--------------------------------------------------------------------------------
/code-snippets/lesson1/1_12.js:
--------------------------------------------------------------------------------
1 | // Multiple line body arrow function
2 | ( arg1, arg2 ) => {
3 | console.log( `This is arg1: ${arg1}` );
4 | console.log( `This is arg2: ${arg2}` );
5 | /* Many more lines of code can go here */
6 | }
7 |
8 | // Single line body arrow function
9 | ( arg1, arg2 ) => console.log( `This is arg1: ${arg1}` )
10 |
--------------------------------------------------------------------------------
/code-snippets/lesson1/1_28.js:
--------------------------------------------------------------------------------
1 | let names = [ 'John', 'Michael' ];
2 | let [ name1 ] = names
3 | let [ name2, name3, name4 ] = names;
4 |
5 | console.log( name1 ); // Expected output: 'John'
6 | console.log( name2 ); // Expected output: 'John'
7 | console.log( name3 ); // Expected output: 'Michael'
8 | console.log( name4 ); // Expected output: undefined
9 |
--------------------------------------------------------------------------------
/code-snippets/lesson1/1_29.js:
--------------------------------------------------------------------------------
1 | let names = [ 'John', 'Michael', 'Jessica', 'Susan' ];
2 | let [ name1,, name3 ] = names; // Note the missing variable name for the second array item
3 | let [ ,,, ] = names; // Ignores all items in the array
4 |
5 | console.log( name1 ); // Expected output: 'John'
6 | console.log( name3 ); // Expected output: 'Jessica'
7 |
--------------------------------------------------------------------------------
/code-snippets/lesson1/1_54.js:
--------------------------------------------------------------------------------
1 | // Using an iterator
2 | let it = createIterator( [ 'Hello', 'World' ] );
3 | console.log( it.next() ); // Expected output: { value: 'Hello', done: false }
4 | console.log( it.next() ); // Expected output: { value: 'World' , done: false }
5 | console.log( it.next() ); // Expected output: { value: undefined, done: true }
6 |
--------------------------------------------------------------------------------
/code-snippets/lesson3/3_11.html:
--------------------------------------------------------------------------------
1 |
4 |
5 |
11 |
--------------------------------------------------------------------------------
/code-snippets/lesson6/6_20.js:
--------------------------------------------------------------------------------
1 | app.get( '/b(es)?t', ( req, res ) => {
2 | console.log( 'Matched /bt and /best' );
3 | } );
4 | app.get( '/b(es)+t', ( req, res ) => {
5 | console.log( 'Matched /best, /besest, /besesest' );
6 | } );
7 | app.get( '/b(es)*t', ( req, res ) => {
8 | console.log( 'Matched /bt, /best, /besest, /besesest' );
9 | } );
10 |
--------------------------------------------------------------------------------
/code-snippets/lesson1/1_13.js:
--------------------------------------------------------------------------------
1 | // With return keyword - not necessary
2 | let tmp = ( num1, num2 ) => { return ( num1 + num2 ) } // If called with arguments num1 = 5 and num2 = 5, expected output is 10
3 |
4 | // Without return keyword or braces
5 | tmp = ( num1, num2 ) => num1 + num2 // If called with arguments num1 = 5 and num2 = 5, expected output is 10
6 |
--------------------------------------------------------------------------------
/code-snippets/lesson1/1_45.js:
--------------------------------------------------------------------------------
1 | class House{
2 | constructor( address, floors = 1) {
3 | this.address = address;
4 | this.floors = floors;
5 | }
6 | getFloors() {
7 | return this.floors;
8 | }
9 | }
10 | let myHouse = new House( '1100 Fake St., San Francisco CA, USA', 2 );
11 | console.log( myHouse.getFloors() ); // Expected output: 2
12 |
--------------------------------------------------------------------------------
/exercises/exercise30/index.js:
--------------------------------------------------------------------------------
1 | 'use strict';
2 |
3 | const data = [ { f1: 6, f2: 3 }, { f1: 12, f2: 0 }, { f1: 9, f2: 1 }, { f1: 6, f2: 7 } ];
4 | function swap( key1, key2 ) {
5 | return obj => {
6 | [ obj[ key1 ], obj[ key2 ] ] = [ obj[ key2 ], obj[ key1 ] ];
7 | return obj;
8 | }
9 | }
10 | console.log( data.map( swap( 'f1', 'f2' ) ) );
11 |
--------------------------------------------------------------------------------
/code-snippets/lesson3/3_20.html:
--------------------------------------------------------------------------------
1 |
--------------------------------------------------------------------------------
/code-snippets/lesson5/5_6.js:
--------------------------------------------------------------------------------
1 | const data = {
2 | prop1: 'value1',
3 | objectProp: { p1: 'v1', p2: 'v2' },
4 | arrayProp: [ 1, 'test' , { p1: 'v1' }, [ 1, 2, 3 ] ]
5 | };
6 | Object.freeze( data );
7 | Object.freeze( data.objectProp );
8 | Object.freeze( data.arrayProp );
9 | Object.freeze( data.arrayProp[2] );
10 | Object.freeze( data.arrayProp[3] );
11 |
--------------------------------------------------------------------------------
/code-snippets/lesson1/1_3.js:
--------------------------------------------------------------------------------
1 | // Top level scope
2 | function scopeExample() {
3 | // Scope block 1
4 | for ( let i = 0; i < 10; i++ ){ /* Scope block 2 */ }
5 | if ( true ) { /* Scope block 3 */ } else { /* Scope block 4 */ }
6 | // Braces without keywords create scope blocks
7 | { /* Scope block 5 */ }
8 | // Scope block 1
9 | }
10 | // Top level scope
11 |
--------------------------------------------------------------------------------
/code-snippets/lesson1/1_26.js:
--------------------------------------------------------------------------------
1 | const varName = 'first';
2 | function computeNameType( type ) {
3 | return type + 'Name';
4 | }
5 |
6 | const person = {
7 | [ varName + 'Name' ]: 'John',
8 | [ computeNameType( 'last' ) ]: 'Smith'
9 | };
10 |
11 | console.log( person.firstName ); // Expected output: John
12 | console.log( person.lastName ); // Expected output: Smith
13 |
--------------------------------------------------------------------------------
/code-snippets/lesson1/1_56.js:
--------------------------------------------------------------------------------
1 | function *gen() {
2 | let i = 0;
3 | while (true){
4 | let inData = yield i++;
5 | console.log( inData );
6 | }
7 | }
8 |
9 | let sequence = gen();
10 | sequence.next()
11 | sequence.next( 'test1' )
12 | sequence.next()
13 | sequence.next( 'test2' )
14 |
15 | // Expected output:
16 | // 'test1'
17 | // undefined
18 | // 'test2'
19 |
--------------------------------------------------------------------------------
/code-snippets/lesson2/2_14.js:
--------------------------------------------------------------------------------
1 | // Reject the promise with a value
2 | const myPromise = new Promise( ( resolve, reject ) => {
3 | // Do asynchronous work here
4 | reject( new Error ( 'Promise was rejected!' ) );
5 | } );
6 |
7 | myPromse.then( () => {}, error => console.log( error) );
8 | // Expected output: Error: Promise was rejected!
9 | // ** output stack trace omitted
10 |
--------------------------------------------------------------------------------
/exercises/exercise6/index.js:
--------------------------------------------------------------------------------
1 |
2 | function parseHouse( property ) {
3 | return `${property.owner} is selling the property at ${property.address} for ${property.price} USD`
4 | }
5 |
6 | const house = {
7 | address: "123 Main St, San Francisco CA, USA",
8 | floors: 2,
9 | price: 5000000,
10 | owner: "John Doe"
11 | };
12 |
13 | console.log( parseHouse( house ) );
14 |
--------------------------------------------------------------------------------
/code-snippets/lesson1/1_32.js:
--------------------------------------------------------------------------------
1 | function fn( num1, num2, ...args ) {
2 | // Destructures an indefinite number of function parameters into the array args, excluding the first two arguments passed in.
3 | console.log( num1 );
4 | console.log( num2 );
5 | console.log( args );
6 | }
7 |
8 | fn( 1, 2, 3, 4, 5, 6 );
9 | // Expected output
10 | // 1
11 | // 2
12 | // [ 3, 4, 5, 6 ]
13 |
--------------------------------------------------------------------------------
/code-snippets/lesson2/2_28.js:
--------------------------------------------------------------------------------
1 | async function nested1() { return await Promise.reject( 'Error!' ); }
2 | async function nested2() { return await nested1; }
3 | async function nested3() { return await nested2; }
4 | async function nestedErrorExample() {
5 | try{ const value1 = await nested3; }
6 | catch( err ){ console.log( err ); } // Expected output: Oh no!
7 | }
8 | nestedErrorExample();
9 |
--------------------------------------------------------------------------------
/exercises/exercise31/exercise.js:
--------------------------------------------------------------------------------
1 | 'use strict';
2 |
3 | const person = { age: 10, firstName: 'Sandra', lastName: 'Jeffereys' };
4 |
5 | function getOlder() {
6 | person.age++;
7 | }
8 |
9 | function formatName() {
10 | person.name = `Mrs. ${person.firstName} ${person.lastName}`;
11 | }
12 |
13 | console.log( person );
14 | getOlder();
15 | formatName();
16 | console.log( person );
17 |
--------------------------------------------------------------------------------
/code-snippets/lesson1/1_47.js:
--------------------------------------------------------------------------------
1 | class House {
2 | constructor( address = 'somewhere' ) {
3 | this.address = address;
4 | }
5 | }
6 | class Mansion extends House {
7 | constructor( address, floors ) {
8 | super( address );
9 | this.floors = floors;
10 | }
11 | }
12 | let mansion = new Mansion( 'Hollywood CA, USA', 6, 'Brad Pitt' );
13 | console.log( mansion.floors ); // Expected output: 6
14 |
--------------------------------------------------------------------------------
/code-snippets/lesson3/3_9.html:
--------------------------------------------------------------------------------
1 |
4 |
12 |
--------------------------------------------------------------------------------
/exercises/exercise23/exercise.html:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 | Advanced JavaScript - Lesson 3 - Exercise 23
5 |
6 |
7 | Shopping List
8 |
9 |
10 |
11 |
12 |
13 |
14 |
15 |
18 |
19 |
20 |
--------------------------------------------------------------------------------
/code-snippets/lesson6/6_32.js:
--------------------------------------------------------------------------------
1 | class ChildElement extends React.Component {
2 | render() {
3 | return (
4 |
5 | Click me!
6 |
7 | );
8 | }
9 | }
10 | class ParentElement extends React.Component {
11 | clicked() { console.log( 'clicked' ); }
12 | render() {
13 | return ;
14 | }
15 | }
16 |
--------------------------------------------------------------------------------
/exercises/exercise33/index.js:
--------------------------------------------------------------------------------
1 | const http = require( 'http' );
2 | const hostname = '127.0.0.1';
3 | const port = 8000;
4 | const server = http.createServer( ( req, res ) => {
5 | res.statusCode = 200;
6 | res.setHeader( 'Content-Type', 'text/plain' );
7 | res.end( 'My first server!\n' );
8 | } );
9 | server.listen( port, hostname, () => console.log( `Server running at http://${hostname}:${port}/` ) );
10 |
--------------------------------------------------------------------------------
/activities/activity3/package-lock.json:
--------------------------------------------------------------------------------
1 | {
2 | "version": "1.0.0",
3 | "lockfileVersion": 1,
4 | "requires": true,
5 | "dependencies": {
6 | "jquery": {
7 | "version": "3.3.1",
8 | "resolved": "https://registry.npmjs.org/jquery/-/jquery-3.3.1.tgz",
9 | "integrity": "sha512-Ubldcmxp5np52/ENotGxlLe6aGMvmF4R8S6tZjsP6Knsaxd/xp3Zrh50cG93lR6nPXyUFwzN3ZSOQI0wRJNdGg=="
10 | }
11 | }
12 | }
13 |
--------------------------------------------------------------------------------
/code-snippets/lesson1/1_50.js:
--------------------------------------------------------------------------------
1 | // math-module.js
2 | export const PI = 3.1415;
3 | export const DEGREES_IN_CIRCLE = 360;
4 | // index1.js
5 | import { PI } from 'math-module.js'
6 | // index2.js
7 | import { PI, DEGREES_IN_CIRCLE } from 'math-module.js'
8 | // index3.js
9 | import { PI as pi, DEGREES_IN_CIRCLE as degInCircle } from 'math-module.js'
10 | // index4.js
11 | import * as MathModule from 'math-module.js'
12 |
--------------------------------------------------------------------------------
/code-snippets/lesson2/2_22.js:
--------------------------------------------------------------------------------
1 | // Promise function to be wrapped
2 | function promiseFn( args ){
3 | return new Promise( ( resolve, reject ) => {
4 | /* do work */
5 | /* resolve or reject */
6 | } );
7 | }
8 |
9 | // Wrapper function
10 | function wrapper( promiseFn, args, callback ){
11 | promiseFn( args ).then( value => callback( null, value )
12 | .catch( err => callback( err, null );
13 | }
14 |
--------------------------------------------------------------------------------
/code-snippets/lesson2/2_17.js:
--------------------------------------------------------------------------------
1 | // Promise chain handles rejection and continues
2 | // apiCall1 is a function that returns a rejected promise
3 | // apiCall2 is a function that returns a resolved promise
4 | // apiCall3 is a function that returns a resolved promise
5 | // errorHandler1 is a function that returns a resolved promise
6 | myPromse.then( apiCall1 ).then( apiCall2, errorHandler1 ).then( apiCall3 ).catch( errorHandler2 );
7 |
--------------------------------------------------------------------------------
/code-snippets/lesson2/2_29.js:
--------------------------------------------------------------------------------
1 | // Promise chain - API functions return a promise
2 | myPromse.then( apiCall1 ).then( apiCall2 ).then( apiCall3 ).catch( errorHandler );
3 |
4 | async function asyncAwaitUse( myPromise ) {
5 | try{
6 | await myPromise;
7 | await apiCall1();
8 | await apiCall2();
9 | await apiCall3();
10 | } catch( err ){
11 | errorHandler( err );
12 | }
13 | }
14 | asyncAwaitUse( myPromise );
15 |
--------------------------------------------------------------------------------
/exercises/exercise35/basic-express-server.js:
--------------------------------------------------------------------------------
1 | 'use strict';
2 |
3 | // Full Code for the basic express server built in the lesson
4 |
5 | const express = require( 'express' );
6 | const hostname = '127.0.0.1';
7 | const port = 8000;
8 | const app = express();
9 | app.get( '/', ( req, res ) => res.end( 'Working express server!' ) );
10 | app.listen( port, hostname, () => console.log( `Server running at http://${hostname}:${port}/` ) );
11 |
--------------------------------------------------------------------------------
/code-snippets/lesson2/2_21.js:
--------------------------------------------------------------------------------
1 | // Create promises
2 | let promise1 = new Promise( ( resolve, reject ) => setTimeout( resolve( 10 ), 100 ) );
3 | let promise2 = new Promise( ( resolve, reject ) => setTimeout( resolve( 20 ), 200 ) );
4 | let promise3 = new Promise( ( resolve, reject ) => setTimeout( resolve( 30 ), 10 ) );
5 |
6 | Promise.race( [ promise1, promise2, promise3 ] ).then( result => console.log( result ) );
7 |
8 | //Expected output: 30
9 |
--------------------------------------------------------------------------------
/code-snippets/lesson2/2_16.js:
--------------------------------------------------------------------------------
1 | function apiCall1( result ) { // Function that returns a promise
2 | return new Promise( ( resolve, reject ) => {
3 | resolve( 'value1' );
4 | } );
5 | }
6 | function apiCall2( result ) {// Function that returns a promise
7 | return new Promise( ( resolve, reject ) => {
8 | resolve( 'value2' );
9 | } );
10 | }
11 | myPromse.then( apiCall1 ).then( apiCall2 ).then( result => console.log( 'done!') ) ;
12 |
--------------------------------------------------------------------------------
/activities/activity6/activity/.gitignore:
--------------------------------------------------------------------------------
1 | # See https://help.github.com/articles/ignoring-files/ for more about ignoring files.
2 |
3 | # dependencies
4 | /node_modules
5 | /.pnp
6 | .pnp.js
7 |
8 | # testing
9 | /coverage
10 |
11 | # production
12 | /build
13 |
14 | # misc
15 | .DS_Store
16 | .env.local
17 | .env.development.local
18 | .env.test.local
19 | .env.production.local
20 |
21 | npm-debug.log*
22 | yarn-debug.log*
23 | yarn-error.log*
24 |
--------------------------------------------------------------------------------
/activities/activity6/solution/.gitignore:
--------------------------------------------------------------------------------
1 | # See https://help.github.com/articles/ignoring-files/ for more about ignoring files.
2 |
3 | # dependencies
4 | /node_modules
5 | /.pnp
6 | .pnp.js
7 |
8 | # testing
9 | /coverage
10 |
11 | # production
12 | /build
13 |
14 | # misc
15 | .DS_Store
16 | .env.local
17 | .env.development.local
18 | .env.test.local
19 | .env.production.local
20 |
21 | npm-debug.log*
22 | yarn-debug.log*
23 | yarn-error.log*
24 |
--------------------------------------------------------------------------------
/code-snippets/lesson2/2_27.js:
--------------------------------------------------------------------------------
1 | async function tryCatchExample() {
2 | // Try to do asynchronous work
3 | try{
4 | const value1 = await Promise.resolve( 'Success 1' );
5 | const value2 = await Promise.resolve( 'Success 2' );
6 | const value3 = await Promise.reject( 'Oh no!' );
7 | }
8 |
9 | // Catch errors
10 | catch( err ){
11 | console.log( err ); // Expected output: Oh no!
12 | }
13 | }
14 |
15 | tryCatchExample()
16 |
--------------------------------------------------------------------------------
/exercises/exercise31/solution.js:
--------------------------------------------------------------------------------
1 | 'use strict';
2 |
3 | const person = { age: 10, firstName: 'Sandra', lastName: 'Jeffereys' };
4 |
5 | function getOlder( age ) {
6 | return ++age;
7 | }
8 |
9 | function formatName( first, last ) {
10 | return `Mrs. ${first} ${last}`;
11 | }
12 |
13 | console.log( person );
14 | person.age = getOlder( person.age );
15 | person.name = formatName( person.firstName, person.lastName );
16 | console.log( person );
17 |
--------------------------------------------------------------------------------
/code-snippets/lesson2/2_7.js:
--------------------------------------------------------------------------------
1 | function listHandler( err, result ) {
2 | TwitterAPI.unfollow( { user_id: result[ 0 ].id }, unfollowHandler );
3 | }
4 |
5 | function unfollowHandler( err, result) {
6 | TwitterAPI.block( { user_id: result.id }, blockHandler );
7 | }
8 |
9 | function blockHandler( err, result ) {
10 | console.log( 'User unfollowed and blocked!' );
11 | }
12 |
13 | TwitterAPI.listFollowers( { user_id: 'example_user' }, listHandler);
14 |
--------------------------------------------------------------------------------
/exercises/exercise1/index.js:
--------------------------------------------------------------------------------
1 | // Block scope exercise
2 | // Solution
3 | function fn1(){
4 | console.log('Scope 1');
5 | let scope = 5;
6 | console.log(scope);
7 |
8 | {
9 | console.log('Scope 2');
10 | let scope = 'different scope';
11 | console.log(scope);
12 |
13 | }
14 |
15 | {
16 | console.log('Scope 3');
17 | let scope = 'a third scope';
18 | console.log(scope);
19 |
20 | }
21 |
22 | }
23 |
24 | fn1();
25 |
--------------------------------------------------------------------------------
/babel-basic-config/package.json:
--------------------------------------------------------------------------------
1 | {
2 | "name": "bablel-example",
3 | "version": "1.0.0",
4 | "description": "Babel example",
5 | "main": "app.js",
6 | "scripts": {
7 | "transpile": "babel ./app.js --out-file app.transpiled.js --source-maps"
8 | },
9 | "author": "Zachary Shute ",
10 | "license": "ISC",
11 | "devDependencies": {
12 | "babel-cli": "^6.26.0",
13 | "babel-preset-es2015": "^6.24.1"
14 | }
15 | }
16 |
--------------------------------------------------------------------------------
/code-snippets/lesson2/2_19.js:
--------------------------------------------------------------------------------
1 | // Create promises
2 | let promise1 = new Promise( ( resolve, reject ) => setTimeout( () => resolve( 10 ), 100 ) );
3 | let promise2 = new Promise( ( resolve, reject ) => setTimeout( () => resolve( 20 ), 200 ) );
4 | let promise3 = new Promise( ( resolve, reject ) => setTimeout( () => resolve( 30 ), 10 ) );
5 | Promise.all( [ promise1, promise2, promise3 ] ).then( results => console.log( results ) );
6 | //Expected output: [ 10, 20, 30 ]
7 |
--------------------------------------------------------------------------------
/exercises/exercise14/package.json:
--------------------------------------------------------------------------------
1 | {
2 | "name": "bablel-example",
3 | "version": "1.0.0",
4 | "description": "Babel example",
5 | "main": "app.js",
6 | "scripts": {
7 | "transpile": "babel ./app.js --out-file app.transpiled.js --source-maps"
8 | },
9 | "author": "Zachary Shute ",
10 | "license": "ISC",
11 | "devDependencies": {
12 | "babel-cli": "^6.26.0",
13 | "babel-preset-es2015": "^6.24.1"
14 | }
15 | }
16 |
--------------------------------------------------------------------------------
/code-snippets/lesson1/1_14.js:
--------------------------------------------------------------------------------
1 | // Arrow function with a single line body
2 | // Assume numArray is an array of numbers
3 | let tmp = ( numArray ) => numArray.filter( n => n > 5).map( n => n - 1 ).every( n => n < 10 )
4 |
5 | // Arrow function with a single line body broken into multiple lines
6 | // Assume numArray is an array of numbers
7 | tmp = ( numArray ) => (
8 | numArray.filter( n => n > 5)
9 | .map( n => n - 1 )
10 | .every( n => n < 10 )
11 | )
12 |
--------------------------------------------------------------------------------
/code-snippets/lesson2/2_23.js:
--------------------------------------------------------------------------------
1 | // Callback function to be wrapped
2 | function wrappedFn( args, cb ){
3 | /* do work */
4 | /* call cb with error or result */
5 | }
6 |
7 | // Wrapper function
8 | function wrapper( wrappedFn, args ){
9 | return new Promise( ( resolve, reject ) => {
10 | wrappedFn( args, ( err, result ) => {
11 | if( err ) {
12 | return reject( err );
13 | }
14 | resolve( result );
15 | } );
16 | } );
17 | }
18 |
--------------------------------------------------------------------------------
/code-snippets/lesson1/1_48.js:
--------------------------------------------------------------------------------
1 | // math-module-1.js
2 | export const PI = 3.1415;
3 | export const DEGREES_IN_CIRCLE = 360;
4 | export function convertDegToRad( degrees ) {
5 | return degrees * PI / ( DEGREES_IN_CIRCLE /2 );
6 | }
7 |
8 | // math-module-2.js
9 | const PI = 3.1415;
10 | const DEGREES_IN_CIRCLE = 360;
11 | function convertDegToRad( degrees ) {
12 | return degrees * PI / ( DEGREES_IN_CIRCLE /2 );
13 | }
14 | export { PI, DEGREES_IN_CIRCLE, convertDegToRad };
15 |
--------------------------------------------------------------------------------
/code-snippets/lesson6/6_36.js:
--------------------------------------------------------------------------------
1 | class ControlledInput extends React.Component {
2 | constructor(props) {
3 | super(props);
4 | this.state = {value: ''};
5 | }
6 | handleChange(event) { this.setState({value: event.target.value}); }
7 | render() {
8 | return (
9 |
10 |
11 |
Value: {this.state.value}
12 |
13 | );
14 | }
15 | }
16 |
--------------------------------------------------------------------------------
/code-snippets/lesson2/2_30.js:
--------------------------------------------------------------------------------
1 | async function awaitPromiseAll(){
2 | let promise1 = new Promise( ( resolve, reject ) => setTimeout( () => resolve( 10 ), 100 ) );
3 | let promise2 = new Promise( ( resolve, reject ) => setTimeout( () => resolve( 20 ), 200 ) );
4 | let promise3 = new Promise( ( resolve, reject ) => setTimeout( () => resolve( 30 ), 10 ) );
5 | const result = await Promise.all( [ promise1, promise2, promise3 ] );
6 | console.log( result ); //Expected output: [ 10, 20, 30 ]
7 | }
8 | awaitPromiseAll();
9 |
--------------------------------------------------------------------------------
/exercises/exercise17/index.js:
--------------------------------------------------------------------------------
1 | 'use strict';
2 |
3 | function higherOrder( data, cb ) {
4 | if ( !cb || !( typeof cb === 'function' ) ) {
5 | throw new Error( 'Invalid callback. Please provide a function.' );
6 | }
7 |
8 | console.log( data );
9 |
10 | setTimeout( cb, 10 );
11 |
12 | }
13 |
14 | try {
15 | higherOrder( 1, null );
16 | } catch ( err ) {
17 | console.log( `Got error: ${err.message}` );
18 | }
19 |
20 | higherOrder( 1, () => {
21 | console.log( 'Callback Called!' )
22 | } );
23 |
--------------------------------------------------------------------------------
/exercises/exercise35/basic-http-server.js:
--------------------------------------------------------------------------------
1 | 'use strict';
2 |
3 | // Full Code for the basic HTTP server built in the lesson
4 |
5 | const http = require( 'http' );
6 | const hostname = '127.0.0.1';
7 | const port = 8000;
8 | const server = http.createServer( ( req, res ) => {
9 | res.statusCode = 200;
10 | res.setHeader( 'Content-Type', 'text/plain' );
11 | res.end( 'My first server!\n' );
12 | } );
13 | server.listen( port, hostname, () => console.log( `Server running at http://${hostname}:${port}/` ) );
14 |
--------------------------------------------------------------------------------
/code-snippets/lesson6/6_34.js:
--------------------------------------------------------------------------------
1 | class AccountControl extends React.Component {
2 | constructor( props ) {
3 | super( props );
4 | this.state = { account: this.props.account };
5 | }
6 | isLoggedIn() {
7 | if ( this.state.account ) { return ; }
8 | else { return ; }
9 | }
10 | render() {
11 | return (
12 |
13 | {this.isLoggedIn()}
14 | {this.state.account ? : }
15 |
16 | );
17 | }
18 | }
19 |
--------------------------------------------------------------------------------
/code-snippets/lesson2/2_26.js:
--------------------------------------------------------------------------------
1 | async function errorExample1( /* arguments */ ){
2 | return Promise.reject( 'Rejected!' );
3 | }
4 | async function errorExample2( /* arguments */ ){
5 | throw 'Rejected!';
6 | }
7 | async function errorExample3( /* arguments */ ){
8 | await Promise.reject( 'Rejected!' );
9 | }
10 | errorExample1().catch( console.log ); // Expected output: Rejected!
11 | errorExample2().catch( console.log ); // Expected output: Rejected!
12 | errorExample3().catch( console.log ); // Expected output: Rejected!
13 |
--------------------------------------------------------------------------------
/code-snippets/lesson2/2_20.js:
--------------------------------------------------------------------------------
1 | // Create promises
2 | let promise1 = new Promise( ( resolve, reject ) => {
3 | setTimeout( () => { reject( 'Error 1' ); }, 100 );
4 | } );
5 | let promise2 = new Promise( ( resolve, reject ) => {
6 | setTimeout( () => { reject( 'Error 2' ); }, 200 );
7 | } );
8 | let promise3 = new Promise( ( resolve, reject ) => {
9 | setTimeout( () => { reject( 'Error 3' ); }, 10 );
10 | } );
11 | Promise.all( [ promise1, promise2, promise3 ] ).then( console.log ).catch( console.log );
12 | // Expected output:
13 | // Error: Error 3
14 |
--------------------------------------------------------------------------------
/code-snippets/lesson1/1_19.js:
--------------------------------------------------------------------------------
1 | // Define the tag function
2 | function tagFunction( strings, numExp, fruitExp ) {
3 | const str0 = strings[0]; // 'We have '
4 | const str1 = strings[1]; // ' of '
5 | const quantity = numExp < 10 ? 'very few' : 'a lot';
6 | return str0 + quantity + str1 + fruitExp + str2;
7 | }
8 | const fruit = 'apple', num = 8;
9 | // Note: lack of parenthesis or whitespace when calling tag function
10 | const output = tagFunction`We have ${num} of ${fruit}. Exciting!`
11 | console.log( output ) // Expected output: We have very few of apples. Exciting!
12 |
--------------------------------------------------------------------------------
/exercises/exercise13/index.js:
--------------------------------------------------------------------------------
1 | class Car {
2 | constructor( make, model, year, color ) {
3 | this.make = make;
4 | this.model = model;
5 | this.year = year;
6 | this.color = color;
7 | }
8 |
9 | setColor( color ) {
10 | this.color = color;
11 | }
12 | }
13 |
14 | let subaru = new Car( 'Subaru', 'Outback', 2005, 'Grey' );
15 | console.log( 'Make',subaru.make );
16 | console.log( 'Model', subaru.model );
17 | console.log( 'Year', subaru.year );
18 | console.log( 'Color', subaru.color );
19 | subaru.setColor( 'Red' );
20 | console.log( 'New color:', subaru.color );
21 |
--------------------------------------------------------------------------------
/exercises/exercise14/app.js:
--------------------------------------------------------------------------------
1 | // Function 1
2 | const fn1 = ( a, b ) => {
3 | b++;
4 | a++;
5 | return a + b;
6 | };
7 |
8 | // Function 2
9 | const fn2 = ( a, b ) => a * b;
10 |
11 | // Function 3
12 | const fn3 = a => {
13 | a = a * a;
14 | return a + a;
15 | };
16 |
17 | // Function 4
18 | const fn4 = () => {
19 | let a = 10;
20 | a = a * a;
21 | return a + a;
22 | };
23 |
24 | // Function 5
25 | const fn5 = ( a ) => ( { prop1: a } );
26 |
27 | console.log( fn1( 5, 10 ) );
28 | console.log( fn2( 5, 10 ) );
29 | console.log( fn3( 5 ) );
30 | console.log( fn4() );
31 | console.log( fn5( 5 ) );
--------------------------------------------------------------------------------
/exercises/exercise35/package.json:
--------------------------------------------------------------------------------
1 | {
2 | "name": "exercise-35-nodejs-server",
3 | "version": "1.0.0",
4 | "description": "NodeJS server for Lesson 6 Exercise 35",
5 | "main": "index.js",
6 | "scripts": {
7 | "test": "echo \"Error: no test specified\" && exit 1",
8 | "basic-http-server": "node ./basic-http-server.js",
9 | "basic-express-server": "node ./basic-express-server.js",
10 | "start": "node ./index.js"
11 | },
12 | "author": "Zachary Shute",
13 | "license": "ISC",
14 | "dependencies": {
15 | "body-parser": "^1.18.3",
16 | "express": "^4.16.4"
17 | }
18 | }
19 |
--------------------------------------------------------------------------------
/activities/activity6/activity/index.html:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 | Professional JavaScript - Lesson 6 - Activity C
5 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
13 |
14 |
15 |
16 |
17 |
--------------------------------------------------------------------------------
/activities/activity6/solution/index.html:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 | Professional JavaScript - Lesson 6 - Activity C
5 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
13 |
14 |
15 |
16 |
17 |
--------------------------------------------------------------------------------
/exercises/exercise19/index.js:
--------------------------------------------------------------------------------
1 | 'use strict';
2 |
3 | function promiseFunction( data ) {
4 | return new Promise( ( resolve, reject ) => {
5 | setTimeout( () => {
6 |
7 | console.log( data );
8 |
9 | if ( typeof data === 'number' ) {
10 | return reject( new Error( 'Data cannot be of type \'number\'.' ) );
11 | }
12 |
13 | resolve( 'Success!' );
14 |
15 | }, 10 );
16 | } );
17 | }
18 |
19 | promiseFunction( 1 ).then( console.log ).catch( err => console.log( `Error: ${err.message}` ) );
20 | promiseFunction( 'test' ).then( console.log ).catch( err => console.log( `Error: ${err.message}` ) );
21 |
--------------------------------------------------------------------------------
/exercises/exercise4/solution.js:
--------------------------------------------------------------------------------
1 | 'use strict';
2 |
3 | // Function 1
4 | const fn1 = ( a, b ) => {
5 | b++;
6 | a++;
7 | return a + b;
8 | };
9 |
10 | // Function 2
11 | const fn2 = ( a, b ) => a * b;
12 |
13 | // Function 3
14 | const fn3 = a => {
15 | a = a * a;
16 | return a + a;
17 | };
18 |
19 | // Function 4
20 | const fn4 = () => {
21 | let a = 10;
22 | a = a * a;
23 | return a + a;
24 | };
25 |
26 | // Function 5
27 | const fn5 = ( a ) => ( { prop1: a } );
28 |
29 | console.log( fn1( 5, 10 ) );
30 | console.log( fn2( 5, 10 ) );
31 | console.log( fn3( 5 ) );
32 | console.log( fn4() );
33 | console.log( fn5( 5 ) );
34 |
--------------------------------------------------------------------------------
/exercises/exercise11/index.js:
--------------------------------------------------------------------------------
1 | const courseCatalogMetadata = [
2 | {
3 | title: 'Linear Algebra II',
4 | description: 'Advanced linear algebra.',
5 | texts: [ {
6 | author: 'James Smith',
7 | price: 120,
8 | ISBN: '912-6-44-578441-0'
9 | } ]
10 | }
11 | ];
12 | const [ course ] = courseCatalogMetadata;
13 | const [ { texts: textbooks } ] = courseCatalogMetadata;
14 | const [ { texts: [ textbook ] } ] = courseCatalogMetadata;
15 | const [ { texts: [ { ISBN } ] } ] = courseCatalogMetadata;
16 |
17 | console.log( course );
18 | console.log( textbooks );
19 | console.log( textbook );
20 | console.log( ISBN );
21 |
--------------------------------------------------------------------------------
/exercises/exercise24/index.js:
--------------------------------------------------------------------------------
1 | 'use strict';
2 |
3 | function fibonacci( i ) {
4 | if ( i <= 0 ) {
5 | return 0;
6 | } else if ( i === 1 ) {
7 | return 1;
8 | } else {
9 | return fibonacci( i - 1 ) + fibonacci( i - 2 );
10 | }
11 | }
12 |
13 | function test( value, expected ) {
14 | if ( value !== expected ) {
15 | throw new Error( 'Value did not match expected value' );
16 | } else {
17 | console.log( 'Test passed.' );
18 | }
19 | }
20 |
21 | test( fibonacci( 0 ), 0 );
22 | test( fibonacci( 1 ), 1 );
23 | test( fibonacci( 2 ), 1 );
24 | test( fibonacci( 5 ), 5 );
25 | test( fibonacci( 7 ), 13 );
26 | test( fibonacci( 9 ), 34 );
27 |
--------------------------------------------------------------------------------
/exercises/exercise28/index.js:
--------------------------------------------------------------------------------
1 | 'use strict';
2 |
3 | function imperative( arr ) {
4 | const filtered = [];
5 | for ( let i = 0; i < arr.length; i++ ) {
6 | if ( arr[ i ] > 0 ) {
7 | filtered.push( arr[ i ] );
8 | }
9 | }
10 | for ( let j = 0; j < filtered.length; j++ ) {
11 | filtered[ j ] = 2 * filtered[ j ];
12 | }
13 | return filtered;
14 | }
15 |
16 | function declarative( arr ) {
17 | return arr.filter( v => v > 0 ).map( v => 2 * v );
18 | }
19 |
20 | //Test values
21 | const values = [ -5, -4, -3, -2, -1, 0, 1, 2, 3, 4, 5 ];
22 | console.log( imperative( values ) ); // Output: [ 2, 4, 6, 8, 10 ]
23 | console.log( declarative( values ) ); // Output: [ 2, 4, 6, 8, 10 ]
24 |
--------------------------------------------------------------------------------
/exercises/exercise4/exercise.js:
--------------------------------------------------------------------------------
1 | 'use strict';
2 |
3 | // Function 1
4 | const fn1 = function ( a, b ) {
5 | b++;
6 | a++;
7 | return a + b;
8 | };
9 |
10 | // Function 2
11 | const fn2 = function ( a, b ) {
12 | return a * b;
13 | };
14 |
15 | // Function 3
16 | const fn3 = function ( a ) {
17 | a = a * a;
18 | return a + a;
19 | };
20 |
21 | // Function 4
22 | const fn4 = function () {
23 | let a = 10;
24 | a = a * a;
25 | return a + a;
26 | };
27 |
28 | // Function 5
29 | const fn5 = function ( a ) {
30 | return { prop1: a };
31 | };
32 |
33 | console.log( fn1( 5, 10 ) );
34 | console.log( fn2( 5, 10 ) );
35 | console.log( fn3( 5 ) );
36 | console.log( fn4() );
37 | console.log( fn5( 5 ) );
38 |
--------------------------------------------------------------------------------
/exercises/exercise29/exercise-test.js:
--------------------------------------------------------------------------------
1 | 'use strict';
2 |
3 | // Write addItem function here
4 | function addItem() {}
5 |
6 | // Run this code to test your addItem function. If an error is thrown then the code is not correct
7 | const cart = [ 'soap', 'toothpaste', 'toothpaste' ];
8 | const originalLength = cart.length;
9 | const quantityToAdd = 3;
10 | const cartModified = addItem( cart, 'carrot', quantityToAdd );
11 |
12 | if ( cart.length !== originalLength ) {
13 | throw new Error( 'Original cart modified' );
14 | }
15 |
16 | if ( cartModified.length !== ( originalLength + quantityToAdd ) ) {
17 | throw new Error( 'Did not add items to the new cart' );
18 | }
19 |
20 | console.log('No function purity error!');
21 |
--------------------------------------------------------------------------------
/exercises/exercise14/app.transpiled.js:
--------------------------------------------------------------------------------
1 | "use strict";
2 |
3 | // Function 1
4 | var fn1 = function fn1(a, b) {
5 | b++;
6 | a++;
7 | return a + b;
8 | };
9 |
10 | // Function 2
11 | var fn2 = function fn2(a, b) {
12 | return a * b;
13 | };
14 |
15 | // Function 3
16 | var fn3 = function fn3(a) {
17 | a = a * a;
18 | return a + a;
19 | };
20 |
21 | // Function 4
22 | var fn4 = function fn4() {
23 | var a = 10;
24 | a = a * a;
25 | return a + a;
26 | };
27 |
28 | // Function 5
29 | var fn5 = function fn5(a) {
30 | return { prop1: a };
31 | };
32 |
33 | console.log(fn1(5, 10));
34 | console.log(fn2(5, 10));
35 | console.log(fn3(5));
36 | console.log(fn4());
37 | console.log(fn5(5));
38 |
39 | //# sourceMappingURL=app.transpiled.js.map
--------------------------------------------------------------------------------
/activities/activity4/test.js:
--------------------------------------------------------------------------------
1 | 'use strict';
2 |
3 | const { fibonacci } = require( './index.js' );
4 |
5 | describe( 'fibonacci', () => {
6 |
7 | it( 'n=0 should equal 0', ( done ) => {
8 | done( fibonacci( 0 ) !== 0 );
9 | } );
10 |
11 | it( 'n=1 should equal 1', ( done ) => {
12 | done( fibonacci( 1 ) !== 1 );
13 | } );
14 |
15 | it( 'n=2 should equal 1', ( done ) => {
16 | done( fibonacci( 2 ) !== 1 );
17 | } );
18 |
19 | it( 'n=5 should equal 5', ( done ) => {
20 | done( fibonacci( 5 ) !== 5 );
21 | } );
22 |
23 | it( 'n=7 should equal 13', ( done ) => {
24 | done( fibonacci( 7 ) !== 13 );
25 | } );
26 |
27 | it( 'n=9 should equal 34', ( done ) => {
28 | done( fibonacci( 9 ) !== 34 );
29 | } );
30 |
31 | } );
--------------------------------------------------------------------------------
/code-snippets/lesson2/2_6.js:
--------------------------------------------------------------------------------
1 | TwitterAPI.listFollowers( { user_id: 'example_user' }, (err, result) => {
2 | const [ id1, id2, id3 ] = [ result[ 0 ].id, result[ 1 ].id, result[ 2 ].id ];
3 | TwitterAPI.unfollow( { user_id: id1 }, ( err, result ) => {
4 | TwitterAPI.block( { user_id: id1 }, ( err, result ) => {
5 | TwitterAPI.unfollow( { user_id: id2 }, ( err, result ) => {
6 | TwitterAPI.block( { user_id: id2 }, ( err, result ) => {
7 | TwitterAPI.unfollow( { user_id: id3 }, ( err, result ) => {
8 | TwitterAPI.block( { user_id: id3 }, ( err, result ) => {
9 | console.log( 'Unfollowed and blocked 3 users!' );
10 | });
11 | });
12 | });
13 | });
14 | });
15 | });
16 | });
--------------------------------------------------------------------------------
/exercises/exercise25/solution.js:
--------------------------------------------------------------------------------
1 | 'use strict';
2 |
3 | function fakeRounding( arg1 ) {
4 | const decimal = Math.abs(arg1) % 1;
5 | if ( decimal <= 0.5 ) {
6 | return Math.ceil( arg1 );
7 | }
8 | return Math.floor( arg1 );
9 | }
10 |
11 | function test( value, expected ) {
12 | if ( value !== expected ) {
13 | throw new Error( `Value computed (${value}) did not match expected value (${expected})` );
14 | } else {
15 | console.log( 'Test passed.' );
16 | }
17 | }
18 |
19 | test( fakeRounding( 0 ), 0 );
20 | test( fakeRounding( 0.4999 ), 1 );
21 | test( fakeRounding( 0.5 ), 1 );
22 | test( fakeRounding( 0.5001 ), 0 );
23 | test( fakeRounding( -0.4999 ), 0 );
24 | test( fakeRounding( -0.5 ), 0 );
25 | test( fakeRounding( -0.5001 ), -1 );
26 |
--------------------------------------------------------------------------------
/activities/activity6/activity/package.json:
--------------------------------------------------------------------------------
1 | {
2 | "name": "lesson-6-topic-b",
3 | "version": "0.1.0",
4 | "private": true,
5 | "dependencies": {
6 | "babel-cli": "^6.26.0",
7 | "babel-preset-react-app": "^3.1.2",
8 | "body-parser": "^1.18.3",
9 | "express": "^4.16.4",
10 | "react": "^16.6.0",
11 | "react-dom": "^16.6.0",
12 | "react-scripts": "^2.1.1"
13 | },
14 | "scripts": {
15 | "build": "npx babel src -d lib --presets react-app/prod",
16 | "start": "node ./index.js"
17 | },
18 | "description": "This project was bootstrapped with [Create React App](https://github.com/facebook/create-react-app).",
19 | "main": "index.js",
20 | "devDependencies": {},
21 | "keywords": [],
22 | "author": "",
23 | "license": "ISC"
24 | }
25 |
--------------------------------------------------------------------------------
/activities/activity6/solution/package.json:
--------------------------------------------------------------------------------
1 | {
2 | "name": "lesson-6-topic-b",
3 | "version": "0.1.0",
4 | "private": true,
5 | "dependencies": {
6 | "babel-cli": "^6.26.0",
7 | "babel-preset-react-app": "^3.1.2",
8 | "body-parser": "^1.18.3",
9 | "express": "^4.16.4",
10 | "react": "^16.6.0",
11 | "react-dom": "^16.6.0",
12 | "react-scripts": "^2.1.1"
13 | },
14 | "scripts": {
15 | "build": "npx babel src -d lib --presets react-app/prod",
16 | "start": "node ./index.js"
17 | },
18 | "description": "This project was bootstrapped with [Create React App](https://github.com/facebook/create-react-app).",
19 | "main": "index.js",
20 | "devDependencies": {},
21 | "keywords": [],
22 | "author": "",
23 | "license": "ISC"
24 | }
25 |
--------------------------------------------------------------------------------
/exercises/exercise26/exercise.html:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
34 |
--------------------------------------------------------------------------------
/exercises/exercise2/index.js:
--------------------------------------------------------------------------------
1 | // Variable Declaration exercise
2 | console.log('Hoisted before assignment:', hoisted );
3 | var hoisted = 'this got hoisted';
4 | console.log('Hoisted after assignment:',hoisted);
5 |
6 | try{
7 | console.log(notHoisted1);
8 | } catch(err){
9 | console.log('Not hoisted1 with error:', err.message);
10 | }
11 | let notHoisted1 = 5;
12 | console.log('notHoisted1 after assignment', notHoisted1);
13 |
14 | try{
15 | console.log(notHoisted2);
16 | } catch(err){
17 | console.log('Not hoisted2 with error:', err.message);
18 | }
19 | const notHoisted2 = [1,2,3];
20 | console.log('notHoisted2 after assignment', notHoisted2);
21 |
22 | try{
23 | notHoisted2 = 'new value';
24 | } catch(err){
25 | console.log('Not hoisted 2 was not able to be changed');
26 | }
27 | notHoisted2.push(5);
28 | console.log('notHoisted2 updated. Now is:', notHoisted2);
29 |
--------------------------------------------------------------------------------
/exercises/exercise29/exercise-solution.js:
--------------------------------------------------------------------------------
1 | 'use strict';
2 |
3 | // Solution:
4 | function addItem( cart, item, quantity ) {
5 | // Duplicate cart
6 | const newCart = JSON.parse( JSON.stringify( cart ) );
7 | newCart.push( ...Array( quantity ).fill( item ) );
8 | return newCart;
9 | }
10 |
11 | // Run this code to test your addItem function. If an error is thrown then the code is not correct
12 | const cart = [ 'soap', 'toothpaste', 'toothpaste' ];
13 | const originalLength = cart.length;
14 | const quantityToAdd = 3;
15 | const cartModified = addItem( cart, 'carrot', quantityToAdd );
16 |
17 | if ( cart.length !== originalLength ) {
18 | throw new Error( 'Original cart modified' );
19 | }
20 |
21 | if ( cartModified.length !== ( originalLength + quantityToAdd ) ) {
22 | throw new Error( 'Did not add items to the new cart' );
23 | }
24 |
25 | console.log('No function purity error!');
26 |
--------------------------------------------------------------------------------
/exercises/exercise26/spec sheet and tests.txt:
--------------------------------------------------------------------------------
1 | Requirements:
2 | - text input for name
3 | - text input for email
4 | - text input for age
5 | - submit button
6 | - name must be at least 1 character
7 | - name cannot be more than 50 characters
8 | - email must be at least 1 character
9 | - email cannot be more than 50 characters
10 | - age must be a number
11 | - age must be at least 13
12 |
13 | Tests:
14 | - text input for name exists
15 | - text input for email exists
16 | - text input for age exists
17 | - submit button exists
18 | - submit button on click calls validate function
19 | - test empty name field
20 | - test name field with 1 character
21 | - test name field with 50 characters
22 | - test name field with 51 characters
23 | - test empty email field
24 | - test email field with 1 character
25 | - test email field with 50 characters
26 | - test email field with 51 characters
27 | - test empty age field
28 | - test age field with non numeric input
29 | - test age field with value less than 13
30 | - test age field with value of 13
31 | - test age field with value greater than 13
32 | - test with valid data to ensure info is printed to console
--------------------------------------------------------------------------------
/LICENSE:
--------------------------------------------------------------------------------
1 | MIT License
2 |
3 | Copyright (c) 2018 Training By Packt
4 |
5 | Permission is hereby granted, free of charge, to any person obtaining a copy
6 | of this software and associated documentation files (the "Software"), to deal
7 | in the Software without restriction, including without limitation the rights
8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9 | copies of the Software, and to permit persons to whom the Software is
10 | furnished to do so, subject to the following conditions:
11 |
12 | The above copyright notice and this permission notice shall be included in all
13 | copies or substantial portions of the Software.
14 |
15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21 | SOFTWARE.
22 |
--------------------------------------------------------------------------------
/activities/activity2/simple_db.js:
--------------------------------------------------------------------------------
1 | 'use strict';
2 |
3 | module.exports = { get: get, insert: insert };
4 |
5 | const db = {
6 | 'john': { first: 'john', last: 'doe', age: 43 }
7 | };
8 |
9 | function get( key ) {
10 | return new Promise( ( resolve, reject ) => {
11 | setTimeout( () => {
12 |
13 | if ( !key ) {
14 | return reject( new Error( 'Must specify key' ) );
15 | }
16 |
17 | if ( !db[ key ] ) {
18 | return reject( new Error( 'Database entry does not exist' ) );
19 | }
20 |
21 | resolve( db[ key ] );
22 |
23 | }, 50 );
24 | } );
25 | }
26 |
27 | function insert( key, data ) {
28 | return new Promise( ( resolve, reject ) => {
29 | setTimeout( () => {
30 |
31 | if ( !key ) {
32 | return reject( new Error( 'Must specify key' ) );
33 | }
34 |
35 | if ( !data ) {
36 | return reject( new Error( 'Must specify data to set' ) );
37 | }
38 |
39 | if ( db[ key ] ) {
40 | return reject( new Error( 'Database entry already exists' ) );
41 | }
42 |
43 | db[ key ] = data;
44 | resolve( key )
45 |
46 | }, 50 );
47 | } );
48 | }
--------------------------------------------------------------------------------
/activities/activity6/activity/src/index.js:
--------------------------------------------------------------------------------
1 | /*
2 | Scenario: The Front End team working on your note taking app from Activity B has unexpectedly quit. You must build the front end for this application using React. Your front end should have two views, a Home view and an Edit view. Create a react component for each view. The home view should have a button that changes the view to the edit view. The edit view should have a button that switches back to the home view, a text input that contains the note text, a load button that calls the API load route, and a save button that calls the API save route. A NodeJS server has been provided to you. Write your React code in 'Lesson 6/topic c/activity/src/index.js.' When you are ready to test your code run the build script (defined in package.json) before starting the server. You can reference the index.html file from Activity B for hints on how to call the API routes.
3 | */
4 |
5 | /*BUILD REACT FRONT END HERE*/
6 | class App extends React.Component {
7 | constructor( props ) {
8 | super( props );
9 | }
10 |
11 | render() {
12 | return BUILD APP VIEW HERE
;
13 | }
14 | }
15 |
16 | ReactDOM.render(
17 | ,
18 | document.getElementById( 'root' )
19 | );
20 |
--------------------------------------------------------------------------------
/activities/activity5/activity-test.js:
--------------------------------------------------------------------------------
1 | 'use strict';
2 |
3 | // Write your function called immutable here
4 | function immutable() {}
5 |
6 | // Test code. If there are errors then the immutable function does not work as intended
7 | const obj = { a: 10, b: 15, obj: { c: 20 }, arr: [ 1, 5, 10, { test: 'value' } ] };
8 |
9 | const arr = [ 1, 5, [ 5, 6 ], { obj: true } ];
10 |
11 | immutable( obj );
12 | test_try_catch('add property at main object', ()=>{obj.test='test'} );
13 | test_try_catch('add property at nested object', ()=>{obj.obj.test='test'} );
14 | test_try_catch('add property at nested array', ()=>{obj.arr.push('test')} );
15 | test_try_catch('add property at nested array object element', ()=>{obj.arr[3].test='test'} );
16 |
17 | immutable( arr );
18 | test_try_catch('add element', ()=>{arr.push('test')} );
19 | test_try_catch('add element at nested array', ()=>{arr[2].push('test')} );
20 | test_try_catch('edit at nested object', ()=>{arr[3].test='test'} );
21 |
22 | console.log('Passed Tests!');
23 |
24 | function test_try_catch( test, _protected ) {
25 | let success = true;
26 | try {_protected();}
27 | catch ( e ) {success = false;}
28 | if ( success ) {
29 | throw new Error( `Failed test: ${test}` );
30 | }
31 | }
--------------------------------------------------------------------------------
/exercises/exercise35/index.js:
--------------------------------------------------------------------------------
1 | 'use strict';
2 |
3 | const express = require( 'express' );
4 | const http = require( 'http' );
5 | const bodyParser = require( 'body-parser' );
6 | const fs = require( 'fs' );
7 | const notePath = './note.txt';
8 |
9 | console.log( 'Starting HTTP server.' );
10 |
11 | const app = express();
12 | const server = http.createServer( app );
13 |
14 | console.log( 'Configuring HTTP server.' );
15 |
16 | // Middleware
17 | app.use( bodyParser.json( { strict: false } ) );
18 |
19 | // Route Handlers
20 | const router = express.Router();
21 |
22 | router.route( '/' ).get( ( req, res ) => res.sendFile( 'index.html', { root: __dirname } ) );
23 |
24 | router.route( '/save' ).post( ( req, res ) => {
25 | fs.writeFile( notePath, req.body, 'utf8', err => {
26 | if ( err ) {
27 | res.status( 500 ).json(err);
28 | }
29 | res.end();
30 | } );
31 | } );
32 |
33 | router.route( '/load' ).get( ( req, res ) => {
34 | fs.readFile( notePath, 'utf8', ( err, data ) => {
35 | if ( err ) {
36 | res.status( 500 ).json(err);
37 | }
38 | res.json( data );
39 | } );
40 | } );
41 |
42 | app.use( '/', router );
43 |
44 | const port = 8000;
45 |
46 | server.listen( port, err => {
47 | if ( err ) {
48 | throw err;
49 | }
50 |
51 | console.log( `Listening on port ${port}` );
52 | } );
--------------------------------------------------------------------------------
/activities/activity6/activity/index.js:
--------------------------------------------------------------------------------
1 | 'use strict';
2 |
3 | const express = require( 'express' );
4 | const http = require( 'http' );
5 | const bodyParser = require( 'body-parser' );
6 | const fs = require( 'fs' );
7 | const notePath = './note.txt';
8 |
9 | console.log( 'Starting HTTP server.' );
10 |
11 | const app = express();
12 | const server = http.createServer( app );
13 |
14 | console.log( 'Configuring HTTP server.' );
15 |
16 | // Middleware
17 | app.use( bodyParser.json( { strict: false } ) );
18 |
19 | app.use( express.static( __dirname ) );
20 | app.use( express.static( __dirname + '/lib' ) );
21 |
22 | // Route Handlers
23 | const router = express.Router();
24 |
25 | router.route( '/' ).get( ( req, res ) => res.sendFile( 'index.html', { } ) );
26 |
27 | router.route( '/save' ).post( ( req, res ) => {
28 | fs.writeFile( notePath, req.body, 'utf8', err => {
29 | if ( err ) {
30 | res.status( 500 ).json( err );
31 | }
32 | res.end();
33 | } );
34 | } );
35 |
36 | router.route( '/load' ).get( ( req, res ) => {
37 | fs.readFile( notePath, 'utf8', ( err, data ) => {
38 | if ( err ) {
39 | res.status( 500 ).json( err );
40 | }
41 | res.json( data );
42 | } );
43 | } );
44 |
45 | app.use( '/', router );
46 |
47 | const port = 8000;
48 |
49 | server.listen( port, err => {
50 | if ( err ) {
51 | throw err;
52 | }
53 |
54 | console.log( `Listening on port ${port}` );
55 | } );
56 |
--------------------------------------------------------------------------------
/activities/activity6/solution/index.js:
--------------------------------------------------------------------------------
1 | 'use strict';
2 |
3 | const express = require( 'express' );
4 | const http = require( 'http' );
5 | const bodyParser = require( 'body-parser' );
6 | const fs = require( 'fs' );
7 | const notePath = './note.txt';
8 |
9 | console.log( 'Starting HTTP server.' );
10 |
11 | const app = express();
12 | const server = http.createServer( app );
13 |
14 | console.log( 'Configuring HTTP server.' );
15 |
16 | // Middleware
17 | app.use( bodyParser.json( { strict: false } ) );
18 |
19 | app.use( express.static( __dirname ) );
20 | app.use( express.static( __dirname + '/lib' ) );
21 |
22 | // Route Handlers
23 | const router = express.Router();
24 |
25 | router.route( '/' ).get( ( req, res ) => res.sendFile( 'index.html', { } ) );
26 |
27 | router.route( '/save' ).post( ( req, res ) => {
28 | fs.writeFile( notePath, req.body, 'utf8', err => {
29 | if ( err ) {
30 | res.status( 500 ).json( err );
31 | }
32 | res.end();
33 | } );
34 | } );
35 |
36 | router.route( '/load' ).get( ( req, res ) => {
37 | fs.readFile( notePath, 'utf8', ( err, data ) => {
38 | if ( err ) {
39 | res.status( 500 ).json( err );
40 | }
41 | res.json( data );
42 | } );
43 | } );
44 |
45 | app.use( '/', router );
46 |
47 | const port = 8000;
48 |
49 | server.listen( port, err => {
50 | if ( err ) {
51 | throw err;
52 | }
53 |
54 | console.log( `Listening on port ${port}` );
55 | } );
56 |
--------------------------------------------------------------------------------
/exercises/exercise26/solution.html:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 | Submit
8 |
9 |
43 |
--------------------------------------------------------------------------------
/activities/activity1/index.js:
--------------------------------------------------------------------------------
1 | // Generator exercise
2 |
3 | /*
4 | Assignment:
5 | You have been tasked to build a simple app that generates numbers in the Fibonacci sequence upon request. The app generates the next number in the sequence for each request, and resets the sequence it is given an input. Use a generator to generate the Fibonacci sequence. If a value is passed into the generator, reset the sequence.
6 | */
7 |
8 | // Solution
9 |
10 | function* fibonacci () {
11 | let n2 = 0;
12 | let n1 = 1;
13 |
14 | while ( true ) {
15 | let input = yield n2;
16 | if ( input ) {
17 | n1 = 1;
18 | n2 = 0;
19 | } else {
20 | let next = n1 + n2;
21 | [ n1, n2 ] = [ next, n1 ];
22 | }
23 | }
24 | }
25 |
26 | let gen = fibonacci();
27 |
28 | console.log( gen.next().value );
29 | console.log( gen.next().value );
30 | console.log( gen.next().value );
31 | console.log( gen.next().value );
32 | console.log( gen.next().value );
33 | console.log( gen.next( true ).value );
34 | console.log( gen.next().value );
35 | console.log( gen.next().value );
36 | console.log( gen.next().value );
37 | console.log( gen.next().value );
38 | console.log( gen.next().value );
39 |
40 | /*
41 | Hints
42 | - Create a generator first that contains an infinite loop
43 | - Calculate and yield the next fibonacci number
44 | - Catch yield input with a variable and check truthyness
45 | - If truthy reset the seed values to 1 and 0
46 | - Update the seed values each step of the generator
47 | */
48 |
--------------------------------------------------------------------------------
/activities/activity3/activity.html:
--------------------------------------------------------------------------------
1 |
2 |
3 |
12 |
13 |
14 |
15 |
Toggle!
16 |
17 |
18 |
22 |
23 |
27 |
28 |
32 |
33 |
34 |
35 |
36 |
37 |
59 |
60 |
61 |
--------------------------------------------------------------------------------
/exercises/exercise21/exercise.html:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 | Advanced JavaScript - Lesson 3 - Exercise 21
6 |
40 |
41 |
42 |
43 |
47 |
48 |
49 |
--------------------------------------------------------------------------------
/exercises/exercise23/solution.html:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 | Advanced JavaScript - Lesson 3 - Exercise 23
5 |
6 |
7 | Shopping List
8 |
9 | Item to add:
10 | Add!
11 |
12 |
13 |
21 |
53 |
54 |
55 |
--------------------------------------------------------------------------------
/exercises/exercise35/index.html:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 | Advanced JavaScript - Lesson 3 - Exercise 35
5 |
6 |
7 |
8 | Load
9 | Save
10 |
51 |
52 |
53 |
--------------------------------------------------------------------------------
/exercises/Exercise Numbering:
--------------------------------------------------------------------------------
1 | **Lesson One - Introducing ECMAScript 6**
2 |
3 | Exercise 1: Implementing Block Scope
4 | Exercise 2- Declaring Variables
5 | Exercise 3- Converting Arrow Functions
6 | Exercise 4- Upgrading Arrow Functions
7 | Exercise 5- Converting to Template Literals
8 | Exercise 6: Template Literal Conversion
9 | Exercise 7:Implementing Enhanced Object Properties
10 | Exercise 8- Array Destructuring
11 | Exercise 9- Object Destructuring
12 | Exercise 10- Nested Destructuring
13 | Exercise 11- Implementing Destructuring
14 | Exercise 12- Creating Your Own Class
15 | Exercise 13: Implementing Classes
16 | Exercise 14: Transpiling ES6 Code
17 | Exercise 15- Creating a Generator
18 | Activity 1: Implementing Generators
19 |
20 | **Lesson Two - Asynchronous JavaScript**
21 |
22 | Exercise 16: Handling Asynchronous Code
23 | Exercise 17: Analyzing The JavaScript Event Loop
24 | Exercise 18: Working with Callbacks
25 | Exercise 19: Creating and resolving Your First Promise
26 | Exercise 20: Working With Promises
27 | Activity 2: Using Async/Await
28 |
29 | **Lesson Three -DOM Manipulation and Event Handling**
30 |
31 | Exercise 21: Building the HTML code for an Image
32 | Exercise 22: DOM Manipulation
33 | Exercise 23: Handling Your First Event
34 | Exercise 24: Handling and Delegating Events
35 | Activity 3: Implementing jQuery
36 |
37 | **Lesson Four -Testing JavaScript**
38 |
39 | Exercise 25: Applying Test Driven Development
40 | Exercise 26: Building Unit Tests
41 | Exercise 27: Writing Tests
42 | Exercise 28: Setting Up Mocha
43 | Activity 4: Utilizing Test Environments
44 |
45 | **Lesson Five - Functional Programming**
46 |
47 | Exercise 27: Building Imperative and Declarative Functions
48 | Exercise 28: Building Pure Controllers
49 | Activity 5: Recursive Immutability
50 |
51 | **Lesson Six - JavaScript Ecosystem**
52 |
53 | Exercise 29: Exporting and Importing NPM Modules
54 | Exercise 30: Creating a Basic HTTP Server
55 | Exercise 31: Creating a Basic Express Server
56 | Exercise 32: Building a Backend With Node.js
57 | Activity 6: Building a Frontend with React
58 |
--------------------------------------------------------------------------------
/exercises/exercise16/index.js:
--------------------------------------------------------------------------------
1 | 'use strict';
2 |
3 | function f1() { console.log( 'f1' ); }
4 |
5 | function f2() { console.log( 'f2' ); }
6 |
7 | function f3() {
8 | console.log( 'f3' );
9 | setTimeout( f5, 90 )
10 | }
11 |
12 | function f4() { console.log( 'f4' ); }
13 |
14 | function f5() { console.log( 'f5' ); }
15 |
16 | setTimeout( f1, 105 );
17 | setTimeout( f2, 15 );
18 | setTimeout( f3, 10 );
19 | setTimeout( f4, 100 );
20 |
21 | /* Expected program output:
22 | f3
23 | f2
24 | f4
25 | f5
26 | f1
27 | */
28 |
29 | /*
30 |
31 | Expected stack, queue, and heap output
32 |
33 | step 0
34 | stack:
35 | queue:
36 | heap:
37 |
38 | step 1
39 | stack: , setTimeout( f1, 105 );
40 | queue:
41 | heap:
42 |
43 | step 2
44 | stack: , setTimeout( f2, 15 );
45 | queue:
46 | heap: setTimeout( f1, 105 )
47 |
48 | step 3
49 | stack: , setTimeout( f3, 10 );
50 | queue:
51 | heap: setTimeout( f1, 105 ), setTimeout( f2, 15 )
52 |
53 | step 4
54 | stack: , setTimeout( f4, 100 );
55 | queue:
56 | heap: setTimeout( f1, 105 ), setTimeout( f2, 15 ), setTimeout( f3, 10 )
57 |
58 | step 5
59 | stack:
60 | queue: { event: timeout, handler: f3 }
61 | heap: setTimeout( f1, 105 ), setTimeout( f2, 15 ), setTimeout( f4, 100 )
62 |
63 | step 6
64 | stack: , f3
65 | queue:
66 | heap: setTimeout( f1, 105 ), setTimeout( f2, 15 ), setTimeout( f4, 100 )
67 |
68 | step 7
69 | stack: , f3, console.log( 'f3' )
70 | queue:
71 | heap: setTimeout( f1, 105 ), setTimeout( f2, 15 ), setTimeout( f4, 100 )
72 |
73 | step 8
74 | stack: , f3, setTimeout( f5, 90)
75 | queue:
76 | heap: setTimeout( f1, 105 ), setTimeout( f2, 15 ), setTimeout( f4, 100 )
77 |
78 | step 9
79 | stack: , f3
80 | queue:
81 | heap: setTimeout( f1, 105 ), setTimeout( f2, 15 ), setTimeout( f4, 100 ), setTimeout( f5, 90)
82 |
83 | */
84 |
85 | /* Hints
86 | - Order the timeouts in order of event fire delay
87 | - Two timeouts (f4 & f5) expire at the same ms offset, consider which event gets handled first (f4)?
88 | */
--------------------------------------------------------------------------------
/activities/activity6/activity/lib/index.js:
--------------------------------------------------------------------------------
1 | var _createClass = function () { function defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } } return function (Constructor, protoProps, staticProps) { if (protoProps) defineProperties(Constructor.prototype, protoProps); if (staticProps) defineProperties(Constructor, staticProps); return Constructor; }; }();
2 |
3 | function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
4 |
5 | function _possibleConstructorReturn(self, call) { if (!self) { throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); } return call && (typeof call === "object" || typeof call === "function") ? call : self; }
6 |
7 | function _inherits(subClass, superClass) { if (typeof superClass !== "function" && superClass !== null) { throw new TypeError("Super expression must either be null or a function, not " + typeof superClass); } subClass.prototype = Object.create(superClass && superClass.prototype, { constructor: { value: subClass, enumerable: false, writable: true, configurable: true } }); if (superClass) Object.setPrototypeOf ? Object.setPrototypeOf(subClass, superClass) : subClass.__proto__ = superClass; }
8 |
9 | /*BUILD REACT FRONT END HERE*/
10 |
11 | var App = function (_React$Component) {
12 | _inherits(App, _React$Component);
13 |
14 | function App(props) {
15 | _classCallCheck(this, App);
16 |
17 | return _possibleConstructorReturn(this, (App.__proto__ || Object.getPrototypeOf(App)).call(this, props));
18 | }
19 |
20 | _createClass(App, [{
21 | key: 'render',
22 | value: function render() {
23 | return React.createElement(
24 | 'div',
25 | null,
26 | 'BUILD APP VIEW HERE'
27 | );
28 | }
29 | }]);
30 |
31 | return App;
32 | }(React.Component);
33 |
34 | ReactDOM.render(React.createElement(App, null), document.getElementById('root'));
--------------------------------------------------------------------------------
/activities/activity5/activity-solution.js:
--------------------------------------------------------------------------------
1 | 'use strict';
2 |
3 | // Activity F
4 | // Scenario: Your research team has obtained a list of value from your latest experiment however due to a calibration error only some of the data can be used and any data that can be used needs to be scaled. You must to build a utility function that takes in an array, filters out any values less than or equal to 0, scales the remaining values by multiplying them by 2, and returns the final results. First build an imperative function to do this, then build a declarative function to do the same thing.
5 |
6 | function immutable( data ) {
7 | if ( typeof data !== 'object' ) {
8 | return;
9 | }
10 | Object.freeze( data );
11 | Object.values( data ).forEach( immutable );
12 | }
13 |
14 | // Test code. If there are errors then the immutable function does not work as intended
15 | const obj = { a: 10, b: 15, obj: { c: 20 }, arr: [ 1, 5, 10, { test: 'value' } ] };
16 |
17 | const arr = [ 1, 5, [ 5, 6 ], { obj: true } ];
18 |
19 | immutable( obj );
20 | test_try_catch('add property at main object', ()=>{obj.test='test'} );
21 | test_try_catch('add property at nested object', ()=>{obj.obj.test='test'} );
22 | test_try_catch('add property at nested array', ()=>{obj.arr.push('test')} );
23 | test_try_catch('add property at nested array object element', ()=>{obj.arr[3].test='test'} );
24 |
25 | immutable( arr );
26 | test_try_catch('add element', ()=>{arr.push('test')} );
27 | test_try_catch('add element at nested array', ()=>{arr[2].push('test')} );
28 | test_try_catch('edit at nested object', ()=>{arr[3].test='test'} );
29 |
30 | console.log('Passed Tests!');
31 |
32 | function test_try_catch( test, _protected ) {
33 | let success = true;
34 | try {_protected();}
35 | catch ( e ) {success = false;}
36 | if ( success ) {
37 | throw new Error( `Failed test: ${test}` );
38 | }
39 | }
40 |
41 | /* Hints:
42 | - Create a function called immutable that takes in a single argument, data
43 | - If the type of data is not an object then return
44 | -- Use typeof !== 'object'
45 | -- No need to freeze non objects
46 | - Freeze the data object
47 | - Loop through object values and recursively call the immutable function for each
48 |
49 | */
50 |
--------------------------------------------------------------------------------
/README.md:
--------------------------------------------------------------------------------
1 | [](https://github.com/TrainingByPackt/Advanced-JavaScript/issues)
2 | [](https://github.com/TrainingByPackt/Advanced-JavaScript/network)
3 | [](https://github.com/TrainingByPackt/Advanced-JavaScript/stargazers)
4 | [](https://github.com/TrainingByPackt/Advanced-JavaScript/pulls)
5 |
6 | # Advanced JavaScript
7 | In this course, you will gain a deep understanding of JavaScript. You will learn how to write JavaScript in a professional environment using the new JavaScript syntax in ES6, leverage on JavaScript's asynchronous nature using callbacks and promises, and understand how to set up test suites and test your code. You will be introduced to JavaScript's functional programming style and you will apply everything learned to build a simple application in various JavaScript frameworks and libraries for backend and frontend development.
8 |
9 | Advanced JavaScript by **Zachary Shute**
10 |
11 | ## What you will learn
12 | * Examine major features in ES6 and implement those features to build applications
13 | * Create promise and callback handlers to work with asynchronous processes
14 | * Develop asynchronous flows using Promise chaining and async/await syntax
15 | * Manipulate the DOM with JavaScript
16 | * Handle JavaScript browser events
17 | * Explore Test Driven Development and build code tests with JavaScript code testing frameworks.
18 | * List the benefits and drawbacks of functional programming compared to other styles
19 | * Construct applications with the Node.js backend framework and the React frontend framework
20 |
21 |
22 |
23 | ### Hardware Requirements
24 | For an optimal student experience, we recommend the following hardware configuration:
25 | * **Processor**: Intel Core i5 or equivalent
26 | * **Memory**: 4GB RAM
27 | * **Storage**: 35GB available space
28 |
29 | ### Software Requirements
30 | You'll also need the following software installed in advance:
31 | * **OS**: Windows 7 SP1 64-bit, Windows 8.1 64-bit or Windows 10 64-bit
32 | * **Browser**: Google Chrome, Latest Version
33 | * **Atom IDE**
34 | * **Babel**
35 | * **Node.js and npm**
36 |
--------------------------------------------------------------------------------
/activities/activity2/index.js:
--------------------------------------------------------------------------------
1 | 'use strict';
2 |
3 | /* Assignment:
4 |
5 | You have been tasked to build a server that interfaces with a database. You must write code to look up set and look up basic user objects in the database. Import the simple_db.js file. Using the get and insert commands, write the following program using async/await syntax.
6 |
7 | 1) Look up the key 'john'. If it exists, log the age field of the result object.
8 | 2) Look up the key 'sam'. If it exists, log the age field of the result object.
9 | 3) Look up your first name as a database key. If it does not exist, insert your first name. Associate an object containing your first name, last name, and age. Look up the new data association and log the age.
10 |
11 | For any db.get operation that fails, save the key into an array. At the end of the program, print the keys that failed.
12 |
13 | DB API:
14 |
15 | db.get( index )
16 | Takes in an index. Returns a promise. Promise is fulfilled with the db entry associated with that index. If index does not exist, the lookup fails, or key is not specified, The promise is rejected with an error.
17 |
18 | db.insert( index, insertData )
19 | Takes in an index and a data. Returns a promise. Promise is fulfilled with the key inserted if the operation completes. If the operation fails, or there is no key or insert data specified, the promise is rejected with an error.
20 |
21 | */
22 |
23 | const db = require( './simple_db' );
24 |
25 | async function main() {
26 |
27 | const missingKeys = [];
28 |
29 | try {
30 | const user = await db.get( 'john' );
31 | console.log( user.age );
32 | } catch ( err ) {
33 | missingKeys.push( 'john' );
34 | }
35 |
36 | try {
37 | const user = await db.get( 'sam' );
38 | console.log( user.age );
39 | } catch ( err ) {
40 | missingKeys.push( 'sam' );
41 | }
42 |
43 | try {
44 | const user = await db.get( 'zach' );
45 | console.log( user.age );
46 | } catch ( err ) {
47 | missingKeys.push( 'zach' );
48 | await db.insert( 'zach', { first: 'zach', last: 'smith', age: 25 } );
49 | try {
50 | const user = await db.get( 'zach' );
51 | console.log( user.age )
52 | } catch ( err ) {
53 | missingKeys.push( 'zach' );
54 | }
55 | }
56 |
57 | return missingKeys;
58 |
59 | }
60 |
61 | main().then( console.log ).catch( ( err ) => console.log( `Error: ${err}` ) );
62 |
63 | /* Expected output;
64 |
65 | 43
66 |
67 | [ 'sam', f ]
68 |
69 | */
70 |
71 | /* Hits:
72 | - Create an async main function so you can await your db calls
73 | - When you call main, you have to attach a .then and .catch handler to catch runtime errors and the return value
74 | - Await the db calls
75 | - either Use try/catch to handle the errors or use promise.catch()
76 | */
--------------------------------------------------------------------------------
/exercises/exercise21/solution.html:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 | Advanced JavaScript - Lesson 3 - Exercise 21
5 |
39 |
40 |
41 |
42 |
83 |
84 |
85 |
--------------------------------------------------------------------------------
/activities/activity6/solution/src/index.js:
--------------------------------------------------------------------------------
1 | /*
2 | Scenario: The Front End team working on your note taking app from Activity B has unexpectedly quit. You must build the front end for this application using React. Your front end should have two views, a Home view and an Edit view. Create a react component for each view. The home view should have a button that changes the view to the edit view. The edit view should have a button that switches back to the home view, a text input that contains the note text, a load button that calls the API load route, and a save button that calls the API save route. A NodeJS server has been provided to you. Write your React code in 'Lesson 6/topic c/activity/src/index.js.' When you are ready to test your code run the build script (defined in package.json) before starting the server. You can reference the index.html file from Activity B for hints on how to call the API routes.
3 | */
4 |
5 | class Home extends React.Component {
6 | goEdit() {
7 | this.props.changeView( 'editor' )
8 | }
9 |
10 | render() {
11 | return (
12 |
13 |
Note Editor App
14 | Edit Note
15 |
16 | );
17 | }
18 | }
19 |
20 | class Editor extends React.Component {
21 | constructor( props ) {
22 | super( props );
23 | this.state = { value: '' };
24 | }
25 |
26 | handleChange( e ) {
27 | this.setState( { value: e.target.value } );
28 | }
29 |
30 | save() {
31 | const xhttp = new XMLHttpRequest();
32 | xhttp.onreadystatechange = function () {
33 | if ( this.readyState != 4 ) {
34 | return
35 | }
36 | if ( this.status !== 200 ) {
37 | return console.error( 'Failed to save note!' );
38 | }
39 | };
40 |
41 | xhttp.open( "POST", "/save", true );
42 | xhttp.setRequestHeader( 'Content-Type', 'application/json;charset=UTF-8' );
43 | xhttp.send( JSON.stringify( this.state.value ) );
44 | }
45 |
46 | load() {
47 | const xhttp = new XMLHttpRequest();
48 | const that = this;
49 |
50 | xhttp.onreadystatechange = function () {
51 | if ( this.readyState != 4 ) {
52 | return
53 | }
54 | if ( this.status !== 200 ) {
55 | return console.error( 'Failed to load note!' );
56 | }
57 | that.setState( { value: JSON.parse( this.response ) } );
58 | };
59 |
60 | xhttp.open( "GET", "/load", true );
61 | xhttp.send();
62 | }
63 |
64 | goHome() {
65 | this.props.changeView( 'home' );
66 | }
67 |
68 | render() {
69 | return (
70 |
71 | Back to home
72 |
73 | Load
74 | Save
75 |
76 | );
77 | }
78 | }
79 |
80 | class App extends React.Component {
81 | constructor( props ) {
82 | super( props );
83 | this.state = { view: 'home' };
84 | this.changeView = this.changeView.bind( this );
85 | }
86 |
87 | changeView( view ) {
88 | this.setState( { view } )
89 | }
90 |
91 | render() {
92 | return {this.state.view === 'home' ? :
93 | }
;
94 | }
95 | }
96 |
97 | ReactDOM.render(
98 | ,
99 | document.getElementById( 'root' )
100 | );
101 |
102 | /* Hints
103 | -Run `npm install` to install the required dependencies
104 | -Create a Home and Editor component
105 | -Add a constructor to the App class
106 | --Set the state object to have a view property
107 | ---Default the view to 'home'
108 | -Add a changeView method to the app
109 | --The changeView method should take in a value and set state.view to that value with this.setState()
110 | -In App's render function create a conditional rendering based on the value of this.state.view that either displays the Home component or the Editor component
111 | --If state.view is equal to home, show the home view. Otherwise show the editor view
112 | --Pass the changeView function as a parameter to both views
113 | ----
114 | -In the Home component add a goEdit() function that calls the changeView function passed in through props. Have it set the view to 'editor'
115 | --this.props.changeView( 'editor' )
116 | -Create the render function in Home
117 | --Add a title heading or div that contains the title of the app
118 | --Add a button that changes the view to the edit view
119 | ---Calls the goEdit function on click
120 | ---Be sure to properly bind the this state
121 | -Add a constructor to the Editor component
122 | --In the constructor set the state that contains the value of the text input
123 | -Add an input change handler to Editor
124 | --Set state.value with the event value
125 | --this.setState( { value: e.target.value } );
126 | -Create a save function in Editor that calls the API save note route
127 | --Create an XHR request that does a JSON post request to '/save'
128 | --Send the value of the text input from the state variable
129 | --Refer to the Topic B index.html file for implementation details
130 | -Create a load function in Editor that calls the API load note route
131 | --Create an XHR request that does a GET request to '/load'
132 | --Save the returned text value into this.state.value
133 | --Refer to the Topic B index.html file for implementation details
134 | --You will have to save the component this scope into a variable in the load function so that it can be referenced from inside the XHR state change handler
135 | -Create the render function in Editor
136 | --Add a button that changes the state to the home view
137 | ---Calls the goHome function on the click event
138 | --Add a Text field that contains the note value
139 | ---Text field loads it's value from the state.value field
140 | ---Text field calls the handleChange function on a value change
141 | --Add a button to load the note data from the server
142 | ---Calls the load function on the click event
143 | --Add a button to save the note data to the server
144 | ---Calls the save function on the click event
145 | --Be sure to bind the this state properly to all listeners
146 | -When ready to test the code
147 | --Run `npm run build` in the root project folder to transpile the code from JSX
148 | --Run `npm start` to start the server
149 |
150 | */
151 |
--------------------------------------------------------------------------------
/activities/activity6/solution/lib/index.js:
--------------------------------------------------------------------------------
1 | var _createClass = function () { function defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } } return function (Constructor, protoProps, staticProps) { if (protoProps) defineProperties(Constructor.prototype, protoProps); if (staticProps) defineProperties(Constructor, staticProps); return Constructor; }; }();
2 |
3 | function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
4 |
5 | function _possibleConstructorReturn(self, call) { if (!self) { throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); } return call && (typeof call === "object" || typeof call === "function") ? call : self; }
6 |
7 | function _inherits(subClass, superClass) { if (typeof superClass !== "function" && superClass !== null) { throw new TypeError("Super expression must either be null or a function, not " + typeof superClass); } subClass.prototype = Object.create(superClass && superClass.prototype, { constructor: { value: subClass, enumerable: false, writable: true, configurable: true } }); if (superClass) Object.setPrototypeOf ? Object.setPrototypeOf(subClass, superClass) : subClass.__proto__ = superClass; }
8 |
9 | /*
10 | Scenario: The Front End team working on your note taking app from Activity B has unexpectedly quit. You must build the front end for this application using React. Your front end should have two views, a Home view and an Edit view. Create a react component for each view. The home view should have a button that changes the view to the edit view. The edit view should have a button that switches back to the home view, a text input that contains the note text, a load button that calls the API load route, and a save button that calls the API save route. A NodeJS server has been provided to you. Write your React code in 'Lesson 6/topic c/activity/src/index.js.' When you are ready to test your code run the build script (defined in package.json) before starting the server. You can reference the index.html file from Activity B for hints on how to call the API routes.
11 | */
12 |
13 | var Home = function (_React$Component) {
14 | _inherits(Home, _React$Component);
15 |
16 | function Home() {
17 | _classCallCheck(this, Home);
18 |
19 | return _possibleConstructorReturn(this, (Home.__proto__ || Object.getPrototypeOf(Home)).apply(this, arguments));
20 | }
21 |
22 | _createClass(Home, [{
23 | key: 'goEdit',
24 | value: function goEdit() {
25 | this.props.changeView('editor');
26 | }
27 | }, {
28 | key: 'render',
29 | value: function render() {
30 | return React.createElement(
31 | 'div',
32 | null,
33 | React.createElement(
34 | 'h1',
35 | null,
36 | 'Note Editor App'
37 | ),
38 | React.createElement(
39 | 'button',
40 | { type: 'button', onClick: this.goEdit.bind(this) },
41 | 'Edit Note'
42 | )
43 | );
44 | }
45 | }]);
46 |
47 | return Home;
48 | }(React.Component);
49 |
50 | var Editor = function (_React$Component2) {
51 | _inherits(Editor, _React$Component2);
52 |
53 | function Editor(props) {
54 | _classCallCheck(this, Editor);
55 |
56 | var _this2 = _possibleConstructorReturn(this, (Editor.__proto__ || Object.getPrototypeOf(Editor)).call(this, props));
57 |
58 | _this2.state = { value: '' };
59 | return _this2;
60 | }
61 |
62 | _createClass(Editor, [{
63 | key: 'handleChange',
64 | value: function handleChange(e) {
65 | this.setState({ value: e.target.value });
66 | }
67 | }, {
68 | key: 'save',
69 | value: function save() {
70 | var xhttp = new XMLHttpRequest();
71 | xhttp.onreadystatechange = function () {
72 | if (this.readyState != 4) {
73 | return;
74 | }
75 | if (this.status !== 200) {
76 | return console.error('Failed to save note!');
77 | }
78 | };
79 |
80 | xhttp.open("POST", "/save", true);
81 | xhttp.setRequestHeader('Content-Type', 'application/json;charset=UTF-8');
82 | xhttp.send(JSON.stringify(this.state.value));
83 | }
84 | }, {
85 | key: 'load',
86 | value: function load() {
87 | var xhttp = new XMLHttpRequest();
88 | var that = this;
89 |
90 | xhttp.onreadystatechange = function () {
91 | if (this.readyState != 4) {
92 | return;
93 | }
94 | if (this.status !== 200) {
95 | return console.error('Failed to load note!');
96 | }
97 | that.setState({ value: JSON.parse(this.response) });
98 | };
99 |
100 | xhttp.open("GET", "/load", true);
101 | xhttp.send();
102 | }
103 | }, {
104 | key: 'goHome',
105 | value: function goHome() {
106 | this.props.changeView('home');
107 | }
108 | }, {
109 | key: 'render',
110 | value: function render() {
111 | return React.createElement(
112 | 'div',
113 | null,
114 | React.createElement(
115 | 'button',
116 | { type: 'button', onClick: this.goHome.bind(this) },
117 | 'Back to home'
118 | ),
119 | React.createElement('input', { type: 'text', name: 'note text', value: this.state.value, onChange: this.handleChange.bind(this) }),
120 | React.createElement(
121 | 'button',
122 | { type: 'button', onClick: this.load.bind(this) },
123 | 'Load'
124 | ),
125 | React.createElement(
126 | 'button',
127 | { type: 'button', onClick: this.save.bind(this) },
128 | 'Save'
129 | )
130 | );
131 | }
132 | }]);
133 |
134 | return Editor;
135 | }(React.Component);
136 |
137 | var App = function (_React$Component3) {
138 | _inherits(App, _React$Component3);
139 |
140 | function App(props) {
141 | _classCallCheck(this, App);
142 |
143 | var _this3 = _possibleConstructorReturn(this, (App.__proto__ || Object.getPrototypeOf(App)).call(this, props));
144 |
145 | _this3.state = { view: 'home' };
146 | _this3.changeView = _this3.changeView.bind(_this3);
147 | return _this3;
148 | }
149 |
150 | _createClass(App, [{
151 | key: 'changeView',
152 | value: function changeView(view) {
153 | this.setState({ view: view });
154 | }
155 | }, {
156 | key: 'render',
157 | value: function render() {
158 | return React.createElement(
159 | 'div',
160 | null,
161 | this.state.view === 'home' ? React.createElement(Home, { changeView: this.changeView }) : React.createElement(Editor, { changeView: this.changeView })
162 | );
163 | }
164 | }]);
165 |
166 | return App;
167 | }(React.Component);
168 |
169 | ReactDOM.render(React.createElement(App, null), document.getElementById('root'));
170 |
171 | /* Hints
172 | -Run `npm install` to install the required dependencies
173 | -Create a Home and Editor component
174 | -Add a constructor to the App class
175 | --Set the state object to have a view property
176 | ---Default the view to 'home'
177 | -Add a changeView method to the app
178 | --The changeView method should take in a value and set state.view to that value with this.setState()
179 | -In App's render function create a conditional rendering based on the value of this.state.view that either displays the Home component or the Editor component
180 | --If state.view is equal to home, show the home view. Otherwise show the editor view
181 | --Pass the changeView function as a parameter to both views
182 | ----
183 | -In the Home component add a goEdit() function that calls the changeView function passed in through props. Have it set the view to 'editor'
184 | --this.props.changeView( 'editor' )
185 | -Create the render function in Home
186 | --Add a title heading or div that contains the title of the app
187 | --Add a button that changes the view to the edit view
188 | ---Calls the goEdit function on click
189 | ---Be sure to properly bind the this state
190 | -Add a constructor to the Editor component
191 | --In the constructor set the state that contains the value of the text input
192 | -Add an input change handler to Editor
193 | --Set state.value with the event value
194 | --this.setState( { value: e.target.value } );
195 | -Create a save function in Editor that calls the API save note route
196 | --Create an XHR request that does a JSON post request to '/save'
197 | --Send the value of the text input from the state variable
198 | --Refer to the Topic B index.html file for implementation details
199 | -Create a load function in Editor that calls the API load note route
200 | --Create an XHR request that does a GET request to '/load'
201 | --Save the returned text value into this.state.value
202 | --Refer to the Topic B index.html file for implementation details
203 | --You will have to save the component this scope into a variable in the load function so that it can be referenced from inside the XHR state change handler
204 | -Create the render function in Editor
205 | --Add a button that changes the state to the home view
206 | ---Calls the goHome function on the click event
207 | --Add a Text field that contains the note value
208 | ---Text field loads it's value from the state.value field
209 | ---Text field calls the handleChange function on a value change
210 | --Add a button to load the note data from the server
211 | ---Calls the load function on the click event
212 | --Add a button to save the note data to the server
213 | ---Calls the save function on the click event
214 | --Be sure to bind the this state properly to all listeners
215 | -When ready to test the code
216 | --Run `npm run build` in the root project folder to transpile the code from JSX
217 | --Run `npm start` to start the server
218 |
219 | */
--------------------------------------------------------------------------------
/exercises/exercise35/package-lock.json:
--------------------------------------------------------------------------------
1 | {
2 | "name": "exercise-35-nodejs-server",
3 | "version": "1.0.0",
4 | "lockfileVersion": 1,
5 | "requires": true,
6 | "dependencies": {
7 | "accepts": {
8 | "version": "1.3.5",
9 | "resolved": "https://registry.npmjs.org/accepts/-/accepts-1.3.5.tgz",
10 | "integrity": "sha1-63d99gEXI6OxTopywIBcjoZ0a9I=",
11 | "requires": {
12 | "mime-types": "~2.1.18",
13 | "negotiator": "0.6.1"
14 | }
15 | },
16 | "array-flatten": {
17 | "version": "1.1.1",
18 | "resolved": "https://registry.npmjs.org/array-flatten/-/array-flatten-1.1.1.tgz",
19 | "integrity": "sha1-ml9pkFGx5wczKPKgCJaLZOopVdI="
20 | },
21 | "body-parser": {
22 | "version": "1.18.3",
23 | "resolved": "https://registry.npmjs.org/body-parser/-/body-parser-1.18.3.tgz",
24 | "integrity": "sha1-WykhmP/dVTs6DyDe0FkrlWlVyLQ=",
25 | "requires": {
26 | "bytes": "3.0.0",
27 | "content-type": "~1.0.4",
28 | "debug": "2.6.9",
29 | "depd": "~1.1.2",
30 | "http-errors": "~1.6.3",
31 | "iconv-lite": "0.4.23",
32 | "on-finished": "~2.3.0",
33 | "qs": "6.5.2",
34 | "raw-body": "2.3.3",
35 | "type-is": "~1.6.16"
36 | }
37 | },
38 | "bytes": {
39 | "version": "3.0.0",
40 | "resolved": "https://registry.npmjs.org/bytes/-/bytes-3.0.0.tgz",
41 | "integrity": "sha1-0ygVQE1olpn4Wk6k+odV3ROpYEg="
42 | },
43 | "content-disposition": {
44 | "version": "0.5.2",
45 | "resolved": "https://registry.npmjs.org/content-disposition/-/content-disposition-0.5.2.tgz",
46 | "integrity": "sha1-DPaLud318r55YcOoUXjLhdunjLQ="
47 | },
48 | "content-type": {
49 | "version": "1.0.4",
50 | "resolved": "https://registry.npmjs.org/content-type/-/content-type-1.0.4.tgz",
51 | "integrity": "sha512-hIP3EEPs8tB9AT1L+NUqtwOAps4mk2Zob89MWXMHjHWg9milF/j4osnnQLXBCBFBk/tvIG/tUc9mOUJiPBhPXA=="
52 | },
53 | "cookie": {
54 | "version": "0.3.1",
55 | "resolved": "https://registry.npmjs.org/cookie/-/cookie-0.3.1.tgz",
56 | "integrity": "sha1-5+Ch+e9DtMi6klxcWpboBtFoc7s="
57 | },
58 | "cookie-signature": {
59 | "version": "1.0.6",
60 | "resolved": "https://registry.npmjs.org/cookie-signature/-/cookie-signature-1.0.6.tgz",
61 | "integrity": "sha1-4wOogrNCzD7oylE6eZmXNNqzriw="
62 | },
63 | "debug": {
64 | "version": "2.6.9",
65 | "resolved": "https://registry.npmjs.org/debug/-/debug-2.6.9.tgz",
66 | "integrity": "sha512-bC7ElrdJaJnPbAP+1EotYvqZsb3ecl5wi6Bfi6BJTUcNowp6cvspg0jXznRTKDjm/E7AdgFBVeAPVMNcKGsHMA==",
67 | "requires": {
68 | "ms": "2.0.0"
69 | }
70 | },
71 | "depd": {
72 | "version": "1.1.2",
73 | "resolved": "https://registry.npmjs.org/depd/-/depd-1.1.2.tgz",
74 | "integrity": "sha1-m81S4UwJd2PnSbJ0xDRu0uVgtak="
75 | },
76 | "destroy": {
77 | "version": "1.0.4",
78 | "resolved": "https://registry.npmjs.org/destroy/-/destroy-1.0.4.tgz",
79 | "integrity": "sha1-l4hXRCxEdJ5CBmE+N5RiBYJqvYA="
80 | },
81 | "ee-first": {
82 | "version": "1.1.1",
83 | "resolved": "https://registry.npmjs.org/ee-first/-/ee-first-1.1.1.tgz",
84 | "integrity": "sha1-WQxhFWsK4vTwJVcyoViyZrxWsh0="
85 | },
86 | "encodeurl": {
87 | "version": "1.0.2",
88 | "resolved": "https://registry.npmjs.org/encodeurl/-/encodeurl-1.0.2.tgz",
89 | "integrity": "sha1-rT/0yG7C0CkyL1oCw6mmBslbP1k="
90 | },
91 | "escape-html": {
92 | "version": "1.0.3",
93 | "resolved": "https://registry.npmjs.org/escape-html/-/escape-html-1.0.3.tgz",
94 | "integrity": "sha1-Aljq5NPQwJdN4cFpGI7wBR0dGYg="
95 | },
96 | "etag": {
97 | "version": "1.8.1",
98 | "resolved": "https://registry.npmjs.org/etag/-/etag-1.8.1.tgz",
99 | "integrity": "sha1-Qa4u62XvpiJorr/qg6x9eSmbCIc="
100 | },
101 | "express": {
102 | "version": "4.16.4",
103 | "resolved": "https://registry.npmjs.org/express/-/express-4.16.4.tgz",
104 | "integrity": "sha512-j12Uuyb4FMrd/qQAm6uCHAkPtO8FDTRJZBDd5D2KOL2eLaz1yUNdUB/NOIyq0iU4q4cFarsUCrnFDPBcnksuOg==",
105 | "requires": {
106 | "accepts": "~1.3.5",
107 | "array-flatten": "1.1.1",
108 | "body-parser": "1.18.3",
109 | "content-disposition": "0.5.2",
110 | "content-type": "~1.0.4",
111 | "cookie": "0.3.1",
112 | "cookie-signature": "1.0.6",
113 | "debug": "2.6.9",
114 | "depd": "~1.1.2",
115 | "encodeurl": "~1.0.2",
116 | "escape-html": "~1.0.3",
117 | "etag": "~1.8.1",
118 | "finalhandler": "1.1.1",
119 | "fresh": "0.5.2",
120 | "merge-descriptors": "1.0.1",
121 | "methods": "~1.1.2",
122 | "on-finished": "~2.3.0",
123 | "parseurl": "~1.3.2",
124 | "path-to-regexp": "0.1.7",
125 | "proxy-addr": "~2.0.4",
126 | "qs": "6.5.2",
127 | "range-parser": "~1.2.0",
128 | "safe-buffer": "5.1.2",
129 | "send": "0.16.2",
130 | "serve-static": "1.13.2",
131 | "setprototypeof": "1.1.0",
132 | "statuses": "~1.4.0",
133 | "type-is": "~1.6.16",
134 | "utils-merge": "1.0.1",
135 | "vary": "~1.1.2"
136 | }
137 | },
138 | "finalhandler": {
139 | "version": "1.1.1",
140 | "resolved": "http://registry.npmjs.org/finalhandler/-/finalhandler-1.1.1.tgz",
141 | "integrity": "sha512-Y1GUDo39ez4aHAw7MysnUD5JzYX+WaIj8I57kO3aEPT1fFRL4sr7mjei97FgnwhAyyzRYmQZaTHb2+9uZ1dPtg==",
142 | "requires": {
143 | "debug": "2.6.9",
144 | "encodeurl": "~1.0.2",
145 | "escape-html": "~1.0.3",
146 | "on-finished": "~2.3.0",
147 | "parseurl": "~1.3.2",
148 | "statuses": "~1.4.0",
149 | "unpipe": "~1.0.0"
150 | }
151 | },
152 | "forwarded": {
153 | "version": "0.1.2",
154 | "resolved": "https://registry.npmjs.org/forwarded/-/forwarded-0.1.2.tgz",
155 | "integrity": "sha1-mMI9qxF1ZXuMBXPozszZGw/xjIQ="
156 | },
157 | "fresh": {
158 | "version": "0.5.2",
159 | "resolved": "https://registry.npmjs.org/fresh/-/fresh-0.5.2.tgz",
160 | "integrity": "sha1-PYyt2Q2XZWn6g1qx+OSyOhBWBac="
161 | },
162 | "http-errors": {
163 | "version": "1.6.3",
164 | "resolved": "http://registry.npmjs.org/http-errors/-/http-errors-1.6.3.tgz",
165 | "integrity": "sha1-i1VoC7S+KDoLW/TqLjhYC+HZMg0=",
166 | "requires": {
167 | "depd": "~1.1.2",
168 | "inherits": "2.0.3",
169 | "setprototypeof": "1.1.0",
170 | "statuses": ">= 1.4.0 < 2"
171 | }
172 | },
173 | "iconv-lite": {
174 | "version": "0.4.23",
175 | "resolved": "https://registry.npmjs.org/iconv-lite/-/iconv-lite-0.4.23.tgz",
176 | "integrity": "sha512-neyTUVFtahjf0mB3dZT77u+8O0QB89jFdnBkd5P1JgYPbPaia3gXXOVL2fq8VyU2gMMD7SaN7QukTB/pmXYvDA==",
177 | "requires": {
178 | "safer-buffer": ">= 2.1.2 < 3"
179 | }
180 | },
181 | "inherits": {
182 | "version": "2.0.3",
183 | "resolved": "https://registry.npmjs.org/inherits/-/inherits-2.0.3.tgz",
184 | "integrity": "sha1-Yzwsg+PaQqUC9SRmAiSA9CCCYd4="
185 | },
186 | "ipaddr.js": {
187 | "version": "1.8.0",
188 | "resolved": "https://registry.npmjs.org/ipaddr.js/-/ipaddr.js-1.8.0.tgz",
189 | "integrity": "sha1-6qM9bd16zo9/b+DJygRA5wZzix4="
190 | },
191 | "media-typer": {
192 | "version": "0.3.0",
193 | "resolved": "http://registry.npmjs.org/media-typer/-/media-typer-0.3.0.tgz",
194 | "integrity": "sha1-hxDXrwqmJvj/+hzgAWhUUmMlV0g="
195 | },
196 | "merge-descriptors": {
197 | "version": "1.0.1",
198 | "resolved": "https://registry.npmjs.org/merge-descriptors/-/merge-descriptors-1.0.1.tgz",
199 | "integrity": "sha1-sAqqVW3YtEVoFQ7J0blT8/kMu2E="
200 | },
201 | "methods": {
202 | "version": "1.1.2",
203 | "resolved": "https://registry.npmjs.org/methods/-/methods-1.1.2.tgz",
204 | "integrity": "sha1-VSmk1nZUE07cxSZmVoNbD4Ua/O4="
205 | },
206 | "mime": {
207 | "version": "1.4.1",
208 | "resolved": "https://registry.npmjs.org/mime/-/mime-1.4.1.tgz",
209 | "integrity": "sha512-KI1+qOZu5DcW6wayYHSzR/tXKCDC5Om4s1z2QJjDULzLcmf3DvzS7oluY4HCTrc+9FiKmWUgeNLg7W3uIQvxtQ=="
210 | },
211 | "mime-db": {
212 | "version": "1.37.0",
213 | "resolved": "https://registry.npmjs.org/mime-db/-/mime-db-1.37.0.tgz",
214 | "integrity": "sha512-R3C4db6bgQhlIhPU48fUtdVmKnflq+hRdad7IyKhtFj06VPNVdk2RhiYL3UjQIlso8L+YxAtFkobT0VK+S/ybg=="
215 | },
216 | "mime-types": {
217 | "version": "2.1.21",
218 | "resolved": "https://registry.npmjs.org/mime-types/-/mime-types-2.1.21.tgz",
219 | "integrity": "sha512-3iL6DbwpyLzjR3xHSFNFeb9Nz/M8WDkX33t1GFQnFOllWk8pOrh/LSrB5OXlnlW5P9LH73X6loW/eogc+F5lJg==",
220 | "requires": {
221 | "mime-db": "~1.37.0"
222 | }
223 | },
224 | "ms": {
225 | "version": "2.0.0",
226 | "resolved": "https://registry.npmjs.org/ms/-/ms-2.0.0.tgz",
227 | "integrity": "sha1-VgiurfwAvmwpAd9fmGF4jeDVl8g="
228 | },
229 | "negotiator": {
230 | "version": "0.6.1",
231 | "resolved": "https://registry.npmjs.org/negotiator/-/negotiator-0.6.1.tgz",
232 | "integrity": "sha1-KzJxhOiZIQEXeyhWP7XnECrNDKk="
233 | },
234 | "on-finished": {
235 | "version": "2.3.0",
236 | "resolved": "https://registry.npmjs.org/on-finished/-/on-finished-2.3.0.tgz",
237 | "integrity": "sha1-IPEzZIGwg811M3mSoWlxqi2QaUc=",
238 | "requires": {
239 | "ee-first": "1.1.1"
240 | }
241 | },
242 | "parseurl": {
243 | "version": "1.3.2",
244 | "resolved": "https://registry.npmjs.org/parseurl/-/parseurl-1.3.2.tgz",
245 | "integrity": "sha1-/CidTtiZMRlGDBViUyYs3I3mW/M="
246 | },
247 | "path-to-regexp": {
248 | "version": "0.1.7",
249 | "resolved": "https://registry.npmjs.org/path-to-regexp/-/path-to-regexp-0.1.7.tgz",
250 | "integrity": "sha1-32BBeABfUi8V60SQ5yR6G/qmf4w="
251 | },
252 | "proxy-addr": {
253 | "version": "2.0.4",
254 | "resolved": "https://registry.npmjs.org/proxy-addr/-/proxy-addr-2.0.4.tgz",
255 | "integrity": "sha512-5erio2h9jp5CHGwcybmxmVqHmnCBZeewlfJ0pex+UW7Qny7OOZXTtH56TGNyBizkgiOwhJtMKrVzDTeKcySZwA==",
256 | "requires": {
257 | "forwarded": "~0.1.2",
258 | "ipaddr.js": "1.8.0"
259 | }
260 | },
261 | "qs": {
262 | "version": "6.5.2",
263 | "resolved": "https://registry.npmjs.org/qs/-/qs-6.5.2.tgz",
264 | "integrity": "sha512-N5ZAX4/LxJmF+7wN74pUD6qAh9/wnvdQcjq9TZjevvXzSUo7bfmw91saqMjzGS2xq91/odN2dW/WOl7qQHNDGA=="
265 | },
266 | "range-parser": {
267 | "version": "1.2.0",
268 | "resolved": "https://registry.npmjs.org/range-parser/-/range-parser-1.2.0.tgz",
269 | "integrity": "sha1-9JvmtIeJTdxA3MlKMi9hEJLgDV4="
270 | },
271 | "raw-body": {
272 | "version": "2.3.3",
273 | "resolved": "https://registry.npmjs.org/raw-body/-/raw-body-2.3.3.tgz",
274 | "integrity": "sha512-9esiElv1BrZoI3rCDuOuKCBRbuApGGaDPQfjSflGxdy4oyzqghxu6klEkkVIvBje+FF0BX9coEv8KqW6X/7njw==",
275 | "requires": {
276 | "bytes": "3.0.0",
277 | "http-errors": "1.6.3",
278 | "iconv-lite": "0.4.23",
279 | "unpipe": "1.0.0"
280 | }
281 | },
282 | "safe-buffer": {
283 | "version": "5.1.2",
284 | "resolved": "https://registry.npmjs.org/safe-buffer/-/safe-buffer-5.1.2.tgz",
285 | "integrity": "sha512-Gd2UZBJDkXlY7GbJxfsE8/nvKkUEU1G38c1siN6QP6a9PT9MmHB8GnpscSmMJSoF8LOIrt8ud/wPtojys4G6+g=="
286 | },
287 | "safer-buffer": {
288 | "version": "2.1.2",
289 | "resolved": "https://registry.npmjs.org/safer-buffer/-/safer-buffer-2.1.2.tgz",
290 | "integrity": "sha512-YZo3K82SD7Riyi0E1EQPojLz7kpepnSQI9IyPbHHg1XXXevb5dJI7tpyN2ADxGcQbHG7vcyRHk0cbwqcQriUtg=="
291 | },
292 | "send": {
293 | "version": "0.16.2",
294 | "resolved": "https://registry.npmjs.org/send/-/send-0.16.2.tgz",
295 | "integrity": "sha512-E64YFPUssFHEFBvpbbjr44NCLtI1AohxQ8ZSiJjQLskAdKuriYEP6VyGEsRDH8ScozGpkaX1BGvhanqCwkcEZw==",
296 | "requires": {
297 | "debug": "2.6.9",
298 | "depd": "~1.1.2",
299 | "destroy": "~1.0.4",
300 | "encodeurl": "~1.0.2",
301 | "escape-html": "~1.0.3",
302 | "etag": "~1.8.1",
303 | "fresh": "0.5.2",
304 | "http-errors": "~1.6.2",
305 | "mime": "1.4.1",
306 | "ms": "2.0.0",
307 | "on-finished": "~2.3.0",
308 | "range-parser": "~1.2.0",
309 | "statuses": "~1.4.0"
310 | }
311 | },
312 | "serve-static": {
313 | "version": "1.13.2",
314 | "resolved": "https://registry.npmjs.org/serve-static/-/serve-static-1.13.2.tgz",
315 | "integrity": "sha512-p/tdJrO4U387R9oMjb1oj7qSMaMfmOyd4j9hOFoxZe2baQszgHcSWjuya/CiT5kgZZKRudHNOA0pYXOl8rQ5nw==",
316 | "requires": {
317 | "encodeurl": "~1.0.2",
318 | "escape-html": "~1.0.3",
319 | "parseurl": "~1.3.2",
320 | "send": "0.16.2"
321 | }
322 | },
323 | "setprototypeof": {
324 | "version": "1.1.0",
325 | "resolved": "https://registry.npmjs.org/setprototypeof/-/setprototypeof-1.1.0.tgz",
326 | "integrity": "sha512-BvE/TwpZX4FXExxOxZyRGQQv651MSwmWKZGqvmPcRIjDqWub67kTKuIMx43cZZrS/cBBzwBcNDWoFxt2XEFIpQ=="
327 | },
328 | "statuses": {
329 | "version": "1.4.0",
330 | "resolved": "https://registry.npmjs.org/statuses/-/statuses-1.4.0.tgz",
331 | "integrity": "sha512-zhSCtt8v2NDrRlPQpCNtw/heZLtfUDqxBM1udqikb/Hbk52LK4nQSwr10u77iopCW5LsyHpuXS0GnEc48mLeew=="
332 | },
333 | "type-is": {
334 | "version": "1.6.16",
335 | "resolved": "https://registry.npmjs.org/type-is/-/type-is-1.6.16.tgz",
336 | "integrity": "sha512-HRkVv/5qY2G6I8iab9cI7v1bOIdhm94dVjQCPFElW9W+3GeDOSHmy2EBYe4VTApuzolPcmgFTN3ftVJRKR2J9Q==",
337 | "requires": {
338 | "media-typer": "0.3.0",
339 | "mime-types": "~2.1.18"
340 | }
341 | },
342 | "unpipe": {
343 | "version": "1.0.0",
344 | "resolved": "https://registry.npmjs.org/unpipe/-/unpipe-1.0.0.tgz",
345 | "integrity": "sha1-sr9O6FFKrmFltIF4KdIbLvSZBOw="
346 | },
347 | "utils-merge": {
348 | "version": "1.0.1",
349 | "resolved": "https://registry.npmjs.org/utils-merge/-/utils-merge-1.0.1.tgz",
350 | "integrity": "sha1-n5VxD1CiZ5R7LMwSR0HBAoQn5xM="
351 | },
352 | "vary": {
353 | "version": "1.1.2",
354 | "resolved": "https://registry.npmjs.org/vary/-/vary-1.1.2.tgz",
355 | "integrity": "sha1-IpnwLG3tMNSllhsLn3RSShj2NPw="
356 | }
357 | }
358 | }
359 |
--------------------------------------------------------------------------------