├── Lesson02-HTML-CSS ├── boxModel.gif ├── homework │ ├── homework.html │ └── homework-readme.txt └── README.md ├── Lesson12-DOM ├── homework │ ├── assets │ │ ├── lambdawhite.png │ │ └── style.css │ ├── index.html │ ├── README.md │ ├── __tests__ │ │ └── DOM.test.js │ └── DOMhomework.js └── README.md ├── Lesson03-CSS-Positioning ├── homework │ ├── assets │ │ ├── tiger.jpeg │ │ ├── lambdawhite.png │ │ └── dontTouch.css │ ├── homework.css │ └── homework.html └── README.md ├── .travis.yml ├── .eslintrc.js ├── Lesson11-JS-VIII ├── homework │ ├── homework.js │ ├── tests │ │ └── JSVIII.test.js │ └── README.md └── README.md ├── Lesson06-JS-III ├── homework │ ├── README.md │ ├── homework.js │ └── tests │ │ └── JSIII.test.js └── README.md ├── Lesson09-JS-VI ├── homework │ ├── README.md │ ├── homework.js │ └── tests │ │ └── JSVI.test.js └── README.md ├── Lesson05-JS-II ├── homework │ ├── README.md │ ├── homework.js │ └── tests │ │ └── JSII.test.js └── README.md ├── Lesson08-JS-V ├── homework │ ├── README.md │ ├── homework.js │ └── tests │ │ └── JSV.test.js └── README.md ├── Lesson07-JS-IV ├── homework │ ├── README.md │ ├── homework.js │ └── tests │ │ └── JSIV.test.js └── README.md ├── Lesson04-JS-I ├── homework │ ├── README.md │ ├── homework.js │ └── tests │ │ └── JSI.test.js └── README.md ├── package.json ├── Lesson10-JS-VII ├── homework │ ├── README.md │ ├── homework.js │ └── tests │ │ └── JSVII.test.js └── README.md ├── .gitignore ├── README.md └── Lesson01-Git └── README.md /Lesson02-HTML-CSS/boxModel.gif: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/bloominstituteoftechnology/Precourse/HEAD/Lesson02-HTML-CSS/boxModel.gif -------------------------------------------------------------------------------- /Lesson02-HTML-CSS/homework/homework.html: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /Lesson12-DOM/homework/assets/lambdawhite.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/bloominstituteoftechnology/Precourse/HEAD/Lesson12-DOM/homework/assets/lambdawhite.png -------------------------------------------------------------------------------- /Lesson03-CSS-Positioning/homework/assets/tiger.jpeg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/bloominstituteoftechnology/Precourse/HEAD/Lesson03-CSS-Positioning/homework/assets/tiger.jpeg -------------------------------------------------------------------------------- /Lesson03-CSS-Positioning/homework/assets/lambdawhite.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/bloominstituteoftechnology/Precourse/HEAD/Lesson03-CSS-Positioning/homework/assets/lambdawhite.png -------------------------------------------------------------------------------- /.travis.yml: -------------------------------------------------------------------------------- 1 | language: node_js 2 | node_js: "node" 3 | notifications: 4 | email: 5 | recipients: 6 | - dan@lambdaschool.com 7 | - karen@lambdaschool.com 8 | on_success: always 9 | on_failure: never -------------------------------------------------------------------------------- /.eslintrc.js: -------------------------------------------------------------------------------- 1 | module.exports = { 2 | env: { 3 | browser: true, 4 | commonjs: true, 5 | es6: true 6 | }, 7 | extends: "eslint:recommended", 8 | rules: { 9 | quotes: ["error", "single"], 10 | "no-unused-vars": ["error", { vars: "all", args: "none" }], 11 | semi: ["error", "always"] 12 | } 13 | }; 14 | -------------------------------------------------------------------------------- /Lesson11-JS-VIII/homework/homework.js: -------------------------------------------------------------------------------- 1 | // Do not change any of the function names 2 | 3 | // solve these recursively 4 | 5 | function nFactorial(n) { 6 | // return the factorial for n 7 | // example: 8 | // the factorial of 3 is 6 (3 * 2 * 1) 9 | } 10 | 11 | function nFibonacci(n) { 12 | // fibonacci sequence: 1 2 3 5 8 13 ... 13 | // return the nth number in the sequence 14 | } 15 | 16 | // Do not modify code below this line. 17 | // -------------------------------- 18 | 19 | module.exports = { 20 | nFactorial, 21 | nFibonacci, 22 | }; 23 | -------------------------------------------------------------------------------- /Lesson06-JS-III/homework/README.md: -------------------------------------------------------------------------------- 1 | # Homework #JSIII 2 | 3 | ## Instructions 4 | --- 5 | 1. Feynman Writing Prompts - Write out explanations of the following concepts like you are explaining it to a 12 year old. Doing this will help you quickly discover any holes in your understanding. Ask your questions on Slack. 6 | 7 | * Arrays 8 | 9 | 2. 3. From the top level of your `Precourse` folder, run `npm test JSIII.test.js` to run the automated tests. You will fill out the functions in `homework.js` to make the tests pass. 10 | 11 | 12 | For more information about Lambda School's six month CS program visit: https://lambdaschool.com 13 | -------------------------------------------------------------------------------- /Lesson09-JS-VI/homework/README.md: -------------------------------------------------------------------------------- 1 | # Homework #JSVI 2 | 3 | ## Instructions 4 | --- 5 | 1. Feynman Writing Prompts - Write out explanations of the following concepts like you are explaining it to a 12 year old. Doing this will help you quickly discover any holes in your understanding. Ask your questions on Slack. 6 | 7 | * Callback Functions 8 | 9 | 2. From the top level of your `Precourse` folder, run `npm test JSVI.test.js` to run the automated tests. You will fill out the functions in `homework.js` to make the tests pass. 10 | 11 | For more information about Lambda School's six month CS program visit: https://lambdaschool.com 12 | -------------------------------------------------------------------------------- /Lesson05-JS-II/homework/README.md: -------------------------------------------------------------------------------- 1 | # Homework #JSII 2 | 3 | ## Instructions 4 | --- 5 | 1. Feynman Writing Prompts - Write out explanations of the following concepts like you are explaining it to a 12 year old. Doing this will help you quickly discover any holes in your understanding. Ask your questions on Slack. 6 | 7 | * `for` 8 | * `&&`, `||`, `!` 9 | 10 | 2. From the top level of your `Precourse` folder, run `npm test JSII.test.js` to run the automated tests. You will fill out the functions in `homework.js` to make the tests pass. 11 | 12 | For more information about Lambda School's six month CS program visit: https://lambdaschool.com 13 | -------------------------------------------------------------------------------- /Lesson08-JS-V/homework/README.md: -------------------------------------------------------------------------------- 1 | # Homework #JSV 2 | 3 | ## Instructions 4 | --- 5 | 1. Feynman Writing Prompts - Write out explanations of the following concepts like you are explaining it to a 12 year old. Doing this will help you quickly discover any holes in your understanding. Ask your questions on Slack. 6 | 7 | * `prototype` 8 | * Constructors 9 | 10 | 2. From the top level of your `Precourse` folder, run `npm test JSV.test.js` to run the automated tests. You will fill out the functions in `homework.js` to make the tests pass. 11 | 12 | For more information about Lambda School's six month CS program visit: https://lambdaschool.com 13 | -------------------------------------------------------------------------------- /Lesson07-JS-IV/homework/README.md: -------------------------------------------------------------------------------- 1 | # Homework #JSIV 2 | 3 | ## Instructions 4 | --- 5 | 1. Feynman Writing Prompts - Write out explanations of the following concepts like you are explaining it to a 12 year old. Doing this will help you quickly discover any holes in your understanding. Ask your questions on Slack. 6 | 7 | * Objects 8 | * Properties 9 | * Methods 10 | * for in loop 11 | * Dot notation vs bracket notation 12 | 13 | 2. From the top level of your `Precourse` folder, run `npm test JSIV.test.js` to run the automated tests. You will fill out the functions in `homework.js` to make the tests pass. 14 | 15 | 16 | For more information about Lambda School's six month CS program visit: https://lambdaschool.com 17 | -------------------------------------------------------------------------------- /Lesson03-CSS-Positioning/homework/homework.css: -------------------------------------------------------------------------------- 1 | /* 2 | Lesson 3: CSS positioning homwork. All of your work should be done in this file. If you find yourself altering any of the other files 3 | in this folder, you are in the wrong place. 4 | */ 5 | 6 | 7 | /* Exercise One: Centering the text in a span */ 8 | 9 | /* We will start this one off for you: */ 10 | #exerciseOne { 11 | 12 | } 13 | 14 | 15 | /* Exercise Two: Positioning a Header Bar*/ 16 | 17 | /* Place code here */ 18 | 19 | 20 | 21 | /* Exercise Three: */ 22 | 23 | /* Place code here */ 24 | 25 | 26 | 27 | /* Exercise Four: */ 28 | 29 | /* Place code here */ 30 | 31 | 32 | 33 | /* Exercise Five */ 34 | 35 | /* Place code here */ 36 | 37 | 38 | 39 | /* Exercise Six */ 40 | 41 | #exerciseSeven { 42 | display: flex; 43 | } 44 | -------------------------------------------------------------------------------- /Lesson11-JS-VIII/homework/tests/JSVIII.test.js: -------------------------------------------------------------------------------- 1 | describe('Test suite runs', () => { 2 | it('Will run the tests', () => { 3 | expect(true).toBe(true); 4 | }) 5 | }) 6 | 7 | // /* eslint-disable no-undef */ 8 | // const { 9 | // nFactorial, 10 | // nFibonacci, 11 | // } = require('../homework'); 12 | 13 | // describe('nFactorial(n)', function() { 14 | // it('should return the factorial of n', function() { 15 | // expect(nFactorial(5)).toBe(120); 16 | // expect(nFactorial(15)).toBe(1307674368000); 17 | // }); 18 | // }); 19 | 20 | // describe('nFibonacci(n)', function() { 21 | // it('should return the nth fibonacci number', () => { 22 | // const fib1 = nFibonacci(5); 23 | // const fib2 = nFibonacci(3); 24 | // const fib3 = nFibonacci(1); 25 | // expect(fib1).toBe(8); 26 | // expect(fib2).toBe(3); 27 | // expect(fib3).toBe(1); 28 | // }); 29 | // }); 30 | -------------------------------------------------------------------------------- /Lesson12-DOM/homework/index.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | Lambda School Precourse Workshop Web App 4 | 5 | 6 | 7 | 8 | 12 |

To-Do App

13 |
This app was created by:
14 |
15 |
16 |
ADD
17 |
18 |
19 |
20 | 21 | -------------------------------------------------------------------------------- /Lesson09-JS-VI/homework/homework.js: -------------------------------------------------------------------------------- 1 | // Do not change any of the function names 2 | 3 | function invokeCallback(cb) { 4 | // invoke cb 5 | } 6 | 7 | function sumArray(numbers, cb) { 8 | // sum up all of the integers in the numbers array 9 | // pass the result to cb 10 | // no return is necessary 11 | } 12 | 13 | function forEach(arr, cb) { 14 | // iterate over arr and pass its values to cb one by one 15 | // hint: you will be invoking cb multiple times (once for each value in the array) 16 | } 17 | 18 | function map(arr, cb) { 19 | // create a new array 20 | // iterate over each value in arr, pass it to cb, then place the value returned from cb into the new arr 21 | // the new array should be the same length as the array argument 22 | } 23 | 24 | // Do not modify code below this line. 25 | // -------------------------------- 26 | 27 | module.exports = { 28 | invokeCallback, 29 | sumArray, 30 | forEach, 31 | map, 32 | }; 33 | -------------------------------------------------------------------------------- /Lesson04-JS-I/homework/README.md: -------------------------------------------------------------------------------- 1 | # Homework: Introduction to Javascript, JSI 2 | 3 | ## Instructions 4 | --- 5 | 1. Feynman Writing Prompts - In a seprate text file that you create, write out explanations of the following concepts like you are explaining it to a 12 year old. Doing this will help you quickly discover any holes in your understanding. Ask your questions on Slack. 6 | 7 | * Variables 8 | * Strings 9 | * Functions (arguments, `return`) 10 | * `if` statements 11 | * Boolean values (`true`, `false`) 12 | 13 | 14 | 2. Install Node and NPM. NPM comes packaged with Node. https://nodejs.org/en/download/ 15 | 16 | 3. From the top level of your `Precourse` folder, run `npm test JSI.test.js` to run the automated tests. At first all of the tests will be broken. You will fill out the functions in `homework.js` to make the tests pass. 17 | 18 | 19 | For more information about Lambda School's six month CS program visit: https://lambdaschool.com 20 | -------------------------------------------------------------------------------- /package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "lambdaschoolprecourse", 3 | "version": "1.0.0", 4 | "description": "This repo contains the instruction material and assignments for Lambda School's `Web Dev 101 Mini Bootcamp`.", 5 | "main": "index.js", 6 | "scripts": { 7 | "test": "eslint Lesson09-JS-VI/homework/homework.js Lesson08-JS-V/homework/homework.js Lesson07-JS-IV/homework/homework.js Lesson06-JS-III/homework/homework.js Lesson05-JS-II/homework/homework.js Lesson04-JS-I/homework/homework.js && jest" 8 | }, 9 | "repository": { 10 | "type": "git", 11 | "url": "git+https://github.com/lambdaschool/precourse.git" 12 | }, 13 | "author": "Daniel Frehner and Ben Nelson, Lambda School", 14 | "license": "ISC", 15 | "bugs": { 16 | "url": "https://github.com/lambdaschool/precourse/issues" 17 | }, 18 | "homepage": "https://github.com/lambdaschool/precourse#readme", 19 | "devDependencies": { 20 | "eslint": "^4.13.1", 21 | "jest": "^22.0.3" 22 | } 23 | } 24 | -------------------------------------------------------------------------------- /Lesson11-JS-VIII/homework/README.md: -------------------------------------------------------------------------------- 1 | # Homework #JSVIII 2 | 3 | ## Instructions 4 | --- 5 | 1. Feynman Writing Prompts - Write out explanations of the following concepts like you are explaining it to a 12 year old. Doing this will help you quickly discover any holes in your understanding. Ask your questions on Slack. 6 | 7 | * Recursion 8 | 9 | *** Stretch Goals: Everything after this line is optional *** 10 | *** These tests are optional, any work you do to comeplete these tests is extra. That being said, having exposure to these concepts and attempting them is recommended. The better you understand these concepts, the better your experience will be at Lambda School. *** 11 | 2. Umcomment lines 7 through 29 in the file `JSVIII.test.js` in the `__test__` folder in this `homework` folder. Then, from the top level of your `Precourse` folder, run `npm test JSVIII.test.js` to run the automated tests. You will fill out the functions in `homework.js` to make the tests pass. 12 | 13 | For more information about Lambda School's six month CS program visit: https://lambdaschool.com 14 | -------------------------------------------------------------------------------- /Lesson10-JS-VII/homework/README.md: -------------------------------------------------------------------------------- 1 | # Homework #JSVII 2 | 3 | ## Instructions 4 | --- 5 | 1. Feynman Writing Prompts - Write out explanations of the following concepts like you are explaining it to a 12 year old. Doing this will help you quickly discover any holes in your understanding. Ask your questions on Slack. 6 | 7 | * Closure 8 | 9 | *** Stretch Goals: Everything after this line is optional *** 10 | *** These tests are optional, any work you do to comeplete these tests is extra. That being said, having exposure to these concepts and attempting them is recommended. The better you understand these concepts, the better your experience will be at Lambda School. *** 11 | 2. Uncoment lines 7 through 56 in the file `JSVII.test.js` from the `__tests__` folder within this `homework` folder. Then, from the top level of your `Precourse` folder, run `npm test JSVII.test.js` to run the automated tests. You will fill out the functions in `homework.js` to make the tests pass. 12 | 13 | For more information about Lambda School's six month CS program visit: https://lambdaschool.com 14 | -------------------------------------------------------------------------------- /Lesson12-DOM/homework/README.md: -------------------------------------------------------------------------------- 1 | # Homework #JSVII 2 | 3 | ## Instructions 4 | --- 5 | 1. Feynman Writing Prompts - Write out explanations of the following concepts like you are explaining it to a 12 year old. Doing this will help you quickly discover any holes in your understanding. Ask your questions on Slack. 6 | 7 | * DOM 8 | * DOM element selectors 9 | * DOM events 10 | 11 | *** Stretch Goals: Everything after this line is optional *** 12 | *** These tests are optional, any work you do to comeplete these tests is extra. That being said, having exposure to these concepts and attempting them is recommended. The better you understand these concepts, the better your experience will be at Lambda School. *** 13 | 2. Uncoment lines 7 through 108 in the file `DOM.test.js` from the `__test__` folder within this `homework` folder. Then, from the top level of your `Precourse` folder, run `npm test JSVII.test.js` to run the automated tests. You will fill out the functions in `homework.js` to make the tests pass. 14 | 15 | For more information about Lambda School's six month CS program visit: https://lambdaschool.com 16 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | # Logs 2 | logs 3 | *.log 4 | npm-debug.log* 5 | yarn-debug.log* 6 | yarn-error.log* 7 | 8 | # Runtime data 9 | pids 10 | *.pid 11 | *.seed 12 | *.pid.lock 13 | 14 | # Directory for instrumented libs generated by jscoverage/JSCover 15 | lib-cov 16 | 17 | # Coverage directory used by tools like istanbul 18 | coverage 19 | 20 | # nyc test coverage 21 | .nyc_output 22 | 23 | # Grunt intermediate storage (http://gruntjs.com/creating-plugins#storing-task-files) 24 | .grunt 25 | 26 | # Bower dependency directory (https://bower.io/) 27 | bower_components 28 | 29 | # node-waf configuration 30 | .lock-wscript 31 | 32 | # Compiled binary addons (http://nodejs.org/api/addons.html) 33 | build/Release 34 | 35 | # Dependency directories 36 | node_modules/ 37 | jspm_packages/ 38 | 39 | # Typescript v1 declaration files 40 | typings/ 41 | 42 | # Optional npm cache directory 43 | .npm 44 | 45 | # Optional eslint cache 46 | .eslintcache 47 | 48 | # Optional REPL history 49 | .node_repl_history 50 | 51 | # Output of 'npm pack' 52 | *.tgz 53 | 54 | # Yarn Integrity file 55 | .yarn-integrity 56 | 57 | # dotenv environment variables file 58 | .env 59 | 60 | .DS_Store 61 | 62 | package-lock.json 63 | 64 | -------------------------------------------------------------------------------- /Lesson08-JS-V/homework/homework.js: -------------------------------------------------------------------------------- 1 | // Do not change any of the function names 2 | 3 | function createUserClass() { 4 | // create an ES6 class or a constructor function called User 5 | // it should accept an options object with username, name, email, and password properties 6 | // in the constructor set the username, name, email, and password properties 7 | // the constructor should have a method 'sayHi' on its prototype that returns the string 'Hello, my name is {{name}}' 8 | // {{name}} should be the name set on each instance 9 | // return the class 10 | } 11 | 12 | function addPrototypeMethod(Constructor) { 13 | // add a method to the constructor's prototype 14 | // the method should be called 'sayHi' and should return the string 'Hello World!' 15 | } 16 | 17 | function addReverseString() { 18 | // add a method to the string constructor's prototype that returns a reversed copy of the string 19 | // name this method reverse 20 | // hint: 21 | // you will need to use 'this' inside of reverse 22 | } 23 | 24 | // Do not modify code below this line. 25 | // -------------------------------- 26 | 27 | module.exports = { 28 | createUserClass, 29 | addPrototypeMethod, 30 | addReverseString, 31 | }; 32 | -------------------------------------------------------------------------------- /Lesson09-JS-VI/homework/tests/JSVI.test.js: -------------------------------------------------------------------------------- 1 | /* eslint-disable no-undef */ 2 | const { 3 | invokeCallback, 4 | sumArray, 5 | forEach, 6 | map, 7 | } = require('../homework'); 8 | 9 | describe('invokeCallback(cb)', function() { 10 | it('should invoke the callback that is passed in', function() { 11 | const cb = jest.fn(); 12 | invokeCallback(cb); 13 | expect(cb).toHaveBeenCalled(); 14 | }); 15 | }); 16 | 17 | describe('sumArray(cb)', function() { 18 | it('should pass the sum of all array numbers to cb', function(done) { 19 | sumArray([1, 2, 3, 4, 5], function(sum) { 20 | expect(sum).toBe(15); 21 | done(); 22 | }); 23 | }); 24 | }); 25 | 26 | describe('forEach(arr, cb)', function() { 27 | it('should pass all array items one by one to cb', function() { 28 | const nums = []; 29 | forEach([1, 2, 3, 4, 5], function(num) { 30 | nums.push(num); 31 | }); 32 | expect(nums).toEqual([1, 2, 3, 4, 5]); 33 | }); 34 | }); 35 | 36 | describe('map(arr, cb)', function() { 37 | it('should return an array of all the processed array elements', function() { 38 | const squares = map([1, 2, 3, 4, 5], function(num) { 39 | return num * num; 40 | }); 41 | expect(squares).toEqual([1, 4, 9, 16, 25]); 42 | }); 43 | }); 44 | -------------------------------------------------------------------------------- /Lesson10-JS-VII/homework/homework.js: -------------------------------------------------------------------------------- 1 | // Do not change any of the function names 2 | 3 | function counter() { 4 | // Return a function that when invoked increments and returns a counter variable. 5 | // Example: const newCounter = counter(); 6 | // newCounter(); // 1 7 | // newCounter(); // 2 8 | } 9 | 10 | function cacheFunction(cb) { 11 | // use closure to create a cache for the cb function 12 | // the function that you return should accept a single argument and invoke cb with that argument 13 | // when the function you return is invoked with an argument it should save that argument and its result 14 | // when the function you return is called again with an argument that it has seen before it should not call cb 15 | // but should instead directly returned the previous result 16 | // example: 17 | // cb -> function(x) { return x * x; } 18 | // if the function you return is invoked with 5 it would pass 5 to cb(5) and return 25 19 | // if the function you return is invoked again with 5 it will look on an object in the closure scope 20 | // and return 25 directly and will not invoke cb again 21 | } 22 | 23 | // Do not modify code below this line. 24 | // -------------------------------- 25 | 26 | module.exports = { 27 | counter, 28 | cacheFunction, 29 | }; 30 | -------------------------------------------------------------------------------- /Lesson08-JS-V/homework/tests/JSV.test.js: -------------------------------------------------------------------------------- 1 | /* eslint-disable no-undef */ 2 | const { 3 | createUserClass, 4 | addPrototypeMethod, 5 | addReverseString, 6 | } = require('../homework'); 7 | 8 | describe('createUserClass()', function() { 9 | it('should return a user constructor that correctly builds user objects', function() { 10 | const User = createUserClass(); 11 | const user = new User({username: 'SunJieMing', name: 'Ben', email: 'ben@lambdaschool.com', password: 'LS Rocks!' }); 12 | expect(user.username).toBe('SunJieMing'); 13 | expect(user.name).toBe('Ben'); 14 | expect(user.email).toBe('ben@lambdaschool.com'); 15 | expect(user.password).toBe('LS Rocks!'); 16 | }); 17 | }); 18 | 19 | describe('addPrototypeMethod(Constructor)', function() { 20 | it('should add the method sayHi to the constructor', function() { 21 | function Test() { 22 | this.test = true; 23 | } 24 | addPrototypeMethod(Test); 25 | const test = new Test(); 26 | expect(test.sayHi()).toBe('Hello World!'); 27 | }); 28 | }); 29 | 30 | describe('addReverseString(StringPrototype)', function(){ 31 | it('should add a reverse string method to the String prototype that returns a reversed version of the string', function() { 32 | addReverseString(); 33 | const str = 'Hello'; 34 | expect(str.reverse()).toBe('olleH'); 35 | }); 36 | }); 37 | -------------------------------------------------------------------------------- /Lesson05-JS-II/homework/homework.js: -------------------------------------------------------------------------------- 1 | // Do not change any of the function names 2 | 3 | function getBiggest(x, y) { 4 | // x and y are integers. Return the larger integer 5 | // if they are the same return either one 6 | } 7 | 8 | function greeting(language) { 9 | // return a greeting for three different languages: 10 | // language: 'German' -> 'Guten Tag!' 11 | // language: 'Mandarin' -> 'Ni Hao!' 12 | // language: 'Spanish' -> 'Hola!' 13 | // if language is undefined return 'Hello!' 14 | } 15 | 16 | function isTenOrFive(num) { 17 | // return true if num is 10 or 5 18 | // otherwise return false 19 | } 20 | 21 | function isInRange(num) { 22 | // return true if num is less than 50 and greater than 20 23 | // otherwise return false 24 | } 25 | 26 | function isInteger(num) { 27 | // return true if num is an integer 28 | // 0.8 -> false 29 | // 1 -> true 30 | // -10 -> true 31 | // otherwise return false 32 | // hint: you can solve this using Math.floor 33 | } 34 | 35 | function fizzBuzz(num) { 36 | // if num is divisible by 3 return 'fizz' 37 | // if num is divisible by 5 return 'buzz' 38 | // if num is divisible by 3 & 5 return 'fizzbuzz' 39 | // otherwise return num 40 | } 41 | 42 | function isPrime(num) { 43 | // return true if num is prime. 44 | // otherwise return false 45 | // hint: a prime number is only evenly divisible by itself and 1 46 | // hint2: you can solve this using a for loop 47 | // note: 0 and 1 are NOT considered prime numbers 48 | } 49 | 50 | 51 | 52 | // Do not modify code below this line. 53 | // -------------------------------- 54 | 55 | module.exports = { 56 | getBiggest, 57 | greeting, 58 | isTenOrFive, 59 | isInRange, 60 | isInteger, 61 | fizzBuzz, 62 | isPrime, 63 | }; 64 | -------------------------------------------------------------------------------- /Lesson10-JS-VII/homework/tests/JSVII.test.js: -------------------------------------------------------------------------------- 1 | describe('Test suite runs', () => { 2 | it('Will run the tests', () => { 3 | expect(true).toBe(true); 4 | }) 5 | }) 6 | 7 | // /* eslint-disable no-undef */ 8 | // const { 9 | // counter, 10 | // cacheFunction, 11 | // } = require('../homework'); 12 | 13 | // describe('counter', () => { 14 | // it('should return a function', () => { 15 | // expect(typeof counter()).toBe('function'); 16 | // }); 17 | // it('should return 1 when the returned function is invoked', () => { 18 | // expect(counter()()).toBe(1); 19 | // }); 20 | // it('should increment and return the number each time the function is invoked', () => { 21 | // const counterFunction = counter(); 22 | // expect(counterFunction()).toBe(1); 23 | // expect(counterFunction()).toBe(2); 24 | // expect(counterFunction()).toBe(3); 25 | // expect(counterFunction()).toBe(4); 26 | // expect(counterFunction()).toBe(5); 27 | // }); 28 | // }); 29 | 30 | // describe('cacheFunction(cb)', function() { 31 | // it('should return the callback function', function() { 32 | // const cb = function() {}; 33 | // expect(typeof cacheFunction(cb)).toEqual('function'); 34 | // }); 35 | // it('should return the callback functions result when the cached function is invoked', function() { 36 | // const cb = function(x) { 37 | // return x * 2; 38 | // }; 39 | // const cachedFunction = cacheFunction(cb); 40 | // expect(cachedFunction(5)).toBe(10); 41 | // }); 42 | // it('should cache function results', function() { 43 | // const cb = jest.fn(); 44 | // const cachedFunction = cacheFunction(cb); 45 | // cachedFunction(true); 46 | // cachedFunction(true); 47 | // cachedFunction(true); 48 | // cachedFunction(true); 49 | // cachedFunction(true); 50 | // cachedFunction(10); 51 | // cachedFunction(10); 52 | // cachedFunction(10); 53 | // cachedFunction(10); 54 | // expect(cb).toHaveBeenCalledTimes(2); 55 | // }); 56 | // }); 57 | -------------------------------------------------------------------------------- /Lesson03-CSS-Positioning/homework/assets/dontTouch.css: -------------------------------------------------------------------------------- 1 | body { 2 | background: #e5efff; 3 | margin: 95px 0 100px 0; 4 | color: #383f49; 5 | font-family: "Helvetica Neue",Helvetica,Arial,sans-serif; 6 | } 7 | 8 | #header { 9 | text-align: center; 10 | } 11 | 12 | .exerciseContainer { 13 | padding: 30px; 14 | } 15 | 16 | #exerciseTwo { 17 | height: 50px; 18 | text-align: center; 19 | border: 1px solid purple; 20 | } 21 | 22 | #moveBoxContainer { 23 | width: 1000px; 24 | height: 500px; 25 | border: 5px solid #1970fc; 26 | background-color: #bdd6fc; 27 | margin-left: auto; 28 | margin-right: auto; 29 | margin-top: 20px; 30 | position: relative; 31 | } 32 | 33 | #targetContainer { 34 | width: 400px; 35 | height: 300px; 36 | border: 5px dashed red; 37 | position: absolute; 38 | top: 95px; 39 | left: 195px; 40 | } 41 | 42 | #descSpan { 43 | position: absolute; 44 | top: 100px; 45 | left: 615px; 46 | padding-right: 20px; 47 | 48 | } 49 | 50 | #exerciseFour { 51 | display: block; 52 | width: 100vw; 53 | height: 70px; 54 | background-color: #1970fc; 55 | } 56 | 57 | #exerciseFive span { 58 | font-size: 20px; 59 | color: white; 60 | } 61 | 62 | #exerciseFive { 63 | height: 100%; 64 | padding: 0 10px; 65 | } 66 | 67 | #exerciseSeven { 68 | width: 500px; 69 | height: 400px; 70 | margin-left: auto; 71 | margin-right: auto; 72 | border: 3px solid black; 73 | position: relative; 74 | background-color: black; 75 | } 76 | 77 | .itemSpan { 78 | display: block; 79 | text-align: center; 80 | align-self: center; 81 | } 82 | 83 | .items { 84 | width: 100px; 85 | height: 100px; 86 | display: flex; 87 | background-color: white; 88 | } 89 | 90 | #itemOne { 91 | border: 2px dashed green; 92 | } 93 | 94 | #itemTwo { 95 | border: 2px dashed orange; 96 | } 97 | 98 | #itemThree { 99 | border: 2px dashed blue; 100 | } 101 | 102 | #itemFour { 103 | border: 2px dashed red; 104 | } 105 | 106 | 107 | -------------------------------------------------------------------------------- /Lesson12-DOM/homework/assets/style.css: -------------------------------------------------------------------------------- 1 | body { 2 | background-color: rgb(232, 246, 255); 3 | font-family: "Helvetica Neue",Helvetica,Arial,sans-serif; 4 | margin-top: 56px; 5 | display: flex; 6 | flex-direction: column; 7 | align-items: center; 8 | } 9 | 10 | #header { 11 | width: 100%; 12 | position: absolute; 13 | top: 0; 14 | left: 0; 15 | background: #428fbb; 16 | height: 56px; 17 | /* padding-left: 15px; */ 18 | display: flex; 19 | justify-content: space-between; 20 | align-items: center; 21 | } 22 | 23 | #header span { 24 | font-size: 24px; 25 | color: white; 26 | padding-right: 15px; 27 | } 28 | 29 | #header a { 30 | padding-left: 15px; 31 | } 32 | 33 | 34 | #container { 35 | background-color: #428fbb; 36 | box-shadow: 2px 2px 5px#000; 37 | width: 50%; 38 | min-width: 700px; 39 | border-radius: 5px; 40 | } 41 | 42 | #inputContainer { 43 | display: flex; 44 | justify-content: center; 45 | padding: 10px; 46 | margin-bottom: 25px; 47 | } 48 | 49 | #toDoInput { 50 | outline: none; 51 | width: 75%; 52 | padding-left: 10px; 53 | font-size: 20px; 54 | border: none; 55 | border-radius: 4px; 56 | } 57 | 58 | #addButton { 59 | display: flex; 60 | justify-content: center; 61 | align-items: center; 62 | width: 100px; 63 | margin-left: 10px; 64 | border-radius: 4px; 65 | cursor: pointer; 66 | height: 35px; 67 | background: #0160A2; 68 | color: #FFF; 69 | font-size: 20px; 70 | } 71 | 72 | #toDoContainer { 73 | width: 100%; 74 | display: flex; 75 | justify-content: center; 76 | flex-wrap: wrap; 77 | cursor: pointer; 78 | } 79 | 80 | .toDoShell { 81 | width: 650px; 82 | min-height: 50px; 83 | display: flex; 84 | justify-content: space-around; 85 | align-items: center; 86 | background: #fff; 87 | margin-bottom: 10px; 88 | border-radius: 5px; 89 | font-size: 20px; 90 | padding: 5px; 91 | } 92 | 93 | .toDoShell span { 94 | width: 90%; 95 | } 96 | .completeText { 97 | color: lightgrey; 98 | text-decoration: line-through; 99 | } 100 | 101 | .completeCheckbox { 102 | transform: scale(1.8); 103 | } 104 | -------------------------------------------------------------------------------- /Lesson06-JS-III/homework/homework.js: -------------------------------------------------------------------------------- 1 | // Do not change any of the function names 2 | 3 | function returnFirst(arr) { 4 | // return the first item from the array 5 | } 6 | 7 | function returnLast(arr) { 8 | // return the last item of the array 9 | } 10 | 11 | function getArrayLength(arr) { 12 | // return the length of the array 13 | } 14 | 15 | function incrementByOne(arr) { 16 | // arr is an array of integers 17 | // increase each integer by one 18 | // return the array 19 | } 20 | 21 | function addItemToArray(arr, item) { 22 | // add the item to the end of the array 23 | // return the array 24 | } 25 | 26 | function addItemToFront(arr, item) { 27 | // add the item to the front of the array 28 | // return the array 29 | // hint: use the array method .unshift 30 | } 31 | 32 | function wordsToSentence(words) { 33 | // words is an array of strings 34 | // return a string that is all of the words concatenated together 35 | // spaces need to be between each word 36 | // example: ['Hello', 'world!'] -> 'Hello world!' 37 | } 38 | 39 | function contains(arr, item) { 40 | // check to see if item is inside of arr 41 | // return true if it is, otherwise return false 42 | } 43 | 44 | function addNumbers(numbers) { 45 | // numbers is an array of integers. 46 | // add all of the integers and return the value 47 | } 48 | 49 | function averageTestScore(testScores) { 50 | // testScores is an array. Iterate over testScores and compute the average. 51 | // return the average 52 | } 53 | 54 | function largestNumber(numbers) { 55 | // numbers is an array of integers 56 | // return the largest integer 57 | } 58 | 59 | function multiplyArguments() { 60 | // use the arguments keyword to multiply all of the arguments together and return the product 61 | // if no arguments are passed in return 0 62 | // if one argument is passed in just return it 63 | } 64 | 65 | // Do not modify code below this line. 66 | // -------------------------------- 67 | 68 | module.exports = { 69 | returnFirst, 70 | returnLast, 71 | getArrayLength, 72 | incrementByOne, 73 | addItemToArray, 74 | addItemToFront, 75 | wordsToSentence, 76 | contains, 77 | addNumbers, 78 | averageTestScore, 79 | largestNumber, 80 | multiplyArguments, 81 | }; 82 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # Lambda School Precourse Workshop 2 | This repo contains the instruction material and assignments for Lambda School's free `Web Dev 101 mini-bootcamp`. Lambda School's free `Web Dev 101 mini-bootcamp` is a three week long course that covers the fundamentals of programming and web development. Class is held at 5pm Pacific Time Monday through Thursday at the dates listed below. This class is repeated and given live every month. 3 | 4 | To sign up for the program or to learn more about Lambda School's intensive Computer Science program, visit https://www.lambdaschool.com 5 | 6 | To receive help with the homework you can join our Slack team. After registering for the mini-bootcamp on our website you will be sent an invitation to join Slack. We have TAs available to answer questions about the homework. 7 | 8 | 9 | ### Live Broadcast Recordings 10 | 11 | All recordings are available on our [YouTube channel](https://www.youtube.com/channel/UCmgWnKIhmOi-MuRUC62mOFw?view_as=subscriber). 12 | 13 | Live stream recordings will also be listed here: 14 | 15 | * [Lesson 1 - Git, terminal, and GitHub](https://youtu.be/6lLMqYxIMvw) 16 | * [Lesson 2 - HTML & CSS](https://youtu.be/uLSFDk2C5WA) 17 | * [Lesson 3 - CSS Positioning](https://youtu.be/GNLbLG6OxxU) 18 | * [Lesson 4 - JavaScript I](https://youtu.be/bL-1YjvTRXQ) 19 | * [Lesson 5 - JavaScript II](https://www.youtube.com/watch?v=iWeR2cXj-nQ) 20 | * [Lesson 6 - JavaScript III](https://www.youtube.com/watch?v=jOOL4uuCBgw) 21 | * [Lesson 7 - JavaScript IV](https://www.youtube.com/watch?v=6VLr-E5BM_c) 22 | * [Lesson 8 - JavaScript V](https://www.youtube.com/watch?v=eWO2qIThltE) 23 | * [Lesson 9 - JavaScript VI](https://www.youtube.com/watch?v=ucctc5-kjOo) 24 | * [Lesson 10 - JavaScript VII](https://www.youtube.com/watch?v=pNit3wXnsHc) 25 | * [Lesson 11 - JavaScript VIII](https://www.youtube.com/watch?v=YWHjh3QvEZo) 26 | * [Lesson 12 - DOM](https://www.youtube.com/watch?v=_0ZQCGPlsQg) 27 | 28 | #### Directions for updating your fork 29 | 30 | If you have already forked this repository but you would like to add the new updates to your forked copy then type the following git commands from within your local repo: 31 | 32 | ``` 33 | git remote add upstream https://github.com/LambdaSchool/Precourse.git 34 | git pull upstream master 35 | ``` 36 | 37 | You only need to add the `upstream` remote once. If you wish to pull down updates multiple times then just use `git pull upstream master` on subsequent pulls. 38 | 39 | If you have any questions or are experiencing merge conflicts then reach out to a TA for assistance. 40 | -------------------------------------------------------------------------------- /Lesson11-JS-VIII/README.md: -------------------------------------------------------------------------------- 1 | # Lesson 11: Javascript VIII (Recursion) 2 | (Attention: These are the class notes for the [Lambda School](http://www.lambdaschool.com) pre-course instruction workshop. This is meant to serve as an accompaniment to the class) 3 | 4 | In this lesson we will cover: 5 | 6 | * Recursion 7 | 8 | ## Recursion 9 | 10 | In the previous assignment we discussed the flexibility that we have with functions in JavaScript. Another cool aspect about functions is that we can invoke a function from inside of itself. This is called recursion. Recursion is a type of iteration similar to `for` and `while` loops. 11 | 12 | The code below is an example of recursion. Don't actually run this code though because it will produce an infinite loop. Just like with `for` loops, if we don't have something that stops the iteration the cyle will continue forever. In the case below the function `foo` will continue to call itself until the program crashes. 13 | 14 | ```javascript 15 | function foo() { 16 | foo(); // caution: this will produce an infinite loop 17 | } 18 | ``` 19 | 20 | The same basic pieces of a `for` loop apply to a recursive function: 21 | 22 | ```javascript 23 | for (let i = 1; i <= 5; i++) { 24 | console.log(i); 25 | } 26 | // prints 1, 2, 3, 4, 5 27 | ``` 28 | 29 | There are three parts to the code above: 30 | 1. In the code above we have a variable `i` that we will use to keep track of how many iterations we have run. 31 | 2. We also have a truth condition that needs to be checked between each iteration. The code will run as long as it is true. 32 | 3. We are moving towards a condition where the loop stops. `i++` is doing this part. 33 | 34 | Recursion needs to use the same three parts but it is written differently. 35 | 36 | ```javascript 37 | function looper(n) { 38 | if (n > 5) return; 39 | console.log(n); 40 | looper(n + 1); 41 | } 42 | looper(1); 43 | // prints 1, 2, 3, 4, 5 44 | ``` 45 | 46 | The code above will have the same result as the `for` loop used up above. It also has the same three pieces of the `for` loop as shown above. 47 | 1. `n` is the variable we are using to keep track of our iteration. 48 | 2. Instead of a truth condition that must be `true` to keep going like in our `for` loop we have a base case. The base case says "stop when `false`". 49 | 3. We move towards satisfying the base case by modifying `n`. 50 | 51 | Everything that can be writter recursively can be written iteratively (with a `while` loop or a `for` loop). There are cases where a recursive 52 | solution is simpler and easier to write than an iterative solution. Recursive functions are generally used when working with various data structures 53 | like trees, linked lists, or graphs. Programming is all about tradeoffs and different approaches have different advantages. For now we recommend that 54 | you generally stick to iteration but it is good to understand how to write recursive solutions. 55 | 56 | ## Additional Resources: 57 | 58 | * [Eloquent Javascript: Functions](https://eloquentjavascript.net/03_functions.html) - Scroll to the section titled "Recursion" 59 | -------------------------------------------------------------------------------- /Lesson02-HTML-CSS/homework/homework-readme.txt: -------------------------------------------------------------------------------- 1 | These are the instructions for the homework for Lesson 2 - HTML/CSS Fundamentals. 2 | 3 | Now that you have watched us create an HTML file and external style sheet you will do one of your own. 4 | You will be writing all of your code in homework.html found in this folder. 5 | To view your HTML file, in your web browser select File-Open File- then select the homework.html file in this folder. 6 | 7 | I. Create a basic HTML page. 8 | A. Create the basic layout for an HTML page using html, head, and body. 9 | B. Add a title element and give your page the title of "[Your name]'s HTML homework". 10 | C. In the body, create three divs. 11 | 1. In the first div create: 12 | * an h1 element containing [Your name]. 13 | * an h3 element containing "Lambda School". 14 | * an h4 element containing "HTML/CSS homework". 15 | 2. In the second div create:. 16 | * a span element containing text describing your favorite food. 17 | * an 'a' element linking to your favorite restaurant. 18 | 3. In the third div create: 19 | * an an unordered list with two list items 20 | * an img tag in each list item linking to your favorite food. (Use Google image search to find a photo, if you can't 21 | use this address: "http://http://lorempixel.com/400/200/food/"). 22 | 23 | II. Add some style 24 | A. Add style tags to your HTML document. 25 | B. Give your third div the id "thirdDiv". 26 | C. Give your other divs the class "divClass". 27 | D. Give the span in your second div the id "spanId". 28 | E. Add a style rule to your h1 element changing the color of the text (pick from 29 | here: https://www.crockford.com/wrrrld/color.html). 30 | F. Add a style rule to the img element giving it a width of 400px; 31 | G. Add a style rule to 'thirdDiv' changing the height to 600px and the width to 500px. 32 | H. Add a style rule to 'thirdDiv' changing the background color. 33 | I. Change the size of the font for 'spanId' to 18px. 34 | J. Give the id 'spanId' a margin of 50px. 35 | K. Give the id 'thirdDiv' a padding of 50px. 36 | L. Give the id 'thirdDiv' a border, any width color and style you choose. 37 | 38 | III. Create an external style sheet and move all of our previous style rules into the new stylesheet. 39 | A. Create a file called styles.css in this folder. 40 | B. COPY all of your style rules to this new file. (Do not include the style tags!) 41 | C. Place: after your closing style tag. 43 | E. Add a link tag to your html that imports your new css file. 44 | 45 | IV. Add, Commit and push your work to your github account. 46 | 47 | Extra credit: 48 | In order to do some of this you will either need to have an understanding of CSS currently, or will need to 49 | do some further homework, I recommend the additional resources in the README or https://www.w3schools.com/css/default.asp) 50 | 51 | * Set the background of the entire page to an image 52 | * Center the div's on the page 53 | * Center all of the elements on the page 54 | * Read about positioning and use the position rule in your styles 55 | * Read about flexbox and use flexbox to center all of the items on the page 56 | 57 | 58 | -------------------------------------------------------------------------------- /Lesson12-DOM/homework/__tests__/DOM.test.js: -------------------------------------------------------------------------------- 1 | describe('Test suite runs', () => { 2 | it('Will run the tests', () => { 3 | expect(true).toBe(true); 4 | }) 5 | }) 6 | 7 | // const html = require('fs') 8 | // .readFileSync('./Lesson12-DOM/homework/index.html') 9 | // .toString(); 10 | 11 | // document.documentElement.innerHTML = html; 12 | 13 | // const { 14 | // ToDo, 15 | // buildToDo, 16 | // buildToDos, 17 | // addToDo, 18 | // completeToDo, 19 | // toDoItems, 20 | // } = require('../DOMhomework.js'); 21 | // let desc, newToDo; 22 | 23 | // describe('Put your name on it.', () => { 24 | // it('Put your name on it!', () => { 25 | // const nameLength = document.querySelector('#createdBy').innerHTML.length; 26 | // expect(nameLength).toBeGreaterThan(24); 27 | // }); 28 | // }); 29 | 30 | // describe('ToDo Class', () => { 31 | // beforeEach(() => { 32 | // document.documentElement.innerHTML = html; 33 | // desc = 'Create ToDo'; 34 | // newToDo = new ToDo(desc); 35 | // }); 36 | 37 | // it('creates a ToDo', () => { 38 | // expect(newToDo.description).toEqual(desc); 39 | // expect(newToDo.complete).toEqual(false); 40 | // }); 41 | 42 | // it('adds completeToDo to the prototype of ToDo', () => { 43 | // expect(typeof ToDo.prototype.completeToDo).toBe('function'); 44 | // }); 45 | 46 | // it('completeToDo method changes complete to true', () => { 47 | // newToDo.completeToDo(); 48 | // expect(newToDo.complete).toBe(true); 49 | // }); 50 | // }); 51 | 52 | // describe('toDoItems array', () => { 53 | // it('should have an array called \'toDoItems\'', () => { 54 | // expect(Array.isArray(toDoItems)).toBe(true); 55 | // }); 56 | // }); 57 | 58 | // describe('buildToDo function', () => { 59 | // beforeEach(() => { 60 | // document.documentElement.innerHTML = html; 61 | // desc = 'Create ToDo'; 62 | // }); 63 | 64 | // it('creates an HTML toDo from a ToDo Object', () => { 65 | // const newToDo = new ToDo(desc); 66 | // const toDoHTML = buildToDo(newToDo); 67 | // expect(toDoHTML).not.toBeUndefined(); 68 | // expect(toDoHTML.className).toEqual('toDoShell'); 69 | // }); 70 | // }); 71 | 72 | // describe('buildToDos function', () => { 73 | // it('exists, and is a function', () => { 74 | // expect(typeof buildToDos).toBe('function'); 75 | // }); 76 | 77 | // it('returns an array of ToDos', () => { 78 | // const newToDo = new ToDo('Create New ToDo'); 79 | // const builtToDo = buildToDo(newToDo, 0); 80 | // expect(buildToDos([])).toEqual([]); 81 | // expect(buildToDos([newToDo])).toEqual([builtToDo]); 82 | // }); 83 | // }); 84 | 85 | // describe('addToDo function', () => { 86 | // it('is a function', () => { 87 | // expect(typeof addToDo).toBe('function'); 88 | // }); 89 | 90 | // it('adds a ToDo to the toDoItems array', () => { 91 | // document.querySelector('#toDoInput').value = 'Create new ToDo'; 92 | // addToDo(); 93 | // expect(toDoItems.length).toBeGreaterThan(0); 94 | // }); 95 | // }); 96 | 97 | // describe('completeToDo function', () => { 98 | // it('is a function', () => { 99 | // expect(typeof completeToDo).toBe('function'); 100 | // }); 101 | 102 | // it('marks an item in the toDoItems array as complete', () => { 103 | // const e = { target: { id: 1 } }; 104 | // toDoItems.push(new ToDo('Create new toDo')); 105 | // completeToDo(e); 106 | // expect(toDoItems[1].complete).toBeTrue; 107 | // }); 108 | // }); 109 | -------------------------------------------------------------------------------- /Lesson10-JS-VII/README.md: -------------------------------------------------------------------------------- 1 | # Lesson 10: Javascript VII (Closure) 2 | (Attention: These are the class notes for the [Lambda School](http://www.lambdaschool.com) pre-course instruction workshop. This is meant to serve as an accompaniment to the class) 3 | 4 | In this lesson we will cover: 5 | 6 | * Closure 7 | 8 | ## Closure 9 | 10 | In JavaScript functions are first-class objects. What this means is that we can use functions in a very flexible manner. You've already seen how we can assign functions to variables: 11 | 12 | ```javascript 13 | const foo = function() {}; 14 | ``` 15 | 16 | We can put functions on objects: 17 | 18 | ```javascript 19 | const obj = {}; 20 | obj.foo = function() {}; 21 | ``` 22 | 23 | We can put functions in arrays: 24 | 25 | ```javascript 26 | const functions = [ 27 | function() {}, 28 | function() {}, 29 | ]; 30 | ``` 31 | 32 | We can pass functions into other functions (these are called callback functions): 33 | 34 | ```javascript 35 | function foo(cb) { 36 | cb(); 37 | } 38 | 39 | foo(function() { 40 | console.log('I am a callback function!'); 41 | }); 42 | ``` 43 | 44 | And finally, we can return a function definition from a function: 45 | 46 | ```javascript 47 | function outer() { 48 | return function() { 49 | console.log('hi!'); 50 | }; 51 | } 52 | 53 | const inner = outer(); 54 | inner(); // logs 'hi' 55 | ``` 56 | 57 | The function that retuns the new function is called a "Higher Order Function" or HOF. The idea of closure is simply that `inner` that's defined up above is able to look back into `outer` for variables that it needs. It's scope chain is going to look inside of `outer` before it looks at the global scope. 58 | 59 | Here's another example: 60 | 61 | ```javascript 62 | function outer() { 63 | const name = 'Ben'; 64 | return function() { 65 | console.log(name); 66 | }; 67 | } 68 | const name = 'Dan'; 69 | const inner = outer(); 70 | inner(); // logs 'Ben' 71 | ``` 72 | 73 | As you can see from the example above the function `inner` is able to look back into `outer`'s scope to retrieve the `name` variable. 74 | It looks inside of `outer` before it checks the global scope so the name that is printed is `'Ben'` instead of `'Dan'`. 75 | 76 | This also applies to the function's parameters: 77 | 78 | ```javascript 79 | function makeMultiplier(x) { 80 | return function(y) { 81 | return x * y; 82 | } 83 | } 84 | 85 | const multiplyByFive = makeMultiplier(5); 86 | const product1 = multiplyByFive(10); 87 | 88 | const multiplyByTwo = makeMultiplier(5); 89 | const product2 = multiplyByTwo(7); 90 | 91 | console.log(product1); // logs 50 92 | console.log(product2); // logs 14 93 | ``` 94 | 95 | In the example above the `x` and the `y` are both set by their respective function calls. This can be used in many interesting ways. You can make cache functions, private variables, and you can customize a function's behavior as we did in the example above. We are able to produce a custom multiplication function. 96 | 97 | 98 | ## Additional Resources: 99 | 100 | * [Eloquent Javascript: Higher Order Functions](https://eloquentjavascript.net/05_higher_order.html) 101 | * [Understand Closures with Ease](http://javascriptissexy.com/understand-javascript-closures-with-ease/) 102 | * [MDN: Closure](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Closures) 103 | -------------------------------------------------------------------------------- /Lesson07-JS-IV/homework/homework.js: -------------------------------------------------------------------------------- 1 | // Do not change any of the function names 2 | 3 | function makeCat(name, age) { 4 | // create a new object with a name property with the value set to the name argument 5 | // add an age property to the object with the value set to the age argument 6 | // add a method called meow that returns the string 'Meow!' 7 | // return the object 8 | } 9 | 10 | function addProperty(object, property) { 11 | // add the property to the object with a value of null 12 | // return the object 13 | // note: the property name is NOT 'property'. The name is the value of the argument called property (a string) 14 | } 15 | 16 | function invokeMethod(object, method) { 17 | // method is a string that contains the name of a method on the object 18 | // invoke this method 19 | // nothing needs to be returned 20 | } 21 | 22 | function multiplyMysteryNumberByFive(mysteryNumberObject) { 23 | // mysteryNumberObject has a property called mysteryNumber 24 | // multiply the mysteryNumber property by 5 and return the product 25 | } 26 | 27 | function deleteProperty(object, property) { 28 | // remove the property from the object 29 | // return the object 30 | } 31 | 32 | function newUser(name, email, password) { 33 | // create a new object with properties matching the arguments passed in. 34 | // return the new object 35 | } 36 | 37 | function hasEmail(user) { 38 | // return true if the user has a value for the property 'email' 39 | // otherwise return false 40 | } 41 | 42 | function hasProperty(object, property) { 43 | // return true if the object has the value of the property argument 44 | // property is a string 45 | // otherwise return false 46 | } 47 | 48 | function verifyPassword(user, password) { 49 | // check to see if the provided password matches the password property on the user object 50 | // return true if they match 51 | // otherwise return false 52 | } 53 | 54 | function updatePassword(user, newPassword) { 55 | // replace the existing password on the user object with the value of newPassword 56 | // return the object 57 | } 58 | 59 | function addFriend(user, newFriend) { 60 | // user has a property called friends that is an array 61 | // add newFriend to the end of the friends array 62 | // return the user object 63 | } 64 | 65 | function setUsersToPremium(users) { 66 | // users is an array of user objects. 67 | // each user object has the property 'isPremium' 68 | // set each user's isPremium property to true 69 | // return the users array 70 | } 71 | 72 | function sumUserPostLikes(user) { 73 | // user has an array property called 'posts' 74 | // posts is an array of post objects 75 | // each post object has an integer property called 'likes' 76 | // sum together the likes from all the post objects 77 | // return the sum 78 | } 79 | 80 | function addCalculateDiscountPriceMethod(storeItem) { 81 | // add a method to the storeItem object called 'calculateDiscountPrice' 82 | // this method should multiply the storeItem's 'price' and 'discountPercentage' to get the discount 83 | // the method then subtracts the discount from the price and returns the discounted price 84 | // return storeItem at the end of the function 85 | // example: 86 | // price -> 20 87 | // discountPercentage -> .2 88 | // discountPrice = 20 - (20 * .2) 89 | } 90 | 91 | // Do not modify code below this line. 92 | // -------------------------------- 93 | 94 | module.exports = { 95 | makeCat, 96 | addProperty, 97 | invokeMethod, 98 | multiplyMysteryNumberByFive, 99 | deleteProperty, 100 | newUser, 101 | hasEmail, 102 | hasProperty, 103 | verifyPassword, 104 | updatePassword, 105 | addFriend, 106 | setUsersToPremium, 107 | sumUserPostLikes, 108 | addCalculateDiscountPriceMethod, 109 | }; 110 | -------------------------------------------------------------------------------- /Lesson05-JS-II/homework/tests/JSII.test.js: -------------------------------------------------------------------------------- 1 | /* eslint-disable no-undef */ 2 | const { 3 | getBiggest, 4 | greeting, 5 | isTenOrFive, 6 | isInRange, 7 | isInteger, 8 | fizzBuzz, 9 | isPrime, 10 | } = require('../homework'); 11 | 12 | describe('getBiggest(x, y)', function() { 13 | it('should return x if it is larger than y', function() { 14 | expect(getBiggest(10, 5)).toBe(10); 15 | }); 16 | it('should return y if it is larger than x', function() { 17 | expect(getBiggest(50, 100)).toBe(100); 18 | }); 19 | it('should return either one if they are the same', function() { 20 | expect(getBiggest(1000, 1000)).toBe(1000); 21 | }); 22 | }); 23 | 24 | describe('greeting(language)', function() { 25 | it('should return \'Guten Tag!\' for German', function() { 26 | expect(greeting('German')).toBe('Guten Tag!'); 27 | }); 28 | it('should return \'Hola!\' for Spanish', function() { 29 | expect(greeting('Spanish')).toBe('Hola!'); 30 | }); 31 | it('should return \'Ni Hao!\' for Mandarin', function() { 32 | expect(greeting('Mandarin')).toBe('Ni Hao!'); 33 | }); 34 | it('should return \'Hello!\' if no argument is passed in or if a language beyond Spanish, English, and German is passed in.', function() { 35 | expect(greeting('French')).toBe('Hello!'); 36 | expect(greeting()).toBe('Hello!'); 37 | }); 38 | }); 39 | 40 | describe('isTenOrFive(num)', function() { 41 | it('should return true if num is 10 or 5', function() { 42 | expect(isTenOrFive(10)).toBe(true); 43 | expect(isTenOrFive(5)).toBe(true); 44 | }); 45 | it('should return false if num is not 10 or 5', function() { 46 | expect(isTenOrFive(11)).toBe(false); 47 | expect(isTenOrFive(6)).toBe(false); 48 | expect(isTenOrFive(0)).toBe(false); 49 | expect(isTenOrFive(5.01)).toBe(false); 50 | }); 51 | }); 52 | 53 | describe('isInRange(num)', function() { 54 | it('should return true if num is inside range', function() { 55 | expect(isInRange(35.5)).toBe(true); 56 | expect(isInRange(40)).toBe(true); 57 | expect(isInRange(49)).toBe(true); 58 | expect(isInRange(21)).toBe(true); 59 | }); 60 | it('should return false if outside of range', function() { 61 | expect(isInRange(10)).toBe(false); 62 | expect(isInRange(20)).toBe(false); 63 | expect(isInRange(50)).toBe(false); 64 | expect(isInRange(100)).toBe(false); 65 | }); 66 | }); 67 | 68 | describe('isInteger(num)', function() { 69 | it('should return true if num is 5', function() { 70 | expect(isInteger(5)).toBe(true); 71 | }); 72 | it('should return false if num is 0.5', function() { 73 | expect(isInteger(0.5)).toBe(false); 74 | }); 75 | it('should return true if num is -20', function() { 76 | expect(isInteger(-20)).toBe(true); 77 | }); 78 | it('should return true for 0', function() { 79 | expect(isInteger(0)).toBe(true); 80 | }); 81 | }); 82 | 83 | describe('fizzBuzz(num)', function() { 84 | it('should return fizz if divisible by 3', function() { 85 | expect(fizzBuzz(9)).toBe('fizz'); 86 | }); 87 | it('should return buzz if divisible by 5', function() { 88 | expect(fizzBuzz(10)).toBe('buzz'); 89 | }); 90 | it('should return fizzbuzz if divisible by 3 and 5', function() { 91 | expect(fizzBuzz(15)).toBe('fizzbuzz'); 92 | }); 93 | it('should return num if not divisible by 3 or 5', function() { 94 | expect(fizzBuzz(4)).toBe(4); 95 | }); 96 | }); 97 | 98 | describe('isPrime(num)', function() { 99 | it('should return true if num is prime', function() { 100 | expect(isPrime(7)).toBe(true); 101 | expect(isPrime(97)).toBe(true); 102 | }); 103 | it('should return false if num is not prime', function() { 104 | expect(isPrime(10)).toBe(false); 105 | expect(isPrime(100)).toBe(false); 106 | expect(isPrime(0)).toBe(false); 107 | expect(isPrime(1)).toBe(false); 108 | }); 109 | }); 110 | -------------------------------------------------------------------------------- /Lesson08-JS-V/README.md: -------------------------------------------------------------------------------- 1 | # Lesson 8: Javascript V (Classes and Prototype) 2 | (Attention: These are the class notes for the [Lambda School](http://www.lambdaschool.com) pre-course instruction workshop. This is meant to serve as an accompaniment to the class) 3 | 4 | In this lesson we will cover: 5 | 6 | * Classes 7 | * `prototype` 8 | 9 | ## Classes 10 | 11 | Often times when we create an object, we are creating a template. Rather than copy that template over and over again, Javascript gives us access to what we call a constructor or `class`. Classes share much of the same functionality as regular objects, but also expands on that functionality greatly. Classes are useful for creating many objects that share some of the same properties and methods (such as users on a website). 12 | 13 | ### Class and Pseudo Classical Instantiation 14 | 15 | If you have experience in an Object Oriented language (such as Java or C#) you are probably familiar with the concept of classes. While Javascript does not provide a 'true' class system, there is something very familiar. For the sake of argument we will call our class objects 'classes'. It is instantiated in a Pseudo Classical way, using the `new` keyword, and can take arguments. 16 | 17 | In this example we will be creating a `Cat` class. Convention for classes is to give the name of anything that can be instantiated with the `new` keyword an uppercase name. When we use the `new` keyword, Javascript does some great behind the scenes work for us and creates and returns an object automatically. 18 | 19 | ```javascript 20 | function Cat(name) { 21 | // the new operator creates an object, 'this' 22 | this.name = name; 23 | this.meows = function() { 24 | return 'My name is ' + this.name + ' ...Meow!'; 25 | } 26 | // return the object 'this' 27 | } 28 | 29 | const sam = new Cat('Sam'); 30 | const kitty = new Cat('Kitty'); 31 | console.log(sam.meows()); // 'My name is Sam ...Meow!' 32 | console.log(kitty.meows()); // 'My name is Kitty ...Meow!' 33 | 34 | ``` 35 | 36 | ### `this` in Classes 37 | 38 | The `this` keyword can start to become very confusing when we start using it in classes. In the last example we use it in the meows method. A good rule of thumb if you are not certain what `this` is referring to, is to look at where the method is called, and the object to the left of the 'dot'. That is the object `this` refers to. 39 | 40 | ## Prototype 41 | 42 | Creating functions are expensive (in a computer memory way) and each time we create a new class object with methods we are recreating those methods in memory. You can imagine if you are creating thousands of class objects from a class with dozens of methods on it, the memory will add up quickly (20,000-40,000 methods). Classes have a unique way of setting a method once and giving every object of that class access to those methods. This is called the `prototype`. Each class has a prototype property, which we can then set methods on: 43 | 44 | ```javascript 45 | function User(name, github) { 46 | this.name = name; 47 | this.github = github; 48 | } 49 | 50 | User.prototype.introduction = function(){ 51 | return 'My name is ' + this.name + ', my github handle is ' + this.github + '.'; 52 | } 53 | 54 | let dan = new User('Dan', 'tetondan'); 55 | let riley = new Cat('Riley', 'rileyriley'); 56 | 57 | console.log(dan.introduction()); // My name is Dan, my github handle is tetondan. 58 | console.log(riley.introduction()); // My name is Riley, my github handle is rileyriley. 59 | 60 | ``` 61 | Protoype methods DO have access to the `this` keyword, and just as before, it will always point to the object (left of the dot) that is calling it. 62 | 63 | ## Please open the homework folder and complete the assignment described in the README file 64 | 65 | ## Additional Resources: 66 | 67 | * [MDN: Classes](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Classes) 68 | * [MDN: Prototype](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object/prototype) -------------------------------------------------------------------------------- /Lesson06-JS-III/homework/tests/JSIII.test.js: -------------------------------------------------------------------------------- 1 | /* eslint-disable no-undef */ 2 | const { 3 | returnFirst, 4 | returnLast, 5 | getArrayLength, 6 | incrementByOne, 7 | addItemToArray, 8 | addItemToFront, 9 | wordsToSentence, 10 | contains, 11 | addNumbers, 12 | averageTestScore, 13 | largestNumber, 14 | multiplyArguments 15 | } = require('../homework'); 16 | 17 | describe('returnFirst(arr)', function() { 18 | it('should return the first item in the array', function() { 19 | expect(returnFirst([10, 10, 16, 12])).toBe(10); 20 | expect(returnFirst([97, 100, 80, 55, 72, 94])).toBe(97); 21 | }); 22 | }); 23 | 24 | describe('returnLast(arr)', function() { 25 | it('should return the last item in the array', function() { 26 | expect(returnLast([10, 10, 16, 12])).toBe(12); 27 | expect(returnLast([97, 100, 80, 55, 72, 94])).toBe(94); 28 | expect(returnLast(['hi', 'there', 'how', 'are', 'you', 'doing?'])).toBe('doing?'); 29 | }); 30 | }); 31 | 32 | describe('getArrayLength(arr)', function() { 33 | it('should return the length of the array', function() { 34 | expect(getArrayLength([10, 10, 16, 12])).toBe(4); 35 | expect(getArrayLength([97, 100, 80, 55, 72, 94])).toBe(6); 36 | expect(getArrayLength(['hi', 'there', 'how', 'are', 'you', 'doing?'])).toBe(6); 37 | }); 38 | }); 39 | 40 | describe('incrementByOne(arr)', function() { 41 | it('should return the array with each value incremented by one', function() { 42 | expect(incrementByOne([10, 10, 16, 12])).toEqual([11, 11, 17, 13]); 43 | expect(incrementByOne([97, 100, 80, 55, 72, 94])).toEqual([98, 101, 81, 56, 73, 95]); 44 | expect(incrementByOne([])).toEqual([]); 45 | }); 46 | }); 47 | 48 | describe('addItemToArray(arr, item)', function() { 49 | it('should return the array with the item added to the end', function() { 50 | expect(addItemToArray([10, 10, 16, 12], 10)).toEqual([10, 10, 16, 12, 10]); 51 | expect(addItemToArray([97, 100, 80, 55, 72, 94], 'Hello')).toEqual([97, 100, 80, 55, 72, 94, 'Hello']); 52 | expect(addItemToArray([], true)).toEqual([true]); 53 | }); 54 | }); 55 | 56 | describe('addItemToFront(arr, item)', function() { 57 | it('should return the array with the item added to the front', function() { 58 | expect(addItemToFront([10, 10, 16, 12], 10)).toEqual([10, 10, 10, 16, 12]); 59 | expect(addItemToFront([97, 100, 80, 55, 72, 94], 'Hello')).toEqual(['Hello', 97, 100, 80, 55, 72, 94]); 60 | expect(addItemToFront([], true)).toEqual([true]); 61 | }); 62 | }); 63 | 64 | describe('wordsToSentence(words)', function() { 65 | it('should return a string that has all of the words from the array separated by spaces', function() { 66 | expect(wordsToSentence(['LambdaSchool', 'JavaScript', 'Class'])).toBe('LambdaSchool JavaScript Class'); 67 | expect(wordsToSentence(['LambdaSchool'])).toBe('LambdaSchool'); 68 | }); 69 | }); 70 | 71 | describe('contains(arr, item)', function() { 72 | it('should return true if the array contains the item', function() { 73 | expect(contains([10, 10, 16, 12], 10)).toBe(true); 74 | expect(contains([97, 100, 80, 55, 72, 94], 'Hello')).toBe(false); 75 | expect(contains([], true)).toBe(false); 76 | }); 77 | }); 78 | 79 | describe('addNumbers(numbers)', function() { 80 | it('should add all of the numbers in the array together and return the sum', function() { 81 | expect(addNumbers([10, 10, 16])).toBe(36); 82 | expect(addNumbers([97, 100])).toBe(197); 83 | expect(addNumbers([0])).toBe(0); 84 | }); 85 | }); 86 | 87 | describe('averageTestScore(testScores)', function() { 88 | it('should return the average test score', function() { 89 | expect(averageTestScore([10, 10, 16, 12])).toBe(12); 90 | expect(averageTestScore([97, 100, 80, 55, 72, 94])).toBe(83); 91 | }); 92 | }); 93 | 94 | describe('largestNumber(numbers)', function() { 95 | it('should return the largest number', function() { 96 | expect(largestNumber([10, 10, 16, 12])).toBe(16); 97 | expect(largestNumber([97, 100, 80, 55, 72, 94])).toBe(100); 98 | expect(largestNumber([97, 10000, 80, 55, 7.2, -94])).toBe(10000); 99 | }); 100 | }); 101 | 102 | describe('multiplyArguments()', function () { 103 | it('should return the product of all the arguments', function () { 104 | const product = multiplyArguments(5, 5); 105 | const product2 = multiplyArguments(); 106 | const product3 = multiplyArguments(3, 3, 3, 3); 107 | const product4 = multiplyArguments(1); 108 | const product5 = multiplyArguments(10, 0, 10); 109 | expect(product).toBe(25); 110 | expect(product2).toBe(0); 111 | expect(product3).toBe(81); 112 | expect(product4).toBe(1); 113 | expect(product5).toBe(0); 114 | }); 115 | }); 116 | 117 | -------------------------------------------------------------------------------- /Lesson04-JS-I/homework/homework.js: -------------------------------------------------------------------------------- 1 | //In these first 6 questions, replace `null` with the answer 2 | 3 | //create a string variable, it can contain anything 4 | const newString = null ; 5 | 6 | //create a number variable, it an be any number 7 | const newNum = null ; 8 | 9 | //create a boolean variable 10 | const newBool = null ; 11 | 12 | //solve the following math problem 13 | const newSubtract = 10 - null === 5; 14 | 15 | //Solve the following math problem 16 | const newMultiply = 10 * null === 40 ; 17 | 18 | //Solve the following math problem: 19 | const newModulo = 21 % 5 === null ; 20 | 21 | 22 | 23 | //In the next 22 problems you will compete the function. All of your code will go inside of the function braces. 24 | //Make sure you use return when the prompt asks you to. 25 | //hint: console.log() will NOT work. 26 | //Do not change any of the function names 27 | 28 | function returnString(str) { 29 | //simply return the string provided: str 30 | } 31 | 32 | function add(x, y) { 33 | // x and y are numbers 34 | // add x and y together and return the value 35 | // code here 36 | } 37 | 38 | function subtract(x, y) { 39 | // subtract y from x and return the value 40 | // code here 41 | } 42 | 43 | function multiply(x, y) { 44 | // multiply x by y and return the value 45 | // code here 46 | } 47 | 48 | function divide(x, y) { 49 | // divide x by y and return the value 50 | // code here 51 | } 52 | 53 | function areEqual(x, y) { 54 | // return true if x and y are the same 55 | // otherwise return false 56 | // code here 57 | } 58 | 59 | function areSameLength(str1, str2) { 60 | // return true if the two strings have the same length 61 | // otherwise return false 62 | // code here 63 | } 64 | 65 | function lessThanNinety(num) { 66 | // return true if the function argument: num , is less than ninety 67 | // otherwise return false 68 | // code here 69 | } 70 | 71 | function greaterThanFifty(num) { 72 | // return true if num is greater than fifty 73 | // otherwise return false 74 | // code here 75 | } 76 | 77 | function getRemainder(x, y) { 78 | // return the remainder from dividing x by y 79 | // code here 80 | } 81 | 82 | function isEven(num) { 83 | // return true if num is even 84 | // otherwise return false 85 | // code here 86 | } 87 | 88 | function isOdd(num) { 89 | // return true if num is odd 90 | // otherwise return false 91 | // code here 92 | } 93 | 94 | function square(num) { 95 | // square num and return the new value 96 | // hint: NOT square root! 97 | // code here 98 | } 99 | 100 | function cube(num) { 101 | // cube num and return the new value 102 | // code here 103 | } 104 | 105 | function raiseToPower(num, exponent) { 106 | // raise num to whatever power is passed in as exponent 107 | // code here 108 | } 109 | 110 | function roundNumber(num) { 111 | // round num and return it 112 | // code here 113 | } 114 | 115 | function roundUp(num) { 116 | // round num up and return it 117 | // code here 118 | } 119 | 120 | function addExclamationPoint(str) { 121 | // add an exclamation point to the end of str and return the new string 122 | // 'hello world' -> 'hello world!' 123 | // code here 124 | } 125 | 126 | function combineNames(firstName, lastName) { 127 | // return firstName and lastName combined as one string and separated by a space. 128 | // 'Lambda', 'School' -> 'Lambda School' 129 | // code here 130 | } 131 | 132 | function getGreeting(name) { 133 | // Take the name string and concatenate other strings onto it so it takes the following form: 134 | // 'Sam' -> 'Hello Sam!' 135 | // code here 136 | } 137 | 138 | // The next three questions will have you implement math area formulas. 139 | // If you can't remember these area formulas then head over to Google. 140 | 141 | function getRectangleArea(length, width) { 142 | // return the area of the rectangle by using length and width 143 | // code here 144 | } 145 | 146 | function getTriangleArea(base, height) { 147 | // return the area of the triangle by using base and height 148 | // code here 149 | } 150 | 151 | // Do not modify code below this line. 152 | // -------------------------------- 153 | 154 | module.exports = { 155 | newString, 156 | newNum, 157 | newBool, 158 | newSubtract, 159 | newMultiply, 160 | newModulo, 161 | returnString, 162 | areSameLength, 163 | areEqual, 164 | lessThanNinety, 165 | greaterThanFifty, 166 | add, 167 | subtract, 168 | divide, 169 | multiply, 170 | getRemainder, 171 | isEven, 172 | isOdd, 173 | square, 174 | cube, 175 | raiseToPower, 176 | roundNumber, 177 | roundUp, 178 | addExclamationPoint, 179 | combineNames, 180 | getGreeting, 181 | getRectangleArea, 182 | getTriangleArea, 183 | }; 184 | -------------------------------------------------------------------------------- /Lesson09-JS-VI/README.md: -------------------------------------------------------------------------------- 1 | # Lesson 9: Javascript VI (Callbacks) 2 | (Attention: These are the class notes for the [Lambda School](http://www.lambdaschool.com) pre-course instruction workshop. This is meant to serve as an accompaniment to the class) 3 | 4 | In this lesson we will cover: 5 | 6 | * Callbacks 7 | * More Array Methods 8 | 9 | ## Callbacks 10 | 11 | A very important concept in Javascript is the ability to pass a function as an arguments to another function. These functions are called `callbacks`. These functions can be called anytime and passed arguments within the function. We will soon discover why callbacks are so important to Javascript. Convention is to use the `cb` argument variable as your callback. 12 | 13 | ```javascript 14 | function saysHelloToUser(user) { 15 | return 'Hello ' + user + '!'; 16 | } 17 | 18 | function saysGoodbyeToUser(user) { 19 | return 'Goodbye ' + user + '!'; 20 | } 21 | 22 | function createGreeting(user, cb) { 23 | return cb(user); 24 | } 25 | 26 | createGreeting('Dan', saysHelloToUser); // 'Hello Dan!' 27 | createGreeting('Dan', saysGoodbyeToUser); // 'Goodbye Dan!' 28 | ``` 29 | 30 | ## More Array Methods 31 | 32 | We already know about and use array methods, `.push`, `.pop`, `.shift`, `.unshift`, and `.length`. But there are a lot more methods available to us natively on an array. The methods we are going to talk about here are called higher order methods, because they take callbacks as arguments. 33 | 34 | ### .forEach 35 | 36 | `.forEach` is a built in for loop on every array. `.forEach` takes a callback as its only argument, and iterates over every item in the array and calls the callback on it. The callback can take two arguments, the first is the item itself, the second is the index of the item, this argument is optional. 37 | 38 | ```javascript 39 | const cars = ['Ford', 'Chevrolet', 'Toyota', 'Tesla']; 40 | 41 | // We can write the callback function itself in the parentheses as an anonymous function 42 | cars.forEach(function(item, index) { 43 | console.log(item); 44 | }); 45 | 46 | // Or we can instantiate a function to be used as a callback. 47 | // Also, we do not need to use the index argument, if you don’t need it, feel free to leave it out. 48 | function printNames(item) { 49 | console.log(item); 50 | } 51 | 52 | // And call that function in the forEach parentheses 53 | cars.forEach(printNames); 54 | ``` 55 | 56 | ### .reduce 57 | 58 | `.reduce` will run a loop on our array with the intention of reducing each item into one item that is returned. As it's first argument it takes a callback that takes two arguments, first an 'accumulator' (the result of the reduce method until now), and the second is the item it is currently on. The callback must ALWAYS contain a return statement. Reduce also takes an optional second argument, which would be the starting accumulator. If the starting accumulator is not supplied reduce will start at the first item of the array. `.reduce` will always return the accumulator when it is done iterating through the items. 59 | 60 | ```javascript 61 | const nums = [ 1, 2, 3, 4, 5, 6, 7, 8, 9]; 62 | const words = [ 'Hi,', 'my', 'name', 'is', 'Dan']; 63 | 64 | // We can write the anonymous function directly into the .reduce parentheses 65 | // If we leave out the starting item, it will always start at the first item. 66 | const sums = nums.reduce(function(acc, item){ 67 | return acc + item; 68 | }); 69 | 70 | // We can write a function outside of the .reduce parens (to be used multiple times later) 71 | function multiplyTwoNumbers(a, b) { 72 | return a * b; 73 | } 74 | const products = nums.reduce(multiplyTwoNumbers); 75 | 76 | // .reduce works on any data types. 77 | // In this example we set a starting accumulator 78 | const sentence = words.reduce(function(acc, item) { 79 | return acc + ' ' + item; 80 | }, 'Sentence:'); 81 | 82 | console.log(sums); // 45 83 | console.log(products); // 362880 84 | console.log(sentence); // 'Sentence: Hi, my name is Dan' 85 | ``` 86 | ### .map 87 | 88 | `.map` is used when we want to change every item in an array in the same way. `.map` takes a callback as its only argument. Like the `.forEach` method, the callback has the optional arguments item and index. Unlike `.reduce`, `.map` will return the entire array. 89 | 90 | ```javascript 91 | const nums = [2, 3, 4, 5]; 92 | 93 | function multiplyByThree(item) { 94 | return item * 3; 95 | } 96 | 97 | 98 | const double = nums.map(function(item) { 99 | return item * 2; 100 | }); 101 | 102 | const triple = nums.map(multiplyByThree) 103 | 104 | console.log(double); // [ 4, 6, 8, 10 ] 105 | console.log(triple); // [ 6, 9, 12, 15 ] 106 | ``` 107 | 108 | ## Please open the homework folder and complete the assignment described in the README file 109 | 110 | ## Additional Resources: 111 | 112 | * [Understanding Callback Functions and How to Use Them](http://javascriptissexy.com/understand-javascript-callback-functions-and-use-them/) 113 | * [Eloquent Javascript: Higher Order Functions](https://eloquentjavascript.net/05_higher_order.html) 114 | * [MDN: Callback function](https://developer.mozilla.org/en-US/docs/Glossary/Callback_function) 115 | * [MDN: Array methods](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array) 116 | -------------------------------------------------------------------------------- /Lesson03-CSS-Positioning/homework/homework.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | CSS Postioning Homework. 5 | 6 | 7 | 8 | 9 |

This is where the title of the lesson will go. Remove This.

10 |

CSS Postioning Homework

11 |
12 |

Instructions:

13 | 14 | In this assignment we are going to use the display, position, and flex box properties 15 | to position our elements correctly on the page. Please put all of your CSS in the CSS 16 | file "homework.css". "homework.css" should be the only file you touch, if you find 17 | yourself altering the homework.html or dontTouch.css files, you are in the wrong area. 18 | You will need to use the class, id, and element selectors from lesson 2. 19 | 20 |
21 |
22 |

Exercise One:

23 | 24 | Your first exercise will be to make sure the text within this <span> is centered 25 | on the page. The id of this span is "exerciseOne". Text has a unique positioning system 26 | known as "text-align" we can set this to 'left', 'right', 'center', or 'justify'(stretches each 27 | line to fit the width of the container), but this only works for a block elements 28 | and <span> is initially an inline element. Set this span's display property to be 29 | a block element and center the text using text-align. 30 | 31 |
32 |
33 |

Exercise Two:

34 | 35 | There is a box at the top of the screen. That was just supposed to be a placeholder until 36 | we got the title of this lesson locked down. Unfortunately we do not have access to the HTML, 37 | so we can not manually remove it. Using CSS only, make sure the box is not displayed. 38 | The id is "exerciseTwo". 39 | 40 |
41 |
42 |

Exercise Three:

43 | 44 | Below you will see a box, inside of it is an image, we want to make the image appear in the red box. 45 | You will need to change the position attribute, and then adjust the image accordingly. The red box is 46 | 100px from the top and 200px from the left. The id of the image is "exerciseThree". 47 | 48 |
49 |
50 | 51 |
52 | This is an image of an animal, you can see the animal here. There are lot of animals in the world, and this is one of them. I hope you enjoy this image of an animal! 53 |
54 |
55 |
56 |
57 |

Exercise Four:

58 | 59 | The blue rectangular box below is supposed to be our header bar, it should be anchored to 60 | the upper left corner of the page, and should not move when the page is scrolled. The id for 61 | the box is "exerciseFour". Change the position, so that the box is in the upper left hand corner. 62 | 63 |
64 |
65 |
66 | Pre-Course Lessons 67 | 68 | Lambda School 69 |
70 |
71 |
72 |

Exercise Five:

73 | 74 | There are three items in the header bar, "Lambda School", the Lambda School logo, and 75 | "Pre-Course Lessons". Using the id of "exerciseFive", we will make the container they are in 76 | a flex box, we want to make sure that the space between each item is exactly the same, and we want 77 | each of the items to appear centered vertically on the line. 78 | 79 |
80 |
81 |

Exercise Six:

82 | 83 | Now that the items in the header bar are spaced properly, they are out of order. "Lambda School" 84 | should be on the left, and "Pre-Course Lessons" should be on the right. Using the same id from the last exercise, 85 | change the direction in which the items appear. 86 | 87 |
88 |
89 |

Exercise Seven:

90 | 91 | This is a flexbox playground, the id of it is "exerciseSeven". There is no final objective here, your 92 | objective is to play around with the different flex box options. The id's of the child elements are in them. 93 | Try using all of the flexbox ideas we have learned so far, including: justify-content, align-items, align-self, 94 | and flex-direction. Have fun! 95 | 96 |
97 |
98 |
This element's id is "itemOne"
99 |
This element's id is "itemTwo"
100 |
This element's id is "itemThree"
101 |
This element's id is "itemFour"
102 |
103 |
104 |

Extra Credit 1:

105 | 106 | There is a lot to flex box and it can become complicated, but through practice you can learn to quickly 107 | adjust the positioning of your elements with ease. I recommend completing the "Flexbox Froggy" tutorial, 108 | it will show you in depth how the flex box positioning system works: Flexbox Froggy 109 | 110 |
111 |
112 |

Extra Credit 2:

113 | 114 | A new, native, CSS grid system has been introduced. It is called css-grid and can be used to make 115 | positioning even faster and more precise. We will use css-grid in the full course, so it might be 116 | nice to familiarize yourself with it now: A Complete Guide to CSS Grid 117 | 118 | Also, from the makers of "Flexbox Froggy" comes CSS GridGarden! 119 | 120 |
121 | 122 | -------------------------------------------------------------------------------- /Lesson06-JS-III/README.md: -------------------------------------------------------------------------------- 1 | # Lesson 6: Javascript III (`for` Loops continued, and Arrays) 2 | (Attention: These are the class notes for the [Lambda School](http://www.lambdaschool.com) pre-course instruction workshop. This is meant to serve as an accompaniment to the class) 3 | 4 | In this lesson we will cover: 5 | 6 | * Introduction to arrays 7 | * `for` Loops with arrays 8 | 9 | ## Introduction to Arrays 10 | 11 | In the previous lesson we discussed the 3 basic data types (strings, numbers, and booleans), and how to assign those data types to variables. We discussed how a variable can only point to a single string, number, or boolean. In many cases though we want to be able to point to a collection of data types. For example what if we wanted to keep track of every student's name in this class using a single variable, `studentsNames`. We can do that using Arrays. We can think of arrays as storage containers for collections of data. Building an array is simple, declare a variable and set it to []. We can then add however many strings, numbers, or booleans as we want to the container (comma separated), and access those items whenever we want. 12 | 13 | ```javascript 14 | const studentsNames = ['Dan', 'Maria', 'Sara', 'Raj']; 15 | ``` 16 | 17 | ### .length 18 | 19 | Just like the String data type has a built in `.length` method, so does the array. In fact the array has a lot of useful built in methods (we will be discussing those in later lessons). Just like the string `.length` counts the characters, array `.length` will return the number of items in an array: 20 | 21 | ```javascript 22 | const studentsNames = ['Dan', 'Maria', 'Sara', 'Raj']; 23 | 24 | console.log(studentNames.length); // 4 25 | ``` 26 | 27 | ### Accessing Items in an Array 28 | 29 | We can access an item at anytime in an array, we just need to call the item by its position in the array. Items are given a numerical position (index) according to where it is in the array, in order. An array's numerical order ALWAYS starts at 0, so the first item is in the 0 index, the second in the 1 index, the third in the 2, and so on (this can be tricky at first, but just remember arrays always start at 0). 30 | 31 | ```javascript 32 | const studentsNames = ['Dan', 'Maria', 'Sara', 'Raj']; 33 | 0 1 2 3 34 | ``` 35 | 36 | In order to access the item, we will type the name or the array variable, followed by brackets containing the numerical assignment. 37 | 38 | ```javascript 39 | const studentsNames = ['Dan', 'Maria', 'Sara', 'Raj']; 40 | 41 | console.log(studentNames[1]); // 'Maria' 42 | ``` 43 | 44 | To dynamically access the last item in the array, we will use the `.length` method. In our `studentsNames` array, the length is 4. We know the first item is always going to be 0, and every item after is shifted over one number. So in our example the last item has an index of 3. Using our length property we will show how it is done when we don't know the number of items in an array: 45 | 46 | ```javascript 47 | const studentsNames = ['Dan', 'Maria', 'Sara', ... ,'Raj']; 48 | 49 | console.log(studentNames[studentNames.length - 1]); // 'Raj' 50 | ``` 51 | 52 | ### Assignment 53 | 54 | We can assign and reassign any index in the array using the bracket/index and an =. 55 | 56 | ```javascript 57 | const studentsNames = ['Dan', 'Maria', 'Sara', 'Raj']; 58 | 59 | studentNames[0] = 'Ryan'; 60 | 61 | console.log(studentNames); // ['Ryan', 'Maria', 'Sara', 'Raj'] 62 | ``` 63 | ### .push & .pop 64 | 65 | Two more very useful built in array methods are `.push` and `.pop`. These methods refer to the adding and removing of items from the array after it's initial declaration. 66 | 67 | `.push` adds an item to the end of the array, incrementing it's length by 1. (`.push` returns the new length) 68 | 69 | ```javascript 70 | const studentsNames = ['Dan', 'Maria', 'Sara', 'Raj']; 71 | 72 | studentNames.push('Ryan'); 73 | 74 | console.log(studentNames); // ['Dan', 'Maria', 'Sara', 'Raj', 'Ryan'] 75 | ``` 76 | 77 | `.pop` removes the last item in the array, decrementing the length by 1. (`.pop` returns the "popped" item) 78 | 79 | ```javascript 80 | const studentsNames = ['Dan', 'Maria', 'Sara', 'Raj']; 81 | 82 | studentNames.pop(); 83 | 84 | console.log(studentNames); // ['Dan', 'Maria', 'Sara'] 85 | ``` 86 | 87 | ### .unshift & .shift 88 | 89 | `.unshift` and `.shift` are exactly like `.push` and `.pop`, except they operate on the first item in the array. `.unshift(item)` will put a new item in the first position of the array, and `.shift()` will remove the first item in the array. 90 | 91 | ```javascript 92 | const studentsNames = ['Dan', 'Maria', 'Sara', 'Raj']; 93 | 94 | studentNames.unshift('Ryan'); 95 | 96 | console.log(studentNames); // ['Ryan', 'Dan', 'Maria', 'Sara', 'Raj'] 97 | 98 | studentNames.shift(); 99 | 100 | console.log(studentNames); // ['Dan', 'Maria', 'Sara', 'Raj'] 101 | ``` 102 | 103 | ### Notes on Arrays 104 | 105 | Because Javascript is not a strongly typed language, arrays do not need to be typed either. Arrays in Javascript can contains multiple different data types in the same array. 106 | 107 | ## for Loops 108 | 109 | Most of the time, for loops are used to iterate over all of the items in an array. Using the index access technique we can access each item in the array. To do this, we use the `.length` method as the stopping point for the loop. 110 | 111 | ```javascript 112 | const studentsNames = ['Dan', 'Maria', 'Sara', 'Raj']; 113 | 114 | for (let i = 0; i < studentNames.length; i++) { 115 | console.log(studentNames[i]); 116 | } 117 | 118 | // 'Dan' 119 | // 'Maria' 120 | // 'Sara' 121 | // 'Raj' 122 | ``` 123 | 124 | ## Arguments object 125 | 126 | When we pass arguments to a function they are contained in an array-like data structure called `arguments`. `arguments` is available to us anywhere within the function and contains all of the arguments passed to it. While it is array like, it does not have all of the properties of an array. One property it does have is the method `.length`. When we are given a function with an unknown number of arguments, we can use `.length` and a `for` loop to iterate over all of the arguments: 127 | 128 | ```javascript 129 | function sumAllTheNumbers() { 130 | let sum = 0; 131 | 132 | for (let i = 0; i < arguments.length; i++) { 133 | sum = sum + arguments[i]; 134 | } 135 | 136 | return sum; 137 | } 138 | 139 | sumAllTheNumbers(2, 5, 3, 4, 7, 9, 1, 0, 7, 7, 7); // 52 140 | ``` 141 | 142 | ## Please open the homework folder and complete the assignment described in the README file 143 | 144 | ## Additional Resources 145 | 146 | * [MDN: Arrays](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array) 147 | * [MDN: for Loops](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Statements/for) 148 | -------------------------------------------------------------------------------- /Lesson12-DOM/homework/DOMhomework.js: -------------------------------------------------------------------------------- 1 | /* 2 | STEP 0: Create an empty array called 'toDoItems'. 3 | */ 4 | 5 | // code here 6 | 7 | /* 8 | STEP 1: There is a span element currently on the page with the innerHTML of 'This app was created by:', 9 | Using a querySelector, select the span by it's id ('createdBy'). Then using the innerHTML property, 10 | add your name to the END of the current innerHTML. 11 | */ 12 | 13 | // code here 14 | 15 | /* 16 | STEP 2: Create a class called 'ToDo'. The constructor should have one string parameter called description, the description of the toDo. 17 | Add two properties to the class: 'description' which should be set equal to the description passed to the constructor, and 18 | 'complete' which should be set to false. Hint: use the 'this' keyword in the constructor function. 19 | */ 20 | 21 | function ToDo () { 22 | // code here 23 | } 24 | 25 | /* 26 | STEP 3: Add a method called 'completeToDo' to the prototype of the ToDo class. 27 | It will not take any arguemnts. 28 | Inside the function set the ToDo's 'complete' property to true. 29 | */ 30 | 31 | // code here 32 | 33 | /* 34 | STEP 4: This function, buildToDo, will have two parameters. The first is an object of class ToDo and 35 | the second is a numerical index. 36 | 37 | Inside this function it should: 38 | 1.) Create a new 'div' element. Set this to a variable 'toDoShell'. 39 | 2.) Give 'toDoShell' a class (for CSS) of 'toDoShell'. 40 | 3.) Create a new 'span' element. Set this to a variable called 'toDoText'. 41 | 4.) Using the toDo item passed in, set the 'toDoText' innerHTML to the value of the 'description' property on the toDo object. 42 | 5.) Set the id of 'toDoText' to the value of the index argument. 43 | 6.) Using an if statement, check to see if the 'complete' property on the object passed as the first argument 44 | is set to true. If it is, give 'toDoText' a CSS class of 'completeText'. If it is not, do not give it a class. 45 | 7.) Append child 'toDoText' to 'toDoShell' 46 | 8.) return toDoShell 47 | */ 48 | 49 | function buildToDo(todo, index) { 50 | // code here 51 | } 52 | 53 | /* 54 | STEP 5: This function will build and return an array of toDo elements. It will take an array of objects of the ToDo class as it's only argument. 55 | Using the map method on the array passed in, use the 'buildToDo' function you wrote above as the callback passed to map. 56 | Return the new mapped array. 57 | */ 58 | 59 | function buildToDos(toDos) { 60 | // code here 61 | } 62 | 63 | /* 64 | STEP 6: Now that we can build an array of toDo elements, we want to make these elements appear on the screen, 65 | to do this we will create a 'displayToDos' function. 66 | 1.) Select the element with the id 'toDoContainer'. Save this to a variable: 'toDoContainer'. 67 | 2.) Set the innerHTML of 'toDoContainer' to an empty string. (This will let us refresh the elements, and display the new toDos) 68 | 3.) Using the buildToDos function pass it the array toDoItems as it's only argument. 69 | 4.) Using the result of (3), loop over the array appending each element to 'toDoContainer'. 70 | 5.) at the very end of this file, the line before the comment "DO NOT CHANGE ANY CODE BELOW THIS LINE", call this function. 71 | 72 | You can now load your html file in your broswer and see your work so far. 73 | */ 74 | 75 | function displayToDos() { 76 | // code here 77 | } 78 | 79 | /* 80 | STEP 7: This function, 'addToDo' will add a new ToDo to the 'toDoItems' array. 81 | NOTE: We have not learned about input HTML elements yet, so we will give you a little more code to go on here. 82 | 'newToDo' is an text input element. All text input elements have a property called 'value', this value will be whatever is typed into 83 | the text box on the page. 84 | 85 | 1.) Using the value property on 'newToDo', create an new ToDo object using the ToDo class and pass the value as the description. 86 | 2.) add the object from (1) into the toDoItems array. 87 | 3.) Set the value of newToDo to an empty string (this will clear the text in the box allowing the user to enter another item). 88 | 4.) Call displayToDos to refresh the toDos displayed 89 | */ 90 | 91 | function addToDo() { 92 | // code here 93 | } 94 | 95 | /* 96 | STEP 8: In this step we will fire addToDo everytime the 'ADD' button is clicked. 97 | 1.) Select the element with the id 'addButton' 98 | 2.) Add a 'click' event listener to this element, passing it the addToDo function as a callback 99 | */ 100 | 101 | // cod here 102 | 103 | /* 104 | STEP 9: Finally in this step we will define the function to run when we want to compelte a toDo, and add that function to the click event 105 | listener on the toDo element 106 | 107 | Note: We have not covered the argument every event listener receives, the 'event' object. There is a lot of data in this object, 108 | including event type, which element called it, what the values of that element are, etc. In this exercise we will use it to find the 109 | index of the item that called it. We have given you that code, study it to make sure you understand what is happening. 110 | 111 | 1.) Using the index supplied, call completeToDo on the item which called it from toDoItems. 112 | 2.) call displayToDos to refresh to items on the screen. 113 | 3.) In the 'buildToDo' function add a 'click' event listener to the 'toDoText' element, and pass this function as the callback. 114 | */ 115 | 116 | function completeToDo(event) { 117 | // UNCOMMENT THE NEXT LINE 118 | // const index = event.target.id; 119 | // code here 120 | } 121 | 122 | /* STEP 10: Make sure ALL tests pass */ 123 | 124 | 125 | // **********************************************EXTRA CREDIT:********************************************** // 126 | 127 | /* 1.) Research 'checkbox' input types. And apply that research to the buildToDo function: 128 | a.) Create a checkbox in the buildToDo function. A 129 | b.) Give the checkbox the id of the index, and remove the id of the index from toDoText 130 | c.) Give the checkbox the 'click' event listener of completeToDo, and remove the event listener from toDoText 131 | d.) Give the checkbox the class of 'completeCheckbox' 132 | e.) Inside of the current 'if' statement in the buildToDo function, if true, set the attribute, 'checked' to true on the checkbox. 133 | f.) Append this checkbox on the toDoShell element. 134 | */ 135 | // ********************************************** ----------- ********************************************** // 136 | 137 | 138 | // Call displayToDos here (Step 6)<----- 139 | 140 | 141 | // ---------------------------- DO NOT CHANGE ANY CODE BELOW THIS LINE ----------------------------- // 142 | if (typeof module !== 'undefined') { 143 | module.exports = { 144 | toDoItems: toDoItems, 145 | ToDo: ToDo, 146 | buildToDos: buildToDos, 147 | buildToDo: buildToDo, 148 | completeToDo: completeToDo, 149 | displayToDos: displayToDos, 150 | addToDo: addToDo 151 | }; 152 | } 153 | -------------------------------------------------------------------------------- /Lesson07-JS-IV/README.md: -------------------------------------------------------------------------------- 1 | # Lesson 7: Javascript IV (Objects) 2 | (Attention: These are the class notes for the [Lambda School](http://www.lambdaschool.com) pre-course instruction workshop. This is meant to serve as an accompaniment to the class) 3 | 4 | In this lesson we will cover: 5 | 6 | * Introduction to Objects 7 | * Methods 8 | * for...in Loops 9 | * The `this` Keyword 10 | * Objects in Javascript 11 | 12 | ## Introduction to Objects 13 | 14 | In the last lesson we introduced Arrays. Arrays are containers that hold collections of data. In this lesson we will introduce another data container, the Object. Objects and arrays are similar in some ways and very different in others. Where arrays hold multiple items related to each other, Objects will hold a lot of information about one thing. Objects are instantiated by using braces (`{}`). 15 | 16 | ```javascript 17 | const newObj = {}; 18 | ``` 19 | 20 | ### Key:Value pairs 21 | 22 | Unlike arrays that have index valued items, objects use a concept called key:value pairs. The key is the identifier and the value is the value we want to save to that key. The syntax is "key: value". Objects can hold many key:value pairs, they must be separated by a comma (no semi-colons inside of an object!). Keys are unique in an object, there can be only one key of that name. Although, multiple keys can have the same value. Values can be any Javascript type, string, number, boolean, array, function or even another object. In this demo we will create a user object. 23 | 24 | ```javascript 25 | const user = { 26 | username: 'dan.frehner', 27 | password: 'abc123', 28 | lovesJavascript: true, 29 | favoriteNumber: 42, 30 | }; 31 | ``` 32 | 33 | ### Accessing Values 34 | 35 | Once we have key:value pairs we can access those values by calling the object name and the key. There are two different ways to do this, dot notation and bracket notation. 36 | 37 | With dot notation we can just call the object name, a dot, and the key name. Just as we call the `.length` property on an array (hint: the length property is a key:value pair): 38 | 39 | ```javascript 40 | user.lovesJavascript; // true 41 | user.username; // dan.frehner 42 | ``` 43 | 44 | Bracket notation is just like calling an item on an array, although with brackets we MUST use a string or number, or variable pointing to a string or number. Each key can be called by wrapping it with quotes: 45 | 46 | ```javascript 47 | const passString = 'password'; 48 | user['lovesJavascript']; // true 49 | user['username']; // dan.frehner 50 | user[passString]; // abc123 51 | ``` 52 | 53 | In the wild you will see brackets almost always being used with variables. 54 | 55 | ### Assigning Values 56 | 57 | Assigning values works just like accessing them. We can assign them, when we create the object, with dot notation, or with bracket notation: 58 | 59 | ```javascript 60 | const newUser = { 61 | isNew: true, 62 | } 63 | 64 | const loveJSString = 'lovesJavascript'; 65 | 66 | newUser.username = 'new.username'; 67 | newUser['password'] = '12345'; 68 | newUser[loveJSString] = true; 69 | ``` 70 | 71 | ## Removing Properties 72 | 73 | If we want to remove a property we can do it using the `delete` keyword: 74 | 75 | ```javascript 76 | const newObject = { 77 | removeThisProperty: true, 78 | }; 79 | 80 | delete newObject.removeThisProperty; 81 | ``` 82 | 83 | It is rare we will see the use of the `delete` keyword, many find best practice to be setting the value of a keyword to `undefined`. It will be up to you when the time comes. 84 | 85 | ## Methods 86 | 87 | In objects, values can be set to functions. Functions saved on an object are called methods. We have used plenty of methods so far throughout this course. `.length`, `.push`, `.pop`, etc, are all methods. We can set a key to a name, and the value to a function. Just like other times we call methods, we will call this method using dot notation and trailing parentheses (note: we can call a method with arguments just as we would a normal function): 88 | 89 | ```javascript 90 | const newObject = { 91 | sayHiMethod: function() { 92 | console.log('Hi Everyone!'); 93 | }, 94 | } 95 | 96 | newObject.sayHiMethod(); // Hi Everyone! 97 | ``` 98 | 99 | ## for...in Loops 100 | 101 | Sometimes we want to iterate over each key:value pair in our object. With arrays we used a standard for loop and an index number variable. Objects do not contain numerical indexes so the standard loop will not work for objects. Javascript has a second type of for loop built in called the "for...in" loop. It is slightly different syntax, it starts the same but in the parentheses we will declare a variable, the keyword `in`, and the name of the object. This will loop over each key in the object and finish when all of the keys have been iterated over. We can use this key, and bracket notation, in our for loop to access the value associated with that key. 102 | 103 | ```javascript 104 | const user = { 105 | username: 'dan.frehner', 106 | password: 'abc123', 107 | lovesJavascript: true, 108 | favoriteNumber: 42, 109 | }; 110 | 111 | for (let key in user){ 112 | console.log(key); 113 | console.log(user[key]); 114 | } 115 | 116 | // username 117 | // 'dan.frehner' 118 | // password 119 | // 'abc123' 120 | // lovesJavascript 121 | // true 122 | // favoriteNumber 123 | // 42 124 | ``` 125 | 126 | ## The 'this' Keyword 127 | 128 | Objects have a self referential keyword that may be applied in each object called `this`. When called inside of an object it is referring to that very object. `this` can be used to access other keys in the same object, and is especially useful in methods: 129 | 130 | ```javascript 131 | const user = { 132 | username: 'dan.frehner', 133 | password: 'abc123', 134 | lovesJavascript: true, 135 | favoriteNumber: 42, 136 | userSaysHi: function(){ 137 | console.log( this.username + ' says hi!'); 138 | }, 139 | }; 140 | 141 | user.usersaysHi(); // 'dan.frehner says hi!' 142 | ``` 143 | 144 | Note: the `this` keyword can sometimes be one of the more difficult topics in Javascript. We are using it very basically here, but the topic gets much more complex very soon. 145 | 146 | ## Objects in Javascript 147 | 148 | In this lesson we learned what Objects are and the many ways to access values, call methods, and assign values. Many of these techniques looked very familiar, as if we had used them in virtually every aspect of our learnings so far. There is a pattern here, that is because EVERYTHING in Javascript is an Object. Arrays are just objects with numerical keys, Strings are objects under the hood with built in methods, functions are actually objects with their own special properties, the entire Javascript runtime is an object (`window` in a browser, or `global` in Node.js). The more you work with Javascript the more this will start to make sense to you. Just remember, everything is an object. 149 | 150 | ## Please open the homework folder and complete the assignment described in the README file 151 | 152 | ## Additional Resources: 153 | 154 | * [MDN: Object](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object) 155 | * [MDN: this](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Operators/this) 156 | * [MDN: for...in Loop](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Statements/for...in) 157 | -------------------------------------------------------------------------------- /Lesson04-JS-I/homework/tests/JSI.test.js: -------------------------------------------------------------------------------- 1 | /* eslint-disable no-undef */ 2 | const { 3 | newString, 4 | newNum, 5 | newBool, 6 | newSubtract, 7 | newMultiply, 8 | newModulo, 9 | returnString, 10 | areSameLength, 11 | areEqual, 12 | lessThanNinety, 13 | greaterThanFifty, 14 | add, 15 | subtract, 16 | divide, 17 | multiply, 18 | getRemainder, 19 | isEven, 20 | isOdd, 21 | square, 22 | cube, 23 | raiseToPower, 24 | roundNumber, 25 | roundUp, 26 | addExclamationPoint, 27 | combineNames, 28 | getGreeting, 29 | getRectangleArea, 30 | getTriangleArea, 31 | } = require('../homework'); 32 | 33 | describe('newString', function() { 34 | it('should be a string', function() { 35 | expect(typeof newString).toBe('string'); 36 | }); 37 | }); 38 | 39 | describe('newNum', function() { 40 | it('should be a number', function() { 41 | expect(typeof newNum).toBe('number'); 42 | }); 43 | }); 44 | 45 | describe('newBool', function() { 46 | it('should be a boolean', function() { 47 | expect(typeof newBool).toBe('boolean'); 48 | }); 49 | }); 50 | 51 | describe('newSubtract', function() { 52 | it('should be a boolean', function() { 53 | expect(newSubtract).toBe(true); 54 | }); 55 | }); 56 | 57 | describe('newMultiply', function() { 58 | it('should be a boolean', function() { 59 | expect(newMultiply).toBe(true); 60 | }); 61 | }); 62 | 63 | describe('newModulo', function() { 64 | it('should be a boolean', function() { 65 | expect(newModulo).toBe(true); 66 | }); 67 | }); 68 | 69 | describe('returnString(str)', function() { 70 | it('should return the string provided', function() { 71 | let string = 'lambdaSchool'; 72 | expect(returnString(string)).toBe(string); 73 | }); 74 | }); 75 | 76 | describe('add(x, y)', function() { 77 | it('should return the sum of the two arguments', function() { 78 | expect(add(5, 5)).toBe(10); 79 | expect(add(-1, 5)).toBe(4); 80 | }); 81 | }); 82 | 83 | describe('subtract(x, y)', function() { 84 | it('should return the difference of the two arguments', function() { 85 | expect(subtract(5, 5)).toBe(0); 86 | expect(subtract(-1, 5)).toBe(-6); 87 | expect(subtract(5, -5)).toBe(10); 88 | expect(subtract(0, 0)).toBe(0); 89 | }); 90 | }); 91 | 92 | describe('divide(x, y)', function() { 93 | it('should return the quotient of the two arguments', function() { 94 | expect(divide(5, 5)).toBe(1); 95 | expect(divide(10, 5)).toBe(2); 96 | expect(divide(11, 2)).toBe(5.5); 97 | }); 98 | }); 99 | 100 | describe('multiply(x, y)', function() { 101 | it('should return the product of the two arguments', function() { 102 | expect(multiply(5, 5)).toBe(25); 103 | expect(multiply(10, -5)).toBe(-50); 104 | expect(multiply(11, 0)).toBe(0); 105 | }); 106 | }); 107 | 108 | 109 | describe('areEqual(x, y)', function() { 110 | it('should return true if the arguments are equal', function() { 111 | expect(areEqual(15, 15)).toBe(true); 112 | expect(areEqual(90, 50)).toBe(false); 113 | expect(areEqual('test', 'test')).toBe(true); 114 | }); 115 | }); 116 | 117 | describe('areSameLength(str1, str2)', function() { 118 | it('should return true if the arguments have the same length', function() { 119 | expect(areSameLength('hi', 'there')).toBe(false); 120 | expect(areSameLength('javascript', 'bumfuzzled')).toBe(true); 121 | }); 122 | }); 123 | 124 | describe('lessThanNinety(num)', function() { 125 | it('should return true if the argument is less than ninety', function() { 126 | expect(lessThanNinety(15)).toBe(true); 127 | expect(lessThanNinety(90)).toBe(false); 128 | expect(lessThanNinety(100)).toBe(false); 129 | }); 130 | }); 131 | 132 | describe('greaterThanFifty(num)', function() { 133 | it('should return true if the argument is greater than fifty', function() { 134 | expect(greaterThanFifty(15)).toBe(false); 135 | expect(greaterThanFifty(50)).toBe(false); 136 | expect(greaterThanFifty(60)).toBe(true); 137 | }); 138 | }); 139 | 140 | describe('getRemainder(x, y)', function() { 141 | it('should return the division remainder of the two arguments', function() { 142 | expect(getRemainder(5, 5)).toBe(0); 143 | expect(getRemainder(10, 5)).toBe(0); 144 | expect(getRemainder(11, 2)).toBe(1); 145 | }); 146 | }); 147 | 148 | describe('isEven(num)', function() { 149 | it('should return the bool true if the argument is even, false otherwise', function() { 150 | expect(isEven(6)).toBe(true); 151 | expect(isEven(7)).toBe(false); 152 | expect(isEven(0)).toBe(true); 153 | }); 154 | }); 155 | 156 | describe('isOdd(num)', function() { 157 | it('should return the bool true if the argument is odd, false otherwise', function() { 158 | expect(isOdd(6)).toBe(false); 159 | expect(isOdd(7)).toBe(true); 160 | expect(isOdd(0)).toBe(false); 161 | }); 162 | }); 163 | 164 | describe('square(num)', function() { 165 | it('should return the argument after squaring it', function() { 166 | expect(square(6)).toBe(36); 167 | expect(square(7)).toBe(49); 168 | expect(square(0)).toBe(0); 169 | expect(square(-5)).toBe(25); 170 | }); 171 | }); 172 | 173 | describe('cube(num)', function() { 174 | it('should return the argument after cubing it', function() { 175 | expect(cube(3)).toBe(27); 176 | expect(cube(0)).toBe(0); 177 | expect(cube(-5)).toBe(-125); 178 | }); 179 | }); 180 | 181 | describe('raiseToPower(num, exponent)', function() { 182 | it('should return the argument after raising it to the exponent\'s power', function() { 183 | expect(raiseToPower(2, 2)).toBe(4); 184 | expect(raiseToPower(2, 3)).toBe(8); 185 | expect(raiseToPower(0, 5)).toBe(0); 186 | expect(raiseToPower(10, 1)).toBe(10); 187 | }); 188 | }); 189 | 190 | describe('roundNumber(num)', function() { 191 | it('should return the argument after rounding it', function() { 192 | expect(roundNumber(1.5)).toBe(2); 193 | expect(roundNumber(2)).toBe(2); 194 | expect(roundNumber(0.1)).toBe(0); 195 | }); 196 | }); 197 | 198 | describe('roundUp(num)', function() { 199 | it('should return the argument after rounding it up', function() { 200 | expect(roundUp(1.5)).toBe(2); 201 | expect(roundUp(2)).toBe(2); 202 | expect(roundUp(0.1)).toBe(1); 203 | }); 204 | }); 205 | 206 | describe('addExclamationPoint(str)', function() { 207 | it('should add an exclamation point to the end of the string', function() { 208 | expect(addExclamationPoint('hello world')).toBe('hello world!'); 209 | expect(addExclamationPoint('LambdaSchool')).toBe('LambdaSchool!'); 210 | }); 211 | }); 212 | 213 | describe('combineNames(firstName, lastName)', function() { 214 | it('should return the two strings combined into one with a space separating them', function() { 215 | expect(combineNames('hello', 'world')).toBe('hello world'); 216 | expect(combineNames('Lambda', 'School')).toBe('Lambda School'); 217 | }); 218 | }); 219 | 220 | describe('getGreeting(name)', function() { 221 | it('should return the string \'Hello {name}!\'', function() { 222 | expect(getGreeting('Ben')).toBe('Hello Ben!'); 223 | expect(getGreeting('LambdaSchool')).toBe('Hello LambdaSchool!'); 224 | }); 225 | }); 226 | 227 | describe('getRectangleArea(length, width)', function() { 228 | it('should return the correct area', function() { 229 | expect(getRectangleArea(2, 2)).toBe(4); 230 | expect(getRectangleArea(3, 6)).toBe(18); 231 | expect(getRectangleArea(0, 2)).toBe(0); 232 | }); 233 | }); 234 | 235 | describe('getTriangleArea(base, height)', function() { 236 | it('should return the correct area', function() { 237 | expect(getTriangleArea(2, 2)).toBe(2); 238 | expect(getTriangleArea(0, 2)).toBe(0); 239 | }); 240 | }); -------------------------------------------------------------------------------- /Lesson07-JS-IV/homework/tests/JSIV.test.js: -------------------------------------------------------------------------------- 1 | /* eslint-disable no-undef */ 2 | const { 3 | makeCat, 4 | addProperty, 5 | invokeMethod, 6 | multiplyMysteryNumberByFive, 7 | deleteProperty, 8 | newUser, 9 | hasEmail, 10 | hasProperty, 11 | verifyPassword, 12 | updatePassword, 13 | addFriend, 14 | setUsersToPremium, 15 | sumUserPostLikes, 16 | addCalculateDiscountPriceMethod, 17 | } = require('../homework'); 18 | 19 | describe('makeCat(name, age)', function() { 20 | it('should create a new cat with the name and age properties set', function() { 21 | expect(makeCat('Snowball', 1).name).toBe('Snowball'); 22 | expect(makeCat('Snowball', 1).age).toBe(1); 23 | expect(makeCat('Snowball II', 5).name).toBe('Snowball II'); 24 | expect(makeCat('Snowball II', 5).age).toBe(5); 25 | }); 26 | it('should add a method called meow to the new cat object', function() { 27 | expect(makeCat('Snowball III', 2).meow()).toBe('Meow!'); 28 | }); 29 | }); 30 | 31 | describe('addProperty(object, property)', function() { 32 | it('should add the property to the object with a value of null', function() { 33 | const object = { 34 | x: 1, 35 | y: 2, 36 | }; 37 | const updatedObject = { 38 | x: 1, 39 | y: 2, 40 | z: null, 41 | }; 42 | expect(addProperty(object, 'z')).toEqual(updatedObject); 43 | }); 44 | }); 45 | 46 | describe('invokeMethod(object, method)', function() { 47 | it('should invoke the method on the object', function() { 48 | const object = { 49 | x: 0, 50 | incrementX: function() { 51 | this.x++; 52 | }, 53 | } 54 | invokeMethod(object, 'incrementX'); 55 | expect(object.x).toBe(1); 56 | }); 57 | }); 58 | 59 | describe('multiplyMysteryNumberByFive(mysteryNumberObject)', function() { 60 | it('should return the mysteryNumber property multiplied by five', function() { 61 | const mysteryBox = { 62 | mysteryNumber: 999, 63 | }; 64 | expect(multiplyMysteryNumberByFive(mysteryBox)).toBe(4995); 65 | mysteryBox.mysteryNumber = -5; 66 | expect(multiplyMysteryNumberByFive(mysteryBox)).toBe(-25); 67 | }); 68 | }); 69 | 70 | describe('deleteProperty(object, property)', function() { 71 | it('should delete the property from the object', function() { 72 | const updatedObject = { 73 | x: 1, 74 | y: 2, 75 | }; 76 | const object = { 77 | x: 1, 78 | y: 2, 79 | z: null, 80 | }; 81 | expect(deleteProperty(object, 'z')).toEqual(updatedObject); 82 | }); 83 | }); 84 | 85 | describe('newUser(name, email, password)', function() { 86 | it('should return a new user object with a name, email, and password property that match the arguments', function() { 87 | const user = { 88 | name: 'Ben', 89 | email: 'ben@lambdaschool.com', 90 | password: 'correcthorsebatterystaple', 91 | }; 92 | expect(newUser(user.name, user.email, user.password)).toEqual(user); 93 | const user2 = { 94 | name: 'Austen', 95 | email: 'austen@lambdaschool.com', 96 | password: 'password', 97 | }; 98 | expect(newUser(user2.name, user2.email, user2.password)).toEqual(user2); 99 | }); 100 | }); 101 | 102 | describe('hasEmail(user)', function() { 103 | it('should return true if the user object has a value for its email property', function() { 104 | expect(hasEmail({ username: 'SunJieMing', email: 'ben@lambdaschool.com' })).toEqual(true); 105 | expect(hasEmail({ username: 'Austen', email: null })).toEqual(false); 106 | expect(hasEmail({ username: 'Ryan' })).toEqual(false); 107 | }); 108 | }); 109 | 110 | describe('hasProperty(object, property)', function() { 111 | it('should return true if the object has the property that is passed in', function() { 112 | const obj = { 113 | x: true, 114 | }; 115 | expect(hasProperty(obj, 'x')).toEqual(true); 116 | expect(hasProperty(obj, 'y')).toEqual(false); 117 | }); 118 | }); 119 | 120 | describe('verifyPassword(user, password)', function() { 121 | it('should return true if passwords match', function() { 122 | const user = { 123 | password: 'I love js!', 124 | }; 125 | const password = 'I love js!'; 126 | expect(verifyPassword(user, password)).toBe(true); 127 | }); 128 | it('should return false if passwords do not match', function() { 129 | const user = { 130 | password: 'I love js!', 131 | }; 132 | const password = 'Hack this guy!'; 133 | expect(verifyPassword(user, password)).toBe(false); 134 | }); 135 | }); 136 | 137 | describe('updatePassword(user, password)', function() { 138 | it('should return the user object with the updated password', function() { 139 | const user = { 140 | password: 'I love js!', 141 | }; 142 | const password = 'I love js even more!'; 143 | expect(updatePassword(user, password).password).toBe(password); 144 | }); 145 | }); 146 | 147 | describe('addFriend(user, newFriend)', function() { 148 | it('should add a new friend to the end of the friends array property', function() { 149 | const user = { 150 | friends: ['Ben', 'Austen', 'Ryan', 'Mike', 'Young'], 151 | }; 152 | const newFriend = 'Shay'; 153 | expect(addFriend(user, 'Shay').friends.pop()).toBe('Shay'); 154 | }); 155 | }); 156 | 157 | describe('setUsersToPremium(users)', function() { 158 | it('should return the users array with each user\'s isPremium property set to true', function() { 159 | const users = [ 160 | { isPremium: false }, 161 | { isPremium: false }, 162 | { isPremium: false }, 163 | { isPremium: false }, 164 | { isPremium: false }, 165 | ]; 166 | const updatedUsers = [ 167 | { isPremium: true }, 168 | { isPremium: true }, 169 | { isPremium: true }, 170 | { isPremium: true }, 171 | { isPremium: true }, 172 | ]; 173 | expect(setUsersToPremium(users)).toEqual(updatedUsers); 174 | }); 175 | }); 176 | 177 | describe('sumUserPostLikes(user)', function() { 178 | it('should return the sum of likes for all user posts', function() { 179 | const user = { 180 | username: 'SunJieMing', 181 | password: 'JavaScript is awesome!', 182 | posts: [ 183 | { 184 | id: '1', 185 | title: 'JS adventures!', 186 | likes: 10 187 | }, 188 | { 189 | id: '2', 190 | title: 'LambdaSchool forever!', 191 | likes: 100 192 | }, 193 | { 194 | id: '3', 195 | title: 'What is a JavaScript?', 196 | likes: 35 197 | }, 198 | { 199 | id: '4', 200 | title: 'JS Objects for dummies', 201 | likes: 42 202 | }, 203 | { 204 | id: '5', 205 | title: 'Online Education', 206 | likes: 99 207 | }, 208 | ], 209 | }; 210 | expect(sumUserPostLikes(user)).toBe(286); 211 | }); 212 | }); 213 | 214 | describe('addCalculateDiscountPriceMethod(storeItem)', function() { 215 | const storeItem = { 216 | price: 80, 217 | discountPercentage: 0.1, 218 | }; 219 | const storeItem2 = { 220 | price: 5, 221 | discountPercentage: 0.5, 222 | }; 223 | 224 | it('should add the method \'calculateDiscountPrice\' to the store item object', function() { 225 | expect(addCalculateDiscountPriceMethod(storeItem).calculateDiscountPrice).toBeDefined(); 226 | expect(addCalculateDiscountPriceMethod(storeItem2).calculateDiscountPrice).toBeDefined(); 227 | }); 228 | it('should return the discount price from the new \'calculateDiscountPrice\' method', function() { 229 | expect(addCalculateDiscountPriceMethod(storeItem).calculateDiscountPrice()).toBe(72); 230 | expect(addCalculateDiscountPriceMethod(storeItem2).calculateDiscountPrice()).toBe(2.5); 231 | }); 232 | }); 233 | -------------------------------------------------------------------------------- /Lesson03-CSS-Positioning/README.md: -------------------------------------------------------------------------------- 1 | # Lesson 3: Intermediate CSS 2 | (Attention: These are the class notes for the [Lambda School](http://www.lambdaschool.com) pre-course instruction workshop. This is meant to serve as an accompaniment to the class) 3 | 4 | In this lesson we will cover: 5 | 6 | * Introduction to positioning. 7 | * Display property. 8 | * Position property. 9 | * Using the position property to position elements. 10 | * Introduction to Flexbox. 11 | 12 | ## Introduction to positioning 13 | 14 | Building a layout and making everything look clean is what most people are looking to do when they start learning CSS. Positioning HTML elements on the page with CSS is possibly the most powerful ability CSS has, it can also be the most frustrating. In this lesson we will learn a few different ways to position items on the page. 15 | 16 | ## The Display property 17 | 18 | The display property is the one of the most important CSS properties for positioning. We can use the display property to control how the elements are displayed in relation to the elements around them, and how they behave on the screen. 19 | ```css 20 | div { 21 | display: ; 22 | } 23 | ``` 24 | 25 | There are two types of display elements already built into HTML. Block and Inline. 26 | 27 | ### Block Elements 28 | 29 | As a rule of thumb, a block element will always start on a new line, and will always take up the maximum width of the container it is in. Remember how in the last lesson we learned that the \

element will always start on a new line? It is a block element, as is div and \ 30 | 31 | ### Inline elements 32 | 33 | Inline elements are the opposite of Block elements, it will not start on a new line and will only take enough space as is needed to display the data inside of it. span, a, and img elements are all inline elements. 34 | 35 | We can control how an element behaves by using the display: property. If we want an inline element to act as a block element, we set: 36 | 37 | ```css 38 | div { 39 | display: block; 40 | } 41 | ``` 42 | And vise-versa. 43 | 44 | ### Display has a few other rules that we should be aware of that can be set on it: 45 | 46 | ### none 47 | 48 | Setting the display to "none" will make an element disappear completely. This is not to be confused with the "visibility: hidden;" rule which only renders the element invisible, but does not remove it from the page (the space will still look occupied by something). If an item is set to display: none there will be no sign of it on the page. 49 | 50 | ### flex 51 | 52 | Flex is a new(CSS3) powerful tool that gives us the ability to control where on the page we want our items to be. We will talk about this later in this lesson 53 | 54 | ### grid 55 | 56 | This is a new feature in CSS3 that will allow you to create a grid system inside of your element. 57 | 58 | ## The Position property 59 | 60 | The position property will specify the type of positioning method used for an HTML element. There are 5 different methods available (we will go over 4 of them). 61 | ```css 62 | div { 63 | position: ; 64 | } 65 | ``` 66 | 67 | ### static 68 | 69 | This is the default positioning of an element, setting an item to static will not affect the element's behavior in any way. 70 | 71 | ### relative 72 | 73 | Setting a position to relative will keep the element positioned as if it were static, but this method will allow us the ability to set other positioning methods on the element that we will describe very soon. 74 | 75 | ### fixed 76 | 77 | Setting an element as fixed will keep the element to a fixed place on the screen no matter how much you scroll or move the screen, it will remain in that place. Think about a header or menu bar on a webpage. 78 | 79 | ### absolute 80 | 81 | Absolute is a lot like fixed, except it is anchored relative to its parent element (as long as the parent has any position method on it, except static). 82 | 83 | ## Using the position property to position elements 84 | 85 | Now that we have set our position method to the style we want to use, we can then start position our element. (Note: this works for every position method other than "static", which will not affect the element in any way). 86 | 87 | ### top, left, right, and bottom 88 | 89 | After we set a positioning method we can the use top, bottom, left, and right properties to position our element. The value you give to each of these will determine how far away from the edge we want our element to be. For example, if we want our element to be in the extreme upper left corner (with a fixed position) we would use the following: 90 | 91 | ```css 92 | div { 93 | position: fixed; 94 | top: 0; 95 | left: 0; 96 | } 97 | ``` 98 | 99 | If we wanted it to be 10px below the top and 10px off the right edge: 100 | 101 | ```css 102 | div { 103 | position: fixed; 104 | top: 10px; 105 | right: 10px; 106 | } 107 | ``` 108 | 109 | ## Introduction to Flexbox 110 | 111 | Introduced in CSS3, Flexbox is an exciting new feature. It allows us to position our elements in relation to it's parent and each other. No longer do we have to apply CSS "hacks" for things like centering. This allows mobile friendly design to really shine; and allows us to spend less time trying to get our positioning just right. Flexbox can quickly get complicated, but we will cover the basics of flexbox positioning here. 112 | 113 | ### display: flex and inline-flex 114 | 115 | As we mentioned in the display property section, one of our display types can be "flex" this makes any container a flex block, we can also use "inline-flex" to make it a flex inline element. For the most part, we will just be using "flex". 116 | 117 | ### justify-content and align-items 118 | 119 | Now that our container(element) is a flex box. We can imagine it as a grid, columns going from left to right and rows going from top to bottom. We can use the justify-content and align-items properties to tell the flex box where we want our items to be on the grid. Initially "justify-content" will apply to the movement from left to right(row), and "align-items" will apply to the movement from top to bottom (column). We have a number of rules we can place on each of these properties: 120 | 121 | * center: will center an item (or group of items) along the axis in which you apply this rule. 122 | * flex-start: This is what each flex box is set to initially, it will display all of the items in a group at the very beginning of the row or column. 123 | * flex-end: the opposite of flex-start, will display the item(s) at the end of the row/column 124 | * space-between: This rule will evenly space your item(s) along the row/column. The first item will be at the flex-start, and the last will be at the flex-end 125 | * space-around: Like space-between, but will put an equal margin between each item, so no item will be directly touching the edge. 126 | 127 | example: if we wanted our items to be center in the exact middle of a flex box we would use the following: 128 | ```css 129 | div { 130 | display: flex; 131 | justify-content: center; 132 | align-items: center; 133 | } 134 | ``` 135 | 136 | ### flex-direction 137 | 138 | This property can change the way our browser interprets justify-content(JC) and align-items(AI). The default is "row", and this works for us in the majority of cases, but sometimes we want to change the way direction works. 139 | 140 | * row: this is the default direction. JC applies from left to right, ai applies from top to bottom. 141 | * column: This will flip which property controls which direction. JC will apply from top to bottom and ai will apply from left to right. 142 | * row-reverse: Only flips the direction of JC from right to left, does not affect AI 143 | * column-reverse: Only flips direction of AI from bottom to top, does not affect JC 144 | 145 | ### align-self 146 | 147 | One last, more advanced, property we will cover is called "align-self". This will be applied to an element within a flex box that we want to break out of the align-items control. If we give it the property align-self we can position it anywhere along the align-items axis we want. (Note: there is NO justify-self, this is a primary reason developers will change the flex direction) 148 | 149 | ### Now in your browser window, open and complete homework.html 150 | 151 | ## Additional Resources 152 | 153 | * [Flexbox Froggy (a great flexbox tutorial)](http://flexboxfroggy.com/) 154 | * [CSS tricks: A Complete Guide to Flexbox](https://css-tricks.com/snippets/css/a-guide-to-flexbox/) 155 | * [MDN: Using CSS Flexible Boxes](https://developer.mozilla.org/en-US/docs/Web/CSS/CSS_Flexible_Box_Layout/Using_CSS_flexible_boxes) 156 | * [MDN: CSS display propery](https://developer.mozilla.org/en-US/docs/Web/CSS/display) 157 | * [MDN: CSS position property](https://developer.mozilla.org/en-US/docs/Web/CSS/position) 158 | 159 | 160 | 161 | 162 | 163 | 164 | 165 | 166 | 167 | -------------------------------------------------------------------------------- /Lesson12-DOM/README.md: -------------------------------------------------------------------------------- 1 | # Lesson 12: DOM 2 | (Attention: These are the class notes for the [Lambda School](http://www.lambdaschool.com) pre-course instruction workshop. This is meant to serve as an accompaniment to the class) 3 | 4 | In this lesson we will cover: 5 | 6 | * Introduction to the `DOM` 7 | * The `script` Element 8 | * `document` 9 | * `document` Selectors 10 | * Element Methods 11 | * Event Handlers 12 | 13 | ## Introduction to the `DOM` 14 | 15 | The `DOM` (as you will repeatedly hear it called) refers to 'Document Object Model'. When a browser loads a webpage, it takes all of the HTML and creates a model from it. Using Javascript we can access and manipulate that model. Adding and removing elements, changing attributes of elements, and changing styling of elements. 16 | 17 | ## The `script` Element 18 | 19 | We can inject our Javascript code into an HTML page by using the `script` element. We can do this two ways. 20 | 21 | First is to insert opening and closing script tags in the `head` element, the same way we would use the `title` or `style` elements. We then insert our Javascript code directly on the HTML page inline. 22 | 23 | ```html 24 | 25 | 26 | 30 | 31 | 32 | ``` 33 | 34 | The second way is to use the script tag to retrieve our external Javascript file and inject that into our HTML page. Note, the attributes (flags) we use in script are `type` which should be set to "text/javascript" and `src` which will be set to the location of your file. We also want to include the keyword `async` and the end of our script tag to tell the browser to load the script asynchronously from the HTML. NOTE: script is not a self closing tag, you must include a closing tag. 35 | 36 | ```html 37 | 38 | 39 | 40 | 41 | 42 | ``` 43 | 44 | ## `document` 45 | 46 | The first thing to note about Javascript running on a webpage is it's access to a global object called `document`. Remember that DOM stands for `Document Object Model`, the `document` object contains our DOM and prototype methods that allow us to access elements on the DOM and manipulate them. 47 | 48 | ## `document` Selectors 49 | 50 | `document` contains dozens of methods on it's prototype. But most useful are it's selectors. We will take a look at the five most common. 51 | 52 | ### `document.getElementsByClassName` 53 | 54 | `getElementsByClassName` will find elements based on their class names. It will return an array-like object that we can use to iterate through. The class name supplied will be a string with the class name. 55 | 56 | ```javascript 57 | const divs = document.getElementsByClassName('divClass'); 58 | ``` 59 | 60 | ### `document.getElementById` 61 | 62 | `getElementById` will find a single element based on it's id. It will return the element itself. The id supplied must be a string of the id name. 63 | 64 | ```javascript 65 | const div = document.getElementById('divId'); 66 | ``` 67 | 68 | ### `document.querySelector` 69 | 70 | `querySelector` (and `querySelectorAll`) is a new method that takes a CSS style selector as it's argument. Remember that we can ask for classes in CSS using the `.`, ids using the `#`, and elements by using the element name (eg: `'body'`). These selectors will use the same format. It is best to only use ids with `querySelector` because it will only return the first item matching that selector. 71 | 72 | ```javascript 73 | const div = document.querySelector('#divId'); 74 | ``` 75 | 76 | ### `document.querySelectorAll` 77 | 78 | `querySelectorAll` works just like `querySelector` except it returns an array like object containing all elements that match the selector. Because of this, you can use ids OR class names with this method. 79 | 80 | ```javascript 81 | const divs = document.querySelectorAll('#divId'); 82 | ``` 83 | 84 | ### `document.createElement` 85 | 86 | If we want to create an element to be added to our `DOM`, we can use `document.createElement`. This method takes one argument, the element type and returns an empty element of that type. 87 | 88 | ```javascript 89 | const newDiv = document.createElement('div'); 90 | ``` 91 | 92 | ## Element Methods and Properties 93 | 94 | Once we have our elements selected we can use a wide range of methods and properties to affect everything on the element, including: changing the CSS styles, changing the attributes on the element, adding or removing the children of the element, adding or removing event listeners(clicks, etc). There are countless things we can do to affect the element. We will go over some basic methods and properties here. 95 | 96 | ### .innerHTML 97 | 98 | When we have an element, we can set it's `innerHTML`. This is essentially setting the data that is stored between the opening and closing tags of the element. 99 | 100 | ```javascript 101 | const p = document.querySelector('#pId'); 102 | console.log(p.innerHtml) // This is the text between the

tags 103 | 104 | p.innerHTML = 'This is new text to display between the tags'; 105 | 106 | console.log(p.innerHTML); // This is new text to display between the tags 107 | ``` 108 | 109 | ### .[attribute] and .setAttribute 110 | 111 | We can call `.setAttribute` on an element to either add an attribute to the element or reassign one that is already on that element. calling `.[name of attribute] = [new value]` is a shorthand way of doing this. 112 | 113 | ```javascript 114 | const img = document.querySelector('#imgId'); 115 | 116 | img.setAttribute('src', 'http://www.lambdaschool.com/lambdalogo.png'); 117 | 118 | img.src = 'http://www.lambdaschool.com/lambdalogo.png'; 119 | ``` 120 | 121 | ### .style 122 | 123 | Calling the `.style` property on an element gives us access to the styles associated with the element. Note, this does not give us access to the CSS styles, only the inline styles written in HTML. We chain the style we want to read, or affect, on to the end of the `.style` .We can use this to set certain styles on the element. 124 | 125 | ```javascript 126 | const div = document.querySelector('#divId'); 127 | 128 | div.style.height = '300px'; 129 | div.style.background = 'red'; 130 | ``` 131 | 132 | ### .className and .id 133 | 134 | Using the `.className` and `.id` properties we can read and reassign class names and ids. This is most useful when we have two different styles associated and we want to switch the element to another style. 135 | 136 | ```javascript 137 | const div = document.querySelector('#divId'); 138 | 139 | console.log(div.id); // divId 140 | div.className = 'newClassName'; 141 | div.id = 'newId'; 142 | ``` 143 | ### .appendChild 144 | 145 | We have the ability to create a new element set its style, class, id, attributes, and innerHTML, and add it to the `DOM` directly. To do this we use `.appendChild` on a parent node: 146 | 147 | ```javascript 148 | const body = document.querySelector('body'); 149 | const newDiv = document.createElement('div'); 150 | 151 | body.appendChild(newDiv); 152 | 153 | ``` 154 | ## Event Listeners 155 | 156 | An event listener is a function that fires when an event occurs. Events can be anything from a click, to a mouse entering the content area, to an image download finishing. We will explore a few different events, but there are dozens we can choose from. 157 | 158 | ### Click 159 | 160 | The most common event listener to assign to an element is the 'click handler' in fact, it is the only one with it's own property, `.onclick`. To use the onclick property, we set it equal to a function that we want fired each time the element is clicked. 161 | 162 | ```javascript 163 | const div = document.querySelector('#divId'); 164 | div.onclick = function() { 165 | console.log('clicked!'); 166 | }; 167 | ``` 168 | 169 | ### `addEventListener` and Other Events. 170 | 171 | `.onclick` works if we want to add a click listener, but what happens if we want to fire a function when a user enters text in a form input, or the screen is scrolled. There are dozens of built in event listeners, but we must use `.addEventListener`. `.addEventListener` is a method that takes two arguments, the first is the type of event it is listening for, and the second is a callback function that is called when that event happens. Note: it is best to use addEventListener for all events, even clicks. 172 | 173 | ```javascript 174 | const div = document.querySelector('#divId'); 175 | div.addEventListener('mouseenter', function() { 176 | console.log('mouse has entered!'); 177 | }); 178 | ``` 179 | 180 | You can find a list of all events here: [MDN: Events](https://developer.mozilla.org/en-US/docs/Web/Events) 181 | 182 | Using these document methods coupled with the knowledge we have of Javascript, HTML, and CSS, we now how the tools to build a fully functional front end web application. 183 | 184 | ## Additional Resources 185 | 186 | * [MDN: DOM](https://developer.mozilla.org/en-US/docs/Web/API/Document_Object_Model) 187 | * [MDN: script Element](https://developer.mozilla.org/en-US/docs/Web/HTML/Element/script) 188 | * [MDN: Document](https://developer.mozilla.org/en-US/docs/Web/API/Document) 189 | * [MDN: Events](https://developer.mozilla.org/en-US/docs/Web/Events) 190 | 191 | 192 | 193 | -------------------------------------------------------------------------------- /Lesson01-Git/README.md: -------------------------------------------------------------------------------- 1 | # Lesson 1: Git fundamentals 2 | (Attention: These are the class notes for the [Lambda School](http://www.lambdaschool.com) pre-course instruction workshop. This is meant to serve as an accompaniment to the class) 3 | 4 | In this lesson we will cover: 5 | 6 | * Description of version control and Git. 7 | * Basic terminal commands. 8 | * Forking and cloning an existing Github.com repo. 9 | * Basic Git commands (status, add, commit, push). 10 | * Submitting a Pull Request. 11 | 12 | ### Prerequisites: 13 | * Create a [Github.com](https://www.github.com/) account. 14 | * If you are or have applied to Lambda School then set your account email to public in settings. 15 | * If you are on a Windows computer you can install the [git-bash command terminal here](https://git-for-windows.github.io/) 16 | * If you are on a Mac, git is preinstalled and you can access it from your terminal. By pressing ⌘+space and entering "terminal". (You can make sure you have git installed by typing "which git" and pressing enter, if a file path appears on your screen you are go to go. In some cases you may be directed to download the Xcode command line developer tools, follow the instructions) 17 | * If you are on a Linux machine, you may need to install git by accessing your terminal and entering "apt-get install git" 18 | * If you are having trouble installing Git, this resource will help: [https://git-scm.com/book/en/v2/Getting-Started-Installing-Git](https://git-scm.com/book/en/v2/Getting-Started-Installing-Git) 19 | 20 | ## Description of version control and Git 21 | 22 | Version control is a concept in software engineering which applies to the management of source code. There are many systems for applying version control practices to source code. We will be focusing on one of the most popular, "Git". 23 | 24 | ### Git 25 | 26 | Git was created in 2005 by Linus Torvalds. Git allows a team to work concurrently on a single project, or "repository", all while staying current and up to date. This is done through branching, each member, or feature, can have a branch from the master branch. That branch can be edited as needed without interfering with the "master". When the time comes to merge the branches back together, git will evaluate where the changes were made and will correct the master to reflect those changes without interfering with other changes. Git also acts as a sort of time machine, allowing a team to revert ANY changes made to the source code throughout the history of the code. 27 | 28 | ### Github.com 29 | 30 | [Github.com](https://github.com) is a network to store your repositories, essentially it is a repository of repositories. It is one of many available on the internet, and the most popular. Git != Github, although they work very well together. Github is a place for you to store your code or find other projects. It also acts as a portfolio for any code you've worked on. If you plan on being a developer you should have a Github account. We will be using Github extensively throughout your time at Lambda School. 31 | 32 | ## Basic terminal commands: 33 | 34 | > We will be using the "terminal" or "command line" throughout your time at Lambda school. If you are on a Mac or Linux machine, you should have the terminal and git installed already, if you are on a Windows machine I recommend installing ["git-bash"](https://git-for-windows.github.io/). 35 | 36 | Within our terminal we can: traverse our file structure, add files, remove files, update files, and tons more! The terminal is a very powerful tool for developers and you will be using it a lot in your professional development career. It might look scary at first, but in time you will enjoy using it. It is best to get accustomed to it now. To begin we will learn the 'basic' commands: 37 | 38 | "List": Allows us to view the contents of the current folder we are in. 39 | ```bash 40 | $ ls 41 | ``` 42 | 43 | "Change Directory": Allows us to move to a new folder or 'directory'. 44 | ```bash 45 | $ cd [folder] 46 | ``` 47 | 48 | "Make Directory": Makes a new folder in the directory you are currently in. 49 | ```bash 50 | $ mkdir [folder name] 51 | ``` 52 | "Touch" will create a new file. 53 | ```bash 54 | $ touch [file] 55 | ``` 56 | 57 | "Remove": permanently deletes a file. (WARNING! This bypasses any "trashcan" or recycling can you may have and PERMANENTLY deletes the file) (also of note: This will not remove folders, we need a special command for that, that we will learn later.) 58 | ```bash 59 | $ rm [file] 60 | ``` 61 | 62 | ## Exercise 63 | 64 | In this exercise we will create a new folder titled: "LambdaSchool" 65 | 66 | To get to your top level folder type: 67 | 68 | ```bash 69 | cd ~ 70 | ``` 71 | 72 | and press enter. Once in your top level type: 73 | 74 | ```bash 75 | mkdir LambdaSchool 76 | ``` 77 | 78 | and press enter. Congratulations you have created a directory! 79 | 80 | ## Github 81 | 82 | As mentioned before, Github is a central place to store, view, and download repositories, it is not synonymous with "git". You need to have a Github account in order to complete this exercise. 83 | 84 | ### Forking 85 | 86 | Github.com allows users to create their own copy of an repository (as long as it is public) and do whatever work you would like to that on under your own account. This is called "Forking". Essentially this will create a new branch of the repo, and at a future time you may be able to reincorporate("pull") the changes you have made to this branch with the master branch you forked from. 87 | 88 | In order to fork a repo, you will visit the Github repo of your choosing (for this exercise we will be using [this](http://github.com/lambdaschool/precourse) repo). Anywhere within the repo you will see a "Fork" button in the upper right hand corner, click this. Github will take a moment and copy all of the data to your account and it is now available to you to work on. 89 | 90 | ### Cloning 91 | 92 | In order to work on a project you must clone (download) it to your local machine. To do this, visit the top level of the forked repo on your own account, and click on the green button in the upper right hand side of the page that says: "Clone or Download" a dropdown should appear and will can click on the clipboard icon to copy the address. (Note: you can download the entire repo, but this is not advised as cloning will do quite a few steps for you behind the scenes that will make your life much easier.) 93 | 94 | Once you have the address copied, return to your terminal window and enter the following: 95 | 96 | ```bash 97 | $ cd LambdaSchool 98 | 99 | $ git clone [copied address] 100 | ``` 101 | 102 | This will download the repo and you now have a local copy of the repo saved to your machine! 103 | 104 | ## Git commands: 105 | 106 | Throughout these lessons, we will interact with git through our terminal. In the future you may wish to use a Git GUI interface, but during these lessons we will need to use the terminal for all git functions. 107 | 108 | In this exercise, we will add a file to our project and then commit this change to memory in git. 109 | 110 | In your terminal, cd into the LambdaSchool/Precourse folder 111 | 112 | Then enter the following in your terminal: 113 | ```bash 114 | $ touch Lesson01-Git/newFile.js 115 | ``` 116 | 117 | This will add a new file your your project titled "newFile.js" 118 | 119 | at this time we can use the git command "status". Status will read back the status of all changes made to your repo. Use status often, if you’re not sure if something worked, using status will tell you. 120 | 121 | ```bash 122 | $ git status 123 | ``` 124 | 125 | You should see something along these lines: 126 | 127 | ```bash 128 | Changes not staged for commit: 129 | (use "git add ..." to update what will be committed) 130 | (use "git checkout -- ..." to discard changes in working directory) 131 | 132 |    modified: Lesson01-Git/README.md 133 | 134 | Untracked files: 135 | (use "git add ..." to include in what will be committed) 136 | 137 |    Lesson01-Git/newFile.js 138 | 139 | no changes added to commit (use "git add" and/or "git commit -a") 140 | ``` 141 | 142 | This tells us that we have a file that has been changed, but is not saved into the git history yet. 143 | 144 | To do this we will use the 'add' command: 145 | 146 | ```bash 147 | git add Lesson01-Git/newFile.js 148 | ``` 149 | 150 | This has added our changes to the history, now to save that history, we will use "commit". Commit will take all of our added changes and save it to git history. For future reference you will be able to leave a message about the changes, this will make it easier to go back and find the changes you(or anyone) are looking for in the future ,if you should need to. It is always a good idea to leave a concise description of the changes in your commit. A shorthand way of leaving an inline message is using the '-m' flag and writing your message directly after, in quotes. 151 | 152 | ```bash 153 | git commit -m 'added new file, newFile.js' 154 | ``` 155 | 156 | Now that we have our changes saved locally, we want to share those changes in our Github. To do this we will "push" 157 | 158 | ```bash 159 | git push 160 | ``` 161 | 162 | You will be prompted for your username and password. Enter these and then you will receive a message if your changes were pushed successfully: 163 | 164 | ```bash 165 | Counting objects: 5, done. 166 | Delta compression using up to 8 threads. 167 | Compressing objects: 100% (4/4), done. 168 | Writing objects: 100% (5/5), 2.97 KiB | 0 bytes/s, done. 169 | Total 5 (delta 1), reused 0 (delta 0) 170 | remote: Resolving deltas: 100% (1/1), completed with 1 local object. 171 | To git@github.com:[your username]/Precourse.git 172 | cccc682..283b9dd master -> master 173 | ``` 174 | 175 | Congratulations! You just pushed your first git commit! 176 | 177 | ## Pull Requests 178 | 179 | Once you have completed the changes you intend to make, it will be time to merge those changes with the master branch. If you are not making changes directly to your own repository, you will need to submit a "Pull Request" or "PR" as we will refer to it. This allows to owner(or manager/supervisor/lead/senior) of the original repo to look over the changes and decide if they want to include these changes in their master. We will do this through Github. 180 | 181 | In this exercise, we will submit a pull request through github.com 182 | 183 | 184 | ## Further reading and tutorials: 185 | 186 | * [Git: official site](https://git-scm.com/) 187 | * [Github: official tutorial](https://try.github.io/levels/1/challenges/1) 188 | * [Codecademy: Learn Git](https://www.codecademy.com/learn/learn-git) 189 | * [Git: official tutorial](https://git-scm.com/docs/gittutorial) 190 | * [Termianl turorial](https://www.davidbaumgold.com/tutorials/command-line/) 191 | -------------------------------------------------------------------------------- /Lesson05-JS-II/README.md: -------------------------------------------------------------------------------- 1 | # Lesson 5: Javascript II (Control Flow, Comparison Operators, `for` Loops) 2 | (Attention: These are the class notes for the [Lambda School](http://www.lambdaschool.com) pre-course instruction workshop. This is meant to serve as an accompaniment to the class) 3 | 4 | In this lesson we will cover: 5 | 6 | * Undefined and Null 7 | * Comparison Operators (continued) 8 | * Control Flow (continued) 9 | * Logical Operators 10 | * `for` Loops 11 | * `arguments` 12 | 13 | ## Undefined and Null 14 | 15 | There are a couple of Javascript objects that don't really fit into any type. Those are the values `undefined` and `null`. You will get `undefined` when you are looking for something that does not exist like a variable that does not have a value yet. `undefined` simply means what you are asking for does not exist. 16 | 17 | ```javascript 18 | console.log(unkownVar); // undefined 19 | ``` 20 | 21 | `null` is an object that we, the developers, set when we want to tell other developers that the item they are looking for exists, but there is no value associated with it. While `undefined` is set by the Javascript language, `null` is set by a developer. If you ever receive `null`, know that another developer set that value to `null` 22 | 23 | ```javascript 24 | let phoneNumber = '123-456-7890'; 25 | phoneNumber = null; 26 | 27 | phoneNumer; // null 28 | ``` 29 | 30 | One last thing to note, neither `undefined` nor `null` are strings, they are written just as they are with no quotes around them, like a boolean. 31 | 32 | ## Truthiness 33 | 34 | In these lessons we have talked a lot about the boolean values, `true` and `false`. When using an `if` statement or another statement that expects a boolean value (such as the `!`, NOT), and the expression given is not a boolean value, Javascript will do something called type coercion and transform whatever it is given to a boolean value. This is known as truthy and falsey. Every data type has a truthiness to it. Here are some examples: 35 | 36 | ```javascript 37 | // items that are coerced to true 38 | true 39 | 1 40 | ' ' 41 | [] // an array, you'll learn more about this later 42 | {} // an object, you'll learn more about this later 43 | function() {} 44 | 45 | // items that are coerced to false 46 | false 47 | 0 48 | undefined 49 | null 50 | '' 51 | ``` 52 | 53 | ## Comparison Operators (continued) 54 | 55 | In the last lesson we touched on Comparison Operators, we will go a little more in depth as to how they work and then introduce a close relative of Comparison Operators, Logical Operators. 56 | 57 | In the last lesson we introduced our comparison operators, (`>` `>=` `<` `<=` `===` `!==`). These operators work just as they would in a math class, greater than, less than, etc. We use these operators to evaluate two expressions. As the computer runs the code the operator will return either a `true` (if the statement is true) or a `false`. 58 | 59 | ```javascript 60 | 1 > 2; // alse 61 | 2 < 3; // true 62 | 10 >= 10; // true 63 | 100 <= 1; // false 64 | ``` 65 | 66 | The "triple equals" ( `===` ) must not be confused with a single equal sign (which indicates assigning a value to a variable). The triple equal will compare everything about the two items, including type, and return if they are exactly equal or not: 67 | (Something to note: there is a "double equals" ( `==` ) which will compare two items, but it will NOT take into account their types (`1 == '1' // true`). Due to this, it is considered bad practice to use the double equal. We would like to see you always using the triple, and you will always see us using it.) 68 | 69 | ```javascript 70 | 1 === 1; // true 71 | 1 === '1'; // false 72 | 'cat' === 'cat'; // true 73 | 'cat' === 'Cat'; // false 74 | ``` 75 | 76 | The last comparison operator we would like to introduce you to has two parts to it. 77 | 78 | First is the "NOT" (`!`) when you see this it will mean that we are asking the opposite of the expression (we will revisit the NOT operator later in this lesson). 79 | 80 | With that in mind, we can introduce the "not equals" ( `!==` ). This will return true if the items are NOT equal to each other, in any way. This, like the triple equal, takes type into account. 81 | 82 | ```javascript 83 | 1 !== 1; // false 84 | 1 !== '1'; // true 85 | 'cat' !== 'cat'; // false 86 | 'cat' !== 'Cat'; // true 87 | ``` 88 | 89 | ## Control Flow (continued) 90 | 91 | In the last lesson we learned about the `if` operator. We can use `if` to check and see if an expression is `true`, if it is, run some code. If it is not, skip the code and keep running the program. 92 | 93 | ```javascript 94 | if (1 + 1 === 2) { 95 | console.log('The expression is true!'); 96 | } 97 | ``` 98 | 99 | To add on to `if`, we can also use the `else if` and `else` statements. These statements must be used with `if` and must come after it. These statements will be evaluated if the initial `if` returns `false`. We can think of the `else if` as another `if` statement that has been chained (we can have as many else if statements we want). Only one `if` or `else if` statement code block will be run. If at any time a statement returns `true`, that code will be run and the rest will be skipped: 100 | 101 | ```javascript 102 | if (false) { 103 | console.log('This will be skipped!'); 104 | } else if (true) { 105 | console.log('This code will be run'); 106 | } else if (true) { 107 | console.log('This code will NOT be run'); 108 | } 109 | ``` 110 | 111 | The `else` statement will always come at the end of an if-else `if` chain, and will act as a default. If none of the expressions returned `true`, the `else` code block will be run no matter what. If any of the previous `if` or `else if` expressions are `true`, the `else` statement code block will not be run. 112 | 113 | ```javascript 114 | if (false) { 115 | console.log('This will be skipped!'); 116 | } else if (false) { 117 | console.log('This code will NOT be run'); 118 | } else { 119 | console.log('This code will be run'); 120 | } 121 | ``` 122 | 123 | ## Logical Operators 124 | 125 | We can also combine two equality expressions and ask if either of the are true, both of them are true, or neither of them are true. To do this we will use Logical Operators. 126 | 127 | ### && 128 | 129 | The first logical operator we will look at is the "AND" operator. It is written with two ampersands (`&&`). This will evaluate both expressions and will return true if BOTH expressions are true. If one (or both) of them is false this operator will return false: 130 | 131 | ```javascript 132 | if (100 > 10 && 10 === 10) { 133 | console.log('Both statements are true, so this code will be run'); 134 | } 135 | 136 | if (10 === 9 && 10 > 9) { 137 | console.log('One of the statements is false, so the && will return false, this code will not be run'); 138 | } 139 | ``` 140 | 141 | ### || 142 | 143 | The next is the "OR" operator. It is written with two vertical bars (`||`). It will determine if one of the expressions is `true`. It will return `true` if one (or both) of the expressions is `true`. It will return `false` if BOTH expressions are `false`: 144 | 145 | ```javascript 146 | if (100 > 10 || 10 === 10) { 147 | console.log('Both statements are true, so this code will be run'); 148 | } 149 | 150 | if (10 === 9 || 10 > 9) { 151 | console.log('One of the statements is true so the || will return true, this code will be run'); 152 | } 153 | 154 | if (10 === 9 || 1 > 9) { 155 | console.log('Both of the statements are false, so the || will return false. This code will not be run.'); 156 | } 157 | ``` 158 | 159 | ### ! 160 | 161 | The last logical operator is the "NOT" operator. It is written as a single exclamation mark (`!`). We saw this operator earlier when determining equality (`!==`). As before, the NOT operator will return the opposite boolean value of what is passed to it: 162 | 163 | ```javascript 164 | if (!false) { 165 | console.log('The ! will return true, because it is the opposite of false. This code will be run'); 166 | } 167 | 168 | if (!(1 === 1)) { 169 | console.log('1 does equal 1, so that expression returns true. The ! operator will then return the opposite of that. This code will NOT run.'); 170 | } 171 | ``` 172 | 173 | ### Notes About Logical Operators 174 | 175 | A couple things to note about logical operators. 176 | 177 | * The expressions are evaluated in order, and the computer will skip any redundant expressions. In an `&&` statement, if the first expression is `false`, the second expression will not be evaluated because BOTH expressions need to be `true`. Same for the `||` statement. If the first expression is `true`, the second will not be evaluated because there only needs to be one `true` statement to fulfill the requirements of the operator. 178 | 179 | * Use parentheses. As we saw in the second `!` operator example, we used parentheses to evaluate what was inside of the parentheses FIRST, then applied the `!` operator. We can wrap ANY expression in parentheses and it will be evaluated before evaluating the expression as a whole. 180 | 181 | 182 | ## for Loops 183 | 184 | Most software runs on loops, evaluating expressions over and over again until it either returns what we are looking for, or stops after a certain time. Javascript has two looping expressions built in to it and today we will look at the first one, the "for" loop. 185 | 186 | `for` loops have a unique syntax, similar to the `if` statement, but slightly more complex. First we have the `for` keyword, followed by parentheses and then open and close braces. Within the parentheses we will need three things. First, we must declare a variable, this is what the loop will be looping over. Then we will have a conditional expression, the loop will continue happening until this statement is `false`. Third, we will increment our variable. All three of these statements are separated by a semi-colon. 187 | 188 | ```javascript 189 | for (let i = 0 ; i < 10 ; i++ ) { 190 | // | declare a var | conditional expression | increment var| 191 | console.log(i); 192 | } 193 | ``` 194 | 195 | In this example we see that we initially set our `counter` variable to 0, the loop will run and each time it gets to the end, it will increase the counter by one. The for loop will then evaluate the conditional expression. If it is `true`, it will run again, if it is `false` it will stop running. 196 | 197 | ### The ++ operator 198 | 199 | We saw in the last two examples the `++` operator. This is Javascript shorthand for "Set the value of the variable to it's current value plus one". There are a few more of these variable math/assignment shorthand expressions, we will visit them in upcoming lessons. 200 | 201 | ### Infinite Loops. 202 | 203 | It is possible to get your loop stuck in what we call an "Infinite Loop". You must make sure there is a way for the loop to end, take for example this loop: 204 | 205 | ```javascript 206 | for (let i = 0; i >= 0; i++) { 207 | console.log(i); 208 | } 209 | ``` 210 | Because our conditional expression will ALWAS be `true` (`i` will never be less than 0) this loop will essentially run forever. This will break your program, and may crash your web browser, or computer. 211 | 212 | ## Please open the homework folder and complete the assignment described in the README file 213 | 214 | ## Additional Resources 215 | 216 | * [MDN: Comparison Operators](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Operators/Comparison_Operators) 217 | * [MDN: Control Flow](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Statements/if...else) 218 | * [MDN: Logical Operators](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Operators/Logical_Operators) 219 | * [MDN: for Loops](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Statements/for) 220 | -------------------------------------------------------------------------------- /Lesson04-JS-I/README.md: -------------------------------------------------------------------------------- 1 | # Lesson 4: Introduction to Javascript 2 | (Attention: These are the class notes for the [Lambda School](http://www.lambdaschool.com) pre-course instruction workshop. This is meant to serve as an accompaniment to the class) 3 | 4 | In this lesson we will cover: 5 | 6 | * Introduction to Javascript 7 | * Variables 8 | * Strings, Numbers, and Booleans 9 | * Math 10 | * Introduction to Functions 11 | * Control Flow and Comparison Operators 12 | * Introduction to Node and NPM 13 | 14 | ## Introduction to Javascript 15 | 16 | If we imagine a web page as a house, the HTML makes up the materials (wood, brick, and concrete), CSS is how we put all of those materials together, and Javascript is the electricity, plumbing and gas. It's what makes the web page "run". Javascript was originally designed to be used purely on the front end as a way for web developers to add functionality to their web pages, and in its early days it did just that. Recently, the introduction of the "V8 engine" by Google has improved the speed and functionality of JS. That led to the development and release of exciting new front-end Javascript frameworks and eventually Node.js, a way to run Javascript on a server (back-end). This new development has led to a resurgence of Javascript. Javascript is one of the world's most widely used programming languages. We now find Javascript used on front-end, back-end, mobile development, IoT, and really anywhere a traditional programming language would be used. Recently, the newest version of the Javascript language was released (ES6), we will be focusing on and using ES6 in this course, and in the Lambda School full CS course. Keep in mind, Javascript != Java. Although they share similar names (this was, unfortunately, considered a feature by Javascript's early pioneers) that is where the similarities end. 17 | 18 | ## Variables 19 | 20 | At the heart of Javascript are variables. A variable is a way to store the value of something to use later. (A note for those with previous programming knowledge: Javascript is a loosely typed language, a variable can be set (and reset) to any type, we do not need to declare its type when initiating the variable.) 21 | 22 | The anatomy of a variable is first the keyword, a space, the name we are giving the variable, an equal sign, the value we are assigning the variable and then the semi-colon. 23 | 24 | There are three ways to declare a variable. 25 | ```javascript 26 | var firstName = 'John'; 27 | let lastName = 'Smith'; 28 | const favoriteFood = 'Taco'; 29 | ``` 30 | 31 | ### var 32 | 33 | `var` is the ES5 way of declaring a variable. This is a generic variable keyword. 34 | 35 | ### let 36 | 37 | `let` is a new ES6 variable keyword, this will assign a variable much like `var`, but with a little bit different behavior. Most notably, it differs by creating "block level scope". 38 | 39 | ### const 40 | 41 | `const` is also new in ES6. A `const` is a variable that will not be able to be changed. This is short for "constant". 42 | 43 | ### console.log 44 | 45 | Another concept we will talk about right away is 46 | 47 | ```javascript 48 | console.log(); 49 | ``` 50 | 51 | This very simple method will allow us to print to the console anything we put between the parentheses. 52 | 53 | ## Strings, Numbers, and Booleans 54 | 55 | These are the most basic data types in Javascript. 56 | 57 | ### Strings 58 | 59 | Strings are blocks of text, they will always be defined with quotation marks around them, either single or double. Any text with quotes around it is a string. 60 | 61 | ```javascript 62 | const dog = 'fido'; 63 | ``` 64 | ### Numbers 65 | 66 | Numbers are just that, numbers. Numbers do NOT have quotes around them. They can be negative as well. Javascript does have a limitation on the size of a number (+/- 9007199254740991), but only very rarely will that limitation come up. 67 | 68 | ```javascript 69 | const answer = 42; 70 | const negative = -13; 71 | ``` 72 | 73 | ### Boolean 74 | 75 | Booleans come from low level computer science. It is a concept that powers binary code and the very core of computers. You may have seen binary code in the past (0001 0110...), this is boolean logic. It essentially means you have two choices, on or off, 0 or 1, true of false. In Javascript we use Booleans to mean true or false. This may seem simple at first but can get complicated later on. 76 | 77 | ```javascript 78 | const iLoveJavascript = true; 79 | ``` 80 | 81 | ## Math 82 | 83 | Math operators work in javascript just as they would on your calculator. 84 | 85 | ### + - * / = 86 | 87 | ```javascript 88 | 1 + 1 = 2 89 | 2 * 2 = 4 90 | 2 - 2 = 0 91 | 2 / 2 = 1 92 | ``` 93 | 94 | ### % 95 | 96 | Something you may not have seen before is the Modulo (`%`), this math operator will divide the two numbers and return the remainder. 97 | 98 | ```javascript 99 | 21 % 5 = 1; 100 | 21 % 6 = 3; 101 | 21 % 7 = 0; 102 | ``` 103 | 104 | ## Global objects and methods 105 | 106 | Javascript has a number of built in objects for us to use. We have already seen, and have been using, the console object and it's method `log`. Another one of these objects is `Math`. `Math` has a number of methods on it just like `console` has `log`. To add to this, some of our data types also have built in methods. 107 | 108 | ### Math.pow 109 | 110 | We can use the `pow` method on `Math` to return a number risen to an exponent. It will take two numbers. 111 | 112 | ```javascript 113 | Math.pow(2,2) = 4; 114 | Math.pow(3,2) = 9; 115 | Math.pow(3,3) = 27; 116 | ``` 117 | 118 | ### Math.round , Math.floor, Math.ceil 119 | 120 | `Math` also has methods that will round numbers for us. `.round` will round a number to the nearest whole number. `.floor` will always round a number down to the nearest whole number. `.ceil` will always round up to the nearest whole number. 121 | 122 | ```javascript 123 | Math.round(6.5) = 7; 124 | Math.round(6.45) = 6; 125 | Math.floor(6.999) = 6; 126 | Math.ceil(6.0001) = 7; 127 | ``` 128 | 129 | ### .length 130 | 131 | The string data type has a built in method called `.length` . Any string we call this on will return the amount of characters in that string. 132 | 133 | ```javascript 134 | const cat = 'kitty'; 135 | console.log(cat.length); // 5 136 | ``` 137 | 138 | We will see many other built it in methods on other data types throughout this course. 139 | 140 | ## Introduction to Functions 141 | 142 | Now that we have variables set we need functions to compute them, change them, do something with them. There are three ways we can build a function. 143 | 144 | ```javascript 145 | function myFunc() {} 146 | const anotherFunc = function () {}; 147 | const yetAnother = () => {}; 148 | ``` 149 | 150 | We will be using the first way in this lesson, and talk about the other ways in future lessons. 151 | 152 | ### Anatomy of a Function 153 | 154 | ```javascript 155 | function myFunc() {} 156 | ``` 157 | 158 | A function will start with the `function` keyword, this tells whatever is running your program that what follows is a function and to treat it as such. After that comes the name of the function, we like to give functions names that describe what they do. Then comes an open and a close parentheses. And finally, open and close brackets. In between these brackets is where all of our function code will go. 159 | 160 | ```javascript 161 | function logsHello() { 162 | console.log('hello'); 163 | } 164 | 165 | logsHello(); 166 | ``` 167 | 168 | In this example we declare a function `logsHello` and we set it up to `console.log` `'hello'`. We can then see in order to run this function, we need to write the name and parentheses. This is the syntax to run a function. A function always needs parentheses to run. 169 | 170 | ### Arguments 171 | 172 | Now that we can run a basic function, we are going to start passing it arguments. 173 | 174 | ```javascript 175 | function logsHello(name) { 176 | console.log('Hello, ' + name); 177 | } 178 | 179 | logsHello('Dan'); 180 | ``` 181 | 182 | If we add a variable to the parentheses when we declare the function we can use this variable within our function. We initiate the value of this variable by passing it into the function when we call it. So in this case `name = 'Dan'`. We can pass other variables into this as well: 183 | 184 | ```javascript 185 | function logsHello(name) { 186 | console.log( `Hello, ${name}`); 187 | } 188 | 189 | const myName = 'Dan'; 190 | logsHello(myName); 191 | ``` 192 | 193 | We can add multiple arguments by placing a comma in between them: 194 | 195 | ```javascript 196 | function addsTwoNumbers(a, b) { 197 | const sum = a + b; 198 | return sum; 199 | } 200 | 201 | addsTwoNumbers(1, 5); // 6 202 | ``` 203 | ### Return statement and Scope 204 | 205 | In the last example we introduced the `return` statement. We will not `console.log` everything that comes out of a function. Most likely we will want to return something. In this case it is the sum of the two numbers. Think of the return statement as the only way for data to escape a function. Nothing other than what is returned can be accessed outside of the function. Also note, that when a function hits a return statement, the function immediately stops what it is doing and returns. 206 | 207 | ```javascript 208 | function dividesTwoNumbers(a, b) { 209 | const product = a / b; 210 | return product; 211 | } 212 | 213 | dividesTwoNumbers(6, 3); // 2 214 | console.log(product); // undefined 215 | ``` 216 | 217 | If we tried to `console.log` something that we declared inside of the function it would return `undefined` because we do not have access to it outside of the function. This is called scope. The only way to access something inside of the function is to return it. 218 | 219 | We can also set variables to equal what a function returns. 220 | 221 | ```javascript 222 | function subtractsTwoNumbers(a, b) { 223 | const difference = a - b; 224 | return difference; 225 | } 226 | 227 | const differenceValue = subtractsTwoNumbers(10, 9); 228 | console.log(differenceValue); // 1 229 | console.log(difference); // undefined 230 | ``` 231 | 232 | We can see that difference is set inside of the function. The variable inside the function only belongs inside the function. 233 | 234 | ## Control Flow and Comparison Operators 235 | 236 | In this example we are going to use control flow and comparison operators. Control flow is a way for our function to check to see if something is `true`, and either running the code supplied if it is, or moving on if it is not. For this we will use the `if` keyword: 237 | 238 | ```javascript 239 | function canDrive(age) { 240 | if (age > 15) { 241 | return true; 242 | } 243 | 244 | return false; 245 | } 246 | 247 | canDrive(16); // true 248 | ``` 249 | 250 | Here we are taking a number (`age`) and checking to see if the statement is `true` (`16 > 15`), it is, so we will return `true`, and the function will stop. If it is not, it will skip that code and the function will return `false`. 251 | 252 | The "Greater Than" symbol ( `>` ) you see in the last example is called a Comparison Operator. Comparison Operators evaluate two items and return either `true` or `false`. These operators are: `<` , `<=`, `>`, `>=`, `===`, `!==` . We will learn more about these operators in the next lesson. 253 | 254 | ## Introduction to Node and NPM 255 | 256 | Node.js is a runtime environment developed originally for use on backend servers. We will need to install it on our machines in order to complete the exercises over the next four days. To install Node please click here: [Download and install Node.js](https://nodejs.org/en/download/). Node comes shipped with "NPM". NPM is a package manager for javascript packages and we will be using it throughout our time at Lambda School. Once you have installed Node.js, you do not need to do anything else to install NPM. 257 | 258 | ## Please open the homework folder and complete the assignment described in the README file 259 | 260 | ## Additional Resources 261 | 262 | * [Codecademy: Learn Javascript](https://www.codecademy.com/learn/learn-javascript) 263 | * [Udacity: Intro to Javascript](https://www.udacity.com/course/intro-to-javascript--ud803) 264 | * [MDN: Official Javascript Documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript) 265 | -------------------------------------------------------------------------------- /Lesson02-HTML-CSS/README.md: -------------------------------------------------------------------------------- 1 | # Lesson 2: HTML/CSS fundamentals 2 | (Attention: These are the class notes for the [Lambda School](http://www.lambdaschool.com) pre-course instruction workshop. This is meant to serve as an accompaniment to the class) 3 | 4 | In this lesson we will cover: 5 | 6 | * Introduction to HTML. 7 | * Basic HTML elements. 8 | * Introduction to CSS. 9 | * CSS selectors and the \ 141 | 142 | 143 | 144 | 145 | ``` 146 | 147 | ### selectors 148 | 149 | In order for us to apply styling rules to html elements, we have to know which elements to apply the rules to, in come selectors. 150 | You can select all elements of a certain type: p, div, body, etc. or you can apply a class or id to each individual element. We apply these selectors to the HTML tags themselves in the form of a flag: 151 | 152 | ```html 153 |
154 |
155 | ``` 156 | 157 | Ids: are titles that can only appear on a single element, think of it as you would your drivers license number ONLY you have that one number. 158 | 159 | Classes: on the other hand can apply to multiple elements. Think of it like a class room, usually you aren't the only person in a class, although you might be, the class is big enough for lots of people. 160 | 161 | We do not need to add anything to use every element of a certain type as a selector, CSS does that for us already. 162 | 163 | ### Anatomy of styling rules 164 | 165 | Now that we have our selectors in place we need to tell the browser what to do with those selectors. Inside of our style tags, we will insert the rules. Classes will always begin with ".", and Ids will always begin with "#", elements will begin with neither and just have the element name. After the name of the selector we will use braces ("{}") to hold our rules to that one selector. 166 | 167 | ```html 168 | 175 | ``` 176 | 177 | ## Basic CSS styling 178 | 179 | Now that we have some HTML elements selected we can begin to add styling. There are a LOT of different ways you can style an object, you can control how big or small it is, what color it is, where it is placed on the screen, or even if it is visible or not. We will go over some of the most common styling properties and how to use them. 180 | 181 | ### Styling rules rules 182 | Styling rules will need to adhere to a certain syntax in our CSS so that the browser knows how to read them properly. Within the braces, we will then have the name of the property, a colon(":") and the value of the rule, this will be followed by a semicolon(";") 183 | 184 | ```css 185 | div { 186 | styling_property: value of rule; 187 | } 188 | ``` 189 | 190 | 191 | ## Introduction to the Box Model 192 | 193 | We can consider all html elements to be boxes, the make up of each box is the content, padding, border and margin. This is known as the Box Model. 194 | 195 | ![Image](./boxModel.gif) 196 | 197 | ### height and width 198 | 199 | We can tell the browser exactly how wide and how tall we want our element(content) to be, this is used in divs, imgs, and other height based elements( in order to determine the size of text, we will need to use a different styling property ). Size values can be in lots of different measures, but the most common is the pixel "px". 200 | 201 | ```css 202 | div { 203 | height: 400px; 204 | width: 400px; 205 | } 206 | ``` 207 | ### margin 208 | 209 | The margin is the transparent area around the element that you want to leave open. It is the outermost layer in the Box Model. 210 | 211 | 212 | ### border 213 | 214 | Border will set a border around your element, you can determine the size color and style of the border. It will be set up in this order: width style color (a list of border styles can be found here: https://developer.mozilla.org/en-US/docs/Web/CSS/border). The border is outside the padding, but inside the margin. 215 | 216 | ```css 217 | div { 218 | border: 1px solid black; 219 | } 220 | ``` 221 | ### padding 222 | 223 | The padding is the transparent area between the border and the content. It is very similar to the margin. 224 | 225 | ### Box Model Calculation 226 | 227 | When we set the height and width of an element, we are only setting the content. In order to calculate the true height and width we have to factor in the padding, border and margin. 228 | 229 | * Padding is a transparent area around the content. 230 | * Border will wrap around the padding 231 | * Margin is the outermost transparent area wrapping around the entire box. 232 | 233 | Eg. If we set the height of the content to 20px and the width to 20px, the padding to 5px, border to 1px, and the margin to 10 px. 234 | 235 | Actual height = 25px(content) + 2*5px(padding, each side) + 2 * 1(border each side) + 2 * 10(margin, each side) = 57px 236 | 237 | Actual width = 25px(content) + 2*5px(padding, each side) + 2 * 1(border each side) + 2 * 10(margin, each side) = 57px 238 | 239 | Knowing this will help us size and position our elements correctly. 240 | 241 | ## A Couple of Other CSS Properties 242 | 243 | ### background 244 | 245 | Background can be set to a variety of rules, most common would be setting the background to a color or an image. Both are displayed below. 246 | 247 | ```css 248 | .divClass { 249 | background: red; 250 | } 251 | #divId { 252 | background: url('http://imageurl.com/image.jpg'); 253 | } 254 | ``` 255 | 256 | ### color 257 | 258 | Color is used for text only. It will set the color of your text 259 | 260 | ### font-size 261 | 262 | We cant use width or height for text, but we can determine the size of the font used. You can use any size unit here that you would use with a font in a word processor (px, em, in, etc) most popular is px 263 | 264 | 265 | 266 | ## External Stylesheets and the \ element 267 | 268 | We have gone over how to use the \