├── 002-terminal-basics-vscode └── video-examples │ ├── hello-again.js │ └── hello.js ├── 003-variables-primitive-types ├── exercise-solutions │ ├── problem-set-1.js │ ├── problem-set-2.js │ ├── problem-set-3.js │ └── problem-set-warmup.js ├── exercises │ ├── problem-set-1.js │ ├── problem-set-2.js │ ├── problem-set-3.js │ └── problem-set-warmup.js └── video-examples │ └── primitives.js ├── 004-mathematical-operators ├── exercise-solutions │ ├── problem-set-1.js │ ├── problem-set-2.js │ ├── problem-set-3.js │ ├── problem-set-BONUS.js │ └── problem-set-warmup.js ├── exercises │ ├── problem-set-1.js │ ├── problem-set-2.js │ ├── problem-set-3.js │ ├── problem-set-BONUS.js │ └── problem-set-warmup.js └── video-examples │ ├── assignments-math.js │ └── math-operators.js ├── 005-boolean-operators ├── exercise-solutions │ ├── problem-set-1.js │ ├── problem-set-2.js │ ├── problem-set-3.js │ ├── problem-set-BONUS.js │ └── problem-set-warmup.js ├── exercises │ ├── problem-set-1.js │ ├── problem-set-2.js │ ├── problem-set-3.js │ ├── problem-set-BONUS.js │ └── problem-set-warmup.js └── video-examples │ ├── and-or.js │ ├── boolean-assignment.js │ └── boolean-operators.js ├── 006-conditional-statements ├── exercise-solutions │ ├── problem-set-1.js │ ├── problem-set-2.js │ ├── problem-set-3.js │ └── problem-set-warmup.js ├── exercises │ ├── problem-set-1.js │ ├── problem-set-2.js │ ├── problem-set-3.js │ └── problem-set-warmup.js └── video-examples │ ├── if-else-if-statement.js │ ├── if-else-statement.js │ └── if-statement.js ├── 007-while-loops ├── exercise-solutions │ ├── problem-set-1.js │ ├── problem-set-2.js │ ├── problem-set-3.js │ └── problem-set-warmup.js ├── exercises │ ├── problem-set-1.js │ ├── problem-set-2.js │ ├── problem-set-3.js │ └── problem-set-warmup.js └── video-examples │ ├── break-2.js │ ├── break.js │ └── while-loops.js ├── 008-for-loops ├── exercise-solutions │ ├── problem-set-1.js │ ├── problem-set-2.js │ ├── problem-set-3.js │ └── problem-set-warmup.js ├── exercises │ ├── problem-set-1.js │ ├── problem-set-2.js │ ├── problem-set-3.js │ └── problem-set-warmup.js └── video-examples │ ├── break.js │ ├── continue.js │ ├── for-loops1.js │ └── for-loops2.js ├── 009-functions ├── exercise-solutions │ ├── exercise-1.js │ ├── exercise-2.js │ ├── exercise-3.js │ └── exercise-warmup.js ├── exercises │ ├── exercise-1.js │ ├── exercise-2.js │ ├── exercise-3.js │ └── exercise-warmup.js └── video-examples │ ├── functions-2.js │ ├── functions-3.js │ ├── functions-4.js │ └── functions.js ├── 010-arrays ├── exercise-solutions │ ├── exercise-1.js │ ├── exercise-2.js │ ├── exercise-3.js │ ├── exercise-BONUS.js │ └── exercise-warmup.js ├── exercises │ ├── exercise-1.js │ ├── exercise-2.js │ ├── exercise-3.js │ ├── exercise-BONUS.js │ └── exercise-warmup.js └── video-examples │ ├── array-pop.js │ ├── array-push.js │ ├── array-shift.js │ ├── array-unshift.js │ ├── arrays-concepts.js │ └── indices.js ├── 011-array-map ├── exercise-solutions │ ├── BONUS-exercise.js │ ├── exercise-1.js │ ├── exercise-2.js │ ├── exercise-3.js │ └── warmup-exercise.js ├── exercises │ ├── BONUS-exercise.js │ ├── exercise-1.js │ ├── exercise-2.js │ ├── exercise-3.js │ └── warmup-exercise.js └── video-examples │ ├── map-intro.js │ └── map-return.js ├── 012-array-filter ├── exercise-solutions │ ├── BONUS-exercise.js │ ├── exercise-1.js │ ├── exercise-2.js │ ├── exercise-3.js │ └── warmup-exercise.js ├── exercises │ ├── BONUS-exercise.js │ ├── exercise-1.js │ ├── exercise-2.js │ ├── exercise-3.js │ └── warmup-exercise.js └── video-examples │ ├── filter-bugs.js │ └── filter-intro.js ├── 013-array-reduce ├── exercise-solutions │ ├── BONUS-exercise.js │ ├── exercise-1.js │ ├── exercise-2.js │ ├── exercise-3.js │ └── warmup-exercise.js ├── exercises │ ├── BONUS-exercise.js │ ├── exercise-1.js │ ├── exercise-2.js │ ├── exercise-3.js │ └── warmup-exercise.js └── video-examples │ ├── reduce-array.js │ ├── reduce-intro.js │ └── reduce-string.js ├── 014-objects ├── exercise-solutions │ ├── BONUS-exercise.js │ ├── exercise-1.js │ ├── exercise-2.js │ ├── exercise-3.js │ └── warmup-exercise.js ├── exercises │ ├── BONUS-exercise.js │ ├── exercise-1.js │ ├── exercise-2.js │ ├── exercise-3.js │ └── warmup-exercise.js └── video-examples │ ├── objects-delete.js │ ├── objects-in.js │ ├── objects-intro.js │ └── objects-methods.js ├── 015-maps ├── exercise-solutions │ ├── BONUS-exercise-1.js │ ├── BONUS-exercise-2.js │ ├── exercise-1.js │ ├── exercise-2.js │ ├── exercise-3.js │ └── warmup-exercise.js ├── exercises │ ├── BONUS-exercise-1.js │ ├── BONUS-exercise-2.js │ ├── exercise-1.js │ ├── exercise-2.js │ ├── exercise-3.js │ └── warmup-exercise.js └── video-examples │ └── map-intro.js ├── 016-sets ├── exercise-solutions │ ├── exercise-1.js │ ├── exercise-2.js │ ├── exercise-3.js │ └── warmup-exercise.js ├── exercises │ ├── exercise-1.js │ ├── exercise-2.js │ ├── exercise-3.js │ └── warmup-exercise.js └── video-examples │ └── set-basics.js ├── 017-for-of-loops ├── exercise-solutions │ ├── exercise-1.js │ ├── exercise-2.js │ ├── exercise-3.js │ └── warmup-exercise.js ├── exercises │ ├── exercise-1.js │ ├── exercise-2.js │ ├── exercise-3.js │ └── warmup-exercise.js └── video-examples │ ├── for-of-arrays.js │ ├── for-of-maps.js │ ├── for-of-objects.js │ ├── for-of-sets.js │ └── for-of-strings.js ├── 018-Project-1-Blackjack-Game ├── exercise-solutions │ └── blackjack.js ├── exercises │ ├── advice.js │ ├── example-demos.png │ ├── pre-requisites.js │ ├── project-tips.js │ └── requirements.js └── video-examples │ ├── advice.js │ ├── example-demos.png │ ├── pre-requisites.js │ ├── project-tips.js │ └── requirements.js ├── 019-promises ├── exercise-solutions │ ├── BONUS-exercise.js │ ├── exercise-1.js │ ├── exercise-2.js │ ├── exercise-3.js │ └── warmup-exercise.js ├── exercises │ ├── BONUS-exercise.js │ ├── exercise-1.js │ ├── exercise-2.js │ ├── exercise-3.js │ └── warmup-exercise.js └── video-examples │ └── newPromise.js ├── 020-error-handling ├── exercise-solutions │ ├── exercise-1.js │ ├── exercise-2.js │ ├── exercise-3.js │ └── warmup-exercise.js ├── exercises │ ├── exercise-1.js │ ├── exercise-2.js │ ├── exercise-3.js │ └── warmup-exercise.js └── video-examples │ ├── throw.js │ ├── try-catch-object.js │ ├── try-catch.js │ └── try-scope.js ├── 021-async-await ├── exercise-solutions │ ├── exercise-1.js │ ├── exercise-2.js │ ├── exercise-3.js │ └── warmup-exercise.js ├── exercises │ ├── exercise-1.js │ ├── exercise-2.js │ ├── exercise-3.js │ └── warmup-exercise.js └── video-examples │ ├── async-await.js │ ├── errors.js │ ├── pausing.js │ └── return.js ├── 022-array-object-spread-syntax ├── exercise-solutions │ ├── exercise-1.js │ ├── exercise-2.js │ ├── exercise-3.js │ └── warmup-exercise.js ├── exercises │ ├── exercise-1.js │ ├── exercise-2.js │ ├── exercise-3.js │ └── warmup-exercise.js └── video-examples │ ├── array-shallow.js │ ├── intro.js │ ├── maps.js │ ├── obj-shallow.js │ ├── object-dups.js │ ├── objects.js │ ├── sets.js │ └── strings.js ├── 023-destructuring-syntax ├── exercise-solutions │ ├── exercise-1.js │ ├── exercise-2.js │ ├── exercise-3.js │ └── warmup-exercise.js ├── exercises │ ├── exercise-1.js │ ├── exercise-2.js │ ├── exercise-3.js │ └── warmup-exercise.js └── video-examples │ ├── array-intro.js │ └── objects-intro.js ├── 024-ternary-operator ├── exercise-solutions │ ├── exercise-1.js │ ├── exercise-2.js │ ├── exercise-3.js │ └── warmup-exercise.js ├── exercises │ ├── exercise-1.js │ ├── exercise-2.js │ ├── exercise-3.js │ └── warmup-exercise.js └── video-examples │ ├── functions.js │ ├── intro.js │ └── map.js ├── 025-switch-statement ├── exercise-solutions │ ├── exercise-1.js │ ├── exercise-2.js │ ├── exercise-3.js │ └── warmup-exercise.js ├── exercises │ ├── exercise-1.js │ ├── exercise-2.js │ ├── exercise-3.js │ └── warmup-exercise.js └── video-examples │ └── intro.js ├── 026-generators ├── exercise-solutions │ ├── exercise-1.js │ ├── exercise-2.js │ ├── exercise-3.js │ └── warmup-exercise.js ├── exercises │ ├── exercise-1.js │ ├── exercise-2.js │ ├── exercise-3.js │ └── warmup-exercise.js └── video-examples │ ├── delegation.js │ ├── infinite.js │ ├── intro.js │ ├── loops.js │ └── return.js ├── 027-async-generators ├── exercise-solutions │ ├── exercise-1.js │ ├── exercise-2.js │ ├── exercise-3.js │ └── warmup-exercise.js ├── exercises │ ├── exercise-1.js │ ├── exercise-2.js │ ├── exercise-3.js │ └── warmup-exercise.js └── video-examples │ ├── async.js │ ├── infinite.js │ └── promise.js ├── 028-symbols ├── exercise-solutions │ ├── exercise-1.js │ ├── exercise-2.js │ ├── exercise-3.js │ └── warmup-exercise.js ├── exercises │ ├── exercise-1.js │ ├── exercise-2.js │ ├── exercise-3.js │ └── warmup-exercise.js └── video-examples │ ├── admin.js │ ├── intro.js │ ├── iterator.js │ └── symbol.js ├── 029-regular-expressions ├── exercise-solutions │ ├── exercise-1.js │ ├── exercise-2.js │ ├── exercise-3.js │ └── warmup-exercise.js ├── exercises │ ├── exercise-1.js │ ├── exercise-2.js │ ├── exercise-3.js │ └── warmup-exercise.js └── video-examples │ └── intro.js ├── 030-modules ├── exercise-solutions │ ├── exercise-1.js │ ├── exercise-2.js │ ├── exercise-3.js │ ├── exercise1 │ │ ├── main.js │ │ ├── package.json │ │ └── utils.js │ ├── exercise2 │ │ ├── main.js │ │ ├── moduleA.js │ │ ├── moduleB.js │ │ ├── modules.js │ │ └── package.json │ ├── exercise3 │ │ ├── main.js │ │ ├── moduleA.js │ │ ├── moduleB.js │ │ └── package.json │ ├── warmup-exercise.js │ └── warmup │ │ ├── main.js │ │ ├── package.json │ │ └── utils.js ├── exercises │ ├── exercise-1.js │ ├── exercise-2.js │ ├── exercise-3.js │ └── warmup-exercise.js └── video-examples │ ├── async-jungle.js │ ├── jungle.js │ ├── monkey.js │ └── package.json ├── 031-npm ├── exercise-solutions │ ├── exercise-1.js │ ├── exercise-2.js │ ├── exercise-3.js │ ├── exercise1 │ │ ├── main.js │ │ ├── package-lock.json │ │ └── package.json │ ├── exercise2 │ │ ├── hello.txt │ │ ├── main.js │ │ ├── package-lock.json │ │ └── package.json │ ├── exercise3 │ │ ├── hello.js │ │ ├── package-lock.json │ │ └── package.json │ ├── warmup-exercise.js │ └── warmup │ │ ├── main.js │ │ ├── package-lock.json │ │ └── package.json ├── exercises │ ├── exercise-1.js │ ├── exercise-2.js │ ├── exercise-3.js │ └── warmup-exercise.js └── video-examples │ ├── main.js │ ├── package-lock.json │ ├── package.json │ └── utilities │ ├── package.json │ └── util.js ├── 032-fetch-api ├── exercise-solutions │ ├── exercise-1.js │ ├── exercise-2.js │ ├── exercise-3.js │ ├── package-lock.json │ ├── package.json │ └── warmup-exercise.js ├── exercises │ ├── exercise-1.js │ ├── exercise-2.js │ ├── exercise-3.js │ └── warmup-exercise.js └── video-examples │ ├── fetch.js │ ├── package-lock.json │ └── package.json ├── 033-Project-2-Pokemon-Downloader-CLI ├── exercise-solutions │ ├── package-lock.json │ ├── package.json │ ├── pokemon-downloader.js │ ├── prompts.js │ └── saving.js ├── exercises │ ├── advice.js │ ├── mew_downloaded.png │ ├── pikachu_downloaded.png │ ├── pokemon-downloader-demo.png │ ├── pre-requisites.js │ ├── project-tips.js │ ├── requirements.js │ └── stats_example.png └── video-examples │ ├── advice.js │ ├── mew_downloaded.png │ ├── pikachu_downloaded.png │ ├── pokemon-downloader-demo.png │ ├── pre-requisites.js │ ├── project-tips.js │ ├── requirements.js │ └── stats_example.png ├── 034-recursion ├── exercise-solutions │ ├── BONUS-exercise.js │ ├── exercise-1.js │ ├── exercise-2.js │ ├── exercise-3.js │ └── warmup-exercise.js ├── exercises │ ├── BONUS-exercise.js │ ├── exercise-1.js │ ├── exercise-2.js │ ├── exercise-3.js │ └── warmup-exercise.js └── video-examples │ ├── counter.js │ ├── mine.js │ └── nums.js ├── 035-closure ├── exercise-solutions │ ├── BONUS-exercise.js │ ├── exercise-1.js │ ├── exercise-2.js │ ├── exercise-3.js │ ├── package-lock.json │ ├── package.json │ └── warmup-exercise.js ├── exercises │ ├── BONUS-exercise.js │ ├── exercise-1.js │ ├── exercise-2.js │ ├── exercise-3.js │ └── warmup-exercise.js └── video-examples │ ├── closure.js │ └── intro.js ├── 036-prototypes ├── exercise-solutions │ ├── BONUS-exercise.js │ ├── exercise-1.js │ ├── exercise-2.js │ ├── exercise-3.js │ └── warmup-exercise.js ├── exercises │ ├── BONUS-exercise.js │ ├── exercise-1.js │ ├── exercise-2.js │ ├── exercise-3.js │ └── warmup-exercise.js └── video-examples │ ├── animal.js │ ├── array.js │ ├── getters.js │ └── object.js ├── 037-this-keyword ├── exercise-solutions │ ├── BONUS-exercise-1.js │ ├── BONUS-exercise-2.js │ ├── exercise-1.js │ ├── exercise-2.js │ ├── exercise-3.js │ └── warmup-exercise.js ├── exercises │ ├── BONUS-exercise-1.js │ ├── BONUS-exercise-2.js │ ├── exercise-1.js │ ├── exercise-2.js │ ├── exercise-3.js │ └── warmup-exercise.js └── video-examples │ ├── alex.js │ ├── bind.js │ ├── call.js │ ├── new.js │ └── prototype.js ├── 038-classes-oop-intro ├── exercise-solutions │ ├── BONUS-exercise-1.js │ ├── exercise-1.js │ ├── exercise-2.js │ ├── exercise-3.js │ └── warmup-exercise.js ├── exercises │ ├── BONUS-exercise-1.js │ ├── exercise-1.js │ ├── exercise-2.js │ ├── exercise-3.js │ └── warmup-exercise.js └── video-examples │ ├── badIntro.js │ ├── manualClass.js │ └── slightlyBetter.js ├── 039-classes-oop-inheritance-polymorphism ├── exercise-solutions │ ├── BONUS-exercise-1.js │ ├── exercise-1.js │ ├── exercise-2.js │ ├── exercise-3.js │ └── warmup-exercise.js ├── exercises │ ├── BONUS-exercise-1.js │ ├── exercise-1.js │ ├── exercise-2.js │ ├── exercise-3.js │ └── warmup-exercise.js └── video-examples │ ├── parentMethod.js │ ├── polymorphism.js │ └── subclass.js ├── 040-encapsulation-static ├── exercise-solutions │ ├── BONUS-exercise-1.js │ ├── exercise-1.js │ ├── exercise-2.js │ ├── exercise-3.js │ └── warmup-exercise.js ├── exercises │ ├── BONUS-exercise-1.js │ ├── exercise-1.js │ ├── exercise-2.js │ ├── exercise-3.js │ └── warmup-exercise.js └── video-examples │ ├── database.js │ └── static.js ├── 041-Capstone-project-rpg-game ├── exercise-solutions │ ├── EnemyObject.js │ ├── Grid.js │ ├── GridObject.js │ ├── ItemObject.js │ ├── Player.js │ ├── package-lock.json │ ├── package.json │ └── playerPrompts.js ├── exercises │ ├── EnemyObject.js │ ├── Grid.js │ ├── GridObject.js │ ├── ItemObject.js │ ├── Player.js │ ├── package-lock.json │ ├── package.json │ └── playerPrompts.js └── video-examples │ ├── EnemyObject.js │ ├── Grid.js │ ├── GridObject.js │ ├── ItemObject.js │ ├── Player.js │ ├── package-lock.json │ ├── package.json │ └── playerPrompts.js └── README.md /002-terminal-basics-vscode/video-examples/hello-again.js: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Nooder/javascript-in-depth/ba8447af2e4edf784606f946da4a682539fa52da/002-terminal-basics-vscode/video-examples/hello-again.js -------------------------------------------------------------------------------- /002-terminal-basics-vscode/video-examples/hello.js: -------------------------------------------------------------------------------- 1 | console.log("Hello there!"); 2 | -------------------------------------------------------------------------------- /003-variables-primitive-types/exercise-solutions/problem-set-1.js: -------------------------------------------------------------------------------- 1 | /* 2 | 1. Create a variable called name that points at a string containing your name 3 | 2. On the next line, re-assign the variable above to your favourite musician's name 4 | 3. On the next line, re-assign the variable again to the value: true 5 | 3. On the next line, re-assign the variable one last time to the value: 42 6 | 7 | After each of the above steps, log out the variable to the terminal with console.log. 8 | */ 9 | 10 | let name = "Nader"; 11 | console.log(name); 12 | 13 | name = "Linkin Park"; 14 | console.log(name); 15 | 16 | name = true; 17 | console.log(name); 18 | 19 | name = 42; 20 | console.log(name); 21 | -------------------------------------------------------------------------------- /003-variables-primitive-types/exercise-solutions/problem-set-2.js: -------------------------------------------------------------------------------- 1 | /* 2 | 1. Declare a variable using let with any name you like, but without a value. 3 | 2. On a separate line, assign the variable the String: "Moo!" 4 | 3. Log out this variable to the terminal using console.log 5 | 6 | Repeat the above steps but try using a const variable. What happens? 7 | */ 8 | 9 | let myVariable; 10 | myVariable = "Moo!"; 11 | console.log(myVariable); 12 | 13 | const anotherVariable = "Moo!"; 14 | // anotherVariable = "Moo!"; 15 | console.log(anotherVariable); 16 | -------------------------------------------------------------------------------- /003-variables-primitive-types/exercise-solutions/problem-set-3.js: -------------------------------------------------------------------------------- 1 | /* 2 | Use Google/search to look up the *typeof* operator in Javascript. 3 | 4 | Use typeof to log out the types for each of the 5 primitive types 5 | to the terminal using console.log. 6 | 7 | *HINT* - MDN Web Docs are a good resource 8 | */ 9 | 10 | console.log(typeof 42); 11 | console.log(typeof "Hi!"); 12 | console.log(typeof true); 13 | console.log(typeof null); 14 | console.log(typeof undefined); 15 | -------------------------------------------------------------------------------- /003-variables-primitive-types/exercise-solutions/problem-set-warmup.js: -------------------------------------------------------------------------------- 1 | /* 2 | Create a constant variable of each of the following primitive types: 3 | - String 4 | - Number 5 | - Boolean 6 | - Null 7 | - Undefined 8 | 9 | Use console.log to log out each variable to the terminal at the end. 10 | 11 | HINT1: You can run your file in the terminal using this command: node 12 | For example, if your file is called ps1.js, you would type: node ps1.js 13 | 14 | HINT2: Make sure your terminal is "looking at" the correct folder where your code is 15 | */ 16 | 17 | const colour = "Blue"; 18 | const age = 22; 19 | const happy = true; 20 | const emptyThing = null; 21 | const anotherEmptyThing = undefined; 22 | 23 | console.log(colour); 24 | console.log(age); 25 | console.log(happy); 26 | console.log(emptyThing); 27 | console.log(anotherEmptyThing); 28 | -------------------------------------------------------------------------------- /003-variables-primitive-types/exercises/problem-set-1.js: -------------------------------------------------------------------------------- 1 | /* 2 | 1. Create a variable called name that points at a string containing your name 3 | 2. On the next line, re-assign the variable above to your favourite musician's name 4 | 3. On the next line, re-assign the variable again to the value: true 5 | 3. On the next line, re-assign the variable one last time to the value: 42 6 | 7 | After each of the above steps, log out the variable to the terminal with console.log. 8 | */ 9 | -------------------------------------------------------------------------------- /003-variables-primitive-types/exercises/problem-set-2.js: -------------------------------------------------------------------------------- 1 | /* 2 | 1. Declare a variable using let with any name you like, but without a value. 3 | 2. On a separate line, assign the variable the String: "Moo!" 4 | 3. Log out this variable to the terminal using console.log 5 | 6 | Repeat the above steps but try using a const variable. What happens? 7 | */ 8 | -------------------------------------------------------------------------------- /003-variables-primitive-types/exercises/problem-set-3.js: -------------------------------------------------------------------------------- 1 | /* 2 | Use Google/search to look up the *typeof* operator in Javascript. 3 | 4 | Use typeof to log out the types for each of the 5 primitive types 5 | to the terminal using console.log. 6 | 7 | *HINT* - MDN Web Docs are a good resource 8 | */ 9 | -------------------------------------------------------------------------------- /003-variables-primitive-types/exercises/problem-set-warmup.js: -------------------------------------------------------------------------------- 1 | /* 2 | Create a constant variable of each of the following primitive types: 3 | - String 4 | - Number 5 | - Boolean 6 | - Null 7 | - Undefined 8 | 9 | Use console.log to log out each variable to the terminal at the end. 10 | 11 | HINT1: You can run your file in the terminal using this command: node 12 | For example, if your file is called ps1.js, you would type: node ps1.js 13 | 14 | HINT2: Make sure your terminal is "looking at" the correct folder where your code is 15 | */ 16 | -------------------------------------------------------------------------------- /003-variables-primitive-types/video-examples/primitives.js: -------------------------------------------------------------------------------- 1 | // Strings: 2 | 3 | let city = "Toronto"; 4 | 5 | let country; 6 | country = "Canada"; 7 | 8 | country = "India"; 9 | 10 | const name = "Monkey"; 11 | 12 | // Numbers: 13 | 14 | const age = 20; 15 | 16 | let price = 1.23; 17 | 18 | // Booleans: 19 | 20 | const happy = true; 21 | let sad = false; 22 | 23 | // Null and Undefined: 24 | 25 | const empty = null; 26 | const empty2 = undefined; 27 | -------------------------------------------------------------------------------- /004-mathematical-operators/exercise-solutions/problem-set-1.js: -------------------------------------------------------------------------------- 1 | /* 2 | Before printing these out, see if you can calculate them yourself mathematically: 3 | 4 | 1. Print out 5 / 2 5 | 2. Print out 5 % 2 6 | 3. Print out 5 ** 2 7 | 8 | 4. Print out 6 / 2 9 | 5. Print out 6 % 2 10 | 6. Print out 6 ** 2 11 | */ 12 | 13 | console.log(5 / 2); // 2.5 14 | console.log(5 % 2); // 1 15 | console.log(5 ** 2); // 25 16 | 17 | console.log(6 / 2); // 3 18 | console.log(6 % 2); // 0 19 | console.log(6 ** 2); // 36 20 | -------------------------------------------------------------------------------- /004-mathematical-operators/exercise-solutions/problem-set-2.js: -------------------------------------------------------------------------------- 1 | /* 2 | 1. Create a let variable called "points" and print it out 3 | 2. Assign "points" the number 20 and print it out 4 | 3. Add 15 to "points" and print it out 5 | 6 | Question1: What are all the ways you can achieve step 3 above? 7 | Question2: What would happen if you tried to do this with a const variable? 8 | */ 9 | 10 | let points; 11 | console.log(points); 12 | 13 | // const points; 14 | // console.log(points) 15 | 16 | points = 20; 17 | console.log(points); 18 | 19 | // points = points + 15; 20 | points += 15; 21 | console.log(points); 22 | -------------------------------------------------------------------------------- /004-mathematical-operators/exercise-solutions/problem-set-3.js: -------------------------------------------------------------------------------- 1 | /* 2 | Try to calculate these all yourself before coding them: 3 | 4 | 1. What is 5 / 5? 5 | 2. What is 5 % 5? 6 | 3. What is 256 / 2? 7 | 4. What is 256 % 10? 8 | 9 | BONUS: What are all the possible values of ANY_NUMBER % 2? 10 | BONUS2: What are all the possible values of ANY_NUMBER % 10? 11 | */ 12 | 13 | console.log(5 / 5); // 1 14 | console.log(5 % 5); // 0 15 | console.log(256 / 2); // 128 16 | console.log(256 % 10); // 6 17 | -------------------------------------------------------------------------------- /004-mathematical-operators/exercise-solutions/problem-set-BONUS.js: -------------------------------------------------------------------------------- 1 | /* 2 | 1. What happens when you add 2 strings together? 3 | 2. What about when you add a number to a string? 4 | 3. How about when you add booleans together? 5 | 6 | Try to think about how these behaviours might work, 7 | as well as why it might happen. 8 | */ 9 | 10 | // string concatenation 11 | let animal = "dog"; 12 | animal += " says woof!"; 13 | console.log(animal); 14 | 15 | let hello = "cat" + 10; 16 | console.log(hello); 17 | 18 | let bools = true + true; 19 | console.log(bools); 20 | -------------------------------------------------------------------------------- /004-mathematical-operators/exercise-solutions/problem-set-warmup.js: -------------------------------------------------------------------------------- 1 | /* 2 | 1. Use let to create a variable that points at a String 3 | - Then "add" another String to this same variable and print it out 4 | 2. Use let to create a variable that points to a Number 5 | - Then add another Number to this same variable and print it out 6 | */ 7 | 8 | let name = "monkey"; 9 | name = name + " says hello!"; 10 | 11 | console.log(name); 12 | 13 | let points = 40; 14 | points += 10; 15 | console.log(points); 16 | -------------------------------------------------------------------------------- /004-mathematical-operators/exercises/problem-set-1.js: -------------------------------------------------------------------------------- 1 | /* 2 | Before printing these out, see if you can calculate them yourself mathematically: 3 | 4 | 1. Print out 5 / 2 5 | 2. Print out 5 % 2 6 | 3. Print out 5 ** 2 7 | 8 | 4. Print out 6 / 2 9 | 5. Print out 6 % 2 10 | 6. Print out 6 ** 2 11 | */ 12 | -------------------------------------------------------------------------------- /004-mathematical-operators/exercises/problem-set-2.js: -------------------------------------------------------------------------------- 1 | /* 2 | 1. Create a let variable called "points" and print it out 3 | 2. Assign "points" the number 20 and print it out 4 | 3. Add 15 to "points" and print it out 5 | 6 | Question1: What are all the ways you can achieve step 3 above? 7 | Question2: What would happen if you tried to do this with a const variable? 8 | */ 9 | -------------------------------------------------------------------------------- /004-mathematical-operators/exercises/problem-set-3.js: -------------------------------------------------------------------------------- 1 | /* 2 | Try to calculate these all yourself before coding them: 3 | 4 | 1. What is 5 / 5? 5 | 2. What is 5 % 5? 6 | 3. What is 256 / 2? 7 | 4. What is 256 % 10? 8 | 9 | BONUS: What are all the possible values of ANY_NUMBER % 2? 10 | BONUS2: What are all the possible values of ANY_NUMBER % 10? 11 | */ 12 | -------------------------------------------------------------------------------- /004-mathematical-operators/exercises/problem-set-BONUS.js: -------------------------------------------------------------------------------- 1 | /* 2 | 1. What happens when you add 2 strings together? 3 | 2. What about when you add a number to a string? 4 | 3. How about when you add booleans together? 5 | 6 | Try to think about how these behaviours might work, 7 | as well as why it might happen. 8 | */ 9 | 10 | // string concatenation 11 | -------------------------------------------------------------------------------- /004-mathematical-operators/exercises/problem-set-warmup.js: -------------------------------------------------------------------------------- 1 | /* 2 | 1. Use let to create a variable that points at a String 3 | - Then "add" another String to this same variable and print it out 4 | 2. Use let to create a variable that points to a Number 5 | - Then add another Number to this same variable and print it out 6 | */ 7 | -------------------------------------------------------------------------------- /004-mathematical-operators/video-examples/assignments-math.js: -------------------------------------------------------------------------------- 1 | let points = 10; 2 | points++; // points = points + 1; 3 | console.log(points); 4 | 5 | let score = 20; 6 | score--; 7 | score--; 8 | console.log(score); 9 | 10 | score += 100; 11 | console.log(score); 12 | score -= 50; 13 | console.log(score); 14 | 15 | let age = 7; 16 | age *= 2; // age = age * 2; 17 | console.log(age); 18 | 19 | age /= 2; 20 | console.log(age); 21 | 22 | // age is 7 here 23 | // age %= 7; // age = age % 7; 24 | // console.log(age); 25 | 26 | // age is 7 here 27 | age **= 2; 28 | console.log(age); 29 | -------------------------------------------------------------------------------- /004-mathematical-operators/video-examples/math-operators.js: -------------------------------------------------------------------------------- 1 | // Addition 2 | 3 | let age = 10 + 23; 4 | console.log(age); // 33 5 | 6 | // Subtraction 7 | 8 | let points = 50 - 19; 9 | console.log(points); 10 | 11 | // Multiplication 12 | let score = 7 * 50; 13 | console.log(score); 14 | 15 | // Division 16 | let divide = 100 / 13; 17 | console.log(divide); 18 | 19 | // Modulus (Remainder) 20 | let mod = 9 % 3; 21 | console.log(mod); 22 | 23 | // Exponentiation 24 | let exp = 4 ** 3; 25 | console.log(exp); 26 | -------------------------------------------------------------------------------- /005-boolean-operators/exercise-solutions/problem-set-1.js: -------------------------------------------------------------------------------- 1 | /* 2 | Try to think of these answers before coding and printing them out: 3 | 4 | 1. What is the result of: "1" === 1 5 | 2. What is the result of: (3 > 2) === true 6 | 3. What is the result of: (2 ** 2) !== "4" 7 | 4. What is the result of: (true === true) && (false === false) 8 | */ 9 | 10 | console.log("1" === 1); // 1 === 1 11 | console.log(3 > 2 === true); // true === true 12 | console.log(2 ** 2 !== "4"); // 4 !== "4" 13 | console.log(true === true && false === false); // true && true 14 | -------------------------------------------------------------------------------- /005-boolean-operators/exercise-solutions/problem-set-2.js: -------------------------------------------------------------------------------- 1 | /* 2 | What would each of these variables evaluate to? 3 | 4 | 1. const one = true && "hi"; 5 | 2. const two = false && "bye"; 6 | 3. const three = true || "meow"; 7 | 4. const four = false || "rawr"; 8 | 9 | Print them out to the console to see if you got them right. 10 | 11 | HINT: 3 & 4 are more challenging, so don't worry if you don't 12 | get them right away! 13 | */ 14 | 15 | const one = true && "hi"; 16 | console.log(one); 17 | 18 | const two = false && "bye"; 19 | console.log(two); 20 | 21 | const three = true || "meow"; 22 | console.log(three); 23 | 24 | const four = false || "rawr"; 25 | console.log(four); 26 | -------------------------------------------------------------------------------- /005-boolean-operators/exercise-solutions/problem-set-3.js: -------------------------------------------------------------------------------- 1 | /* 2 | What would each of these lines of code do: 3 | 4 | 1. true && console.log("moo"); 5 | 2. false && console.log("moo moo?") 6 | 3. true || console.log("hello friend"); 7 | 4. false || console.log("bye friend"); 8 | 9 | This is a very challenging problem set. Once you see the results, 10 | try to see if you can see WHY it works that way. This will come in 11 | very handy in the future. 12 | */ 13 | 14 | true && console.log("moo"); 15 | false && console.log("moo moo?"); 16 | 17 | true || console.log("hello friend"); 18 | false || console.log("bye friend"); 19 | -------------------------------------------------------------------------------- /005-boolean-operators/exercise-solutions/problem-set-warmup.js: -------------------------------------------------------------------------------- 1 | /* 2 | Write out the truth tables for the following boolean operators 3 | using two boolean values, one on each side: 4 | - AND 5 | - OR 6 | - NOT 7 | 8 | Use console.log to log out the results for each. 9 | 10 | HINT: AND and OR will have 4 possibilities, while NOT has 2 11 | HINT2: console.log(true && true) 12 | */ 13 | 14 | console.log("---AND---"); 15 | console.log(true && true); 16 | console.log(true && false); 17 | console.log(false && true); 18 | console.log(false && false); 19 | 20 | console.log("---OR---"); 21 | console.log(true || true); 22 | console.log(true || false); 23 | console.log(false || true); 24 | console.log(false || false); 25 | 26 | console.log("---NOT---"); 27 | console.log(!true); 28 | console.log(!false); 29 | -------------------------------------------------------------------------------- /005-boolean-operators/exercises/problem-set-1.js: -------------------------------------------------------------------------------- 1 | /* 2 | Try to think of these answers before coding and printing them out: 3 | 4 | 1. What is the result of: "1" === 1 5 | 2. What is the result of: (3 > 2) === true 6 | 3. What is the result of: (2 ** 2) !== "4" 7 | 4. What is the result of: (true === true) && (false === false) 8 | */ 9 | -------------------------------------------------------------------------------- /005-boolean-operators/exercises/problem-set-2.js: -------------------------------------------------------------------------------- 1 | /* 2 | What would each of these variables evaluate to? 3 | 4 | 1. const one = true && "hi"; 5 | 2. const two = false && "bye"; 6 | 3. const three = true || "meow"; 7 | 4. const four = false || "rawr"; 8 | 9 | Print them out to the console to see if you got them right. 10 | 11 | HINT: 3 & 4 are more challenging, so don't worry if you don't 12 | get them right away! 13 | */ 14 | -------------------------------------------------------------------------------- /005-boolean-operators/exercises/problem-set-3.js: -------------------------------------------------------------------------------- 1 | /* 2 | What would each of these lines of code do: 3 | 4 | 1. true && console.log("moo"); 5 | 2. false && console.log("moo moo?") 6 | 3. true || console.log("hello friend"); 7 | 4. false || console.log("bye friend"); 8 | 9 | This is a very challenging problem set. Once you see the results, 10 | try to see if you can see WHY it works that way. This will come in 11 | very handy in the future. 12 | */ 13 | -------------------------------------------------------------------------------- /005-boolean-operators/exercises/problem-set-BONUS.js: -------------------------------------------------------------------------------- 1 | /* 2 | First, lookup how logical AND, OR and NULLISH assignment work 3 | using Google. Then try the following examples. 4 | 5 | What would each of the following variables evaluate to: 6 | 7 | 1. let username = ""; 8 | username &&= "tiger"; 9 | 10 | 2. let vip = 0; 11 | vip ||= 3; 12 | 13 | 3. let loggedIn = null; 14 | loggedIn ??= 0; 15 | 16 | Log each of the values out to see the results. 17 | 18 | This is very very challenging, it might take several tries 19 | or coming back to it in the future when it's more relevant. 20 | */ 21 | -------------------------------------------------------------------------------- /005-boolean-operators/exercises/problem-set-warmup.js: -------------------------------------------------------------------------------- 1 | /* 2 | Write out the truth tables for the following boolean operators 3 | using two boolean values, one on each side: 4 | - AND 5 | - OR 6 | - NOT 7 | 8 | Use console.log to log out the results for each. 9 | 10 | HINT: AND and OR will have 4 possibilities, while NOT has 2 11 | HINT2: console.log(true && true) 12 | */ 13 | -------------------------------------------------------------------------------- /005-boolean-operators/video-examples/and-or.js: -------------------------------------------------------------------------------- 1 | // and or operators 2 | console.log(true && true); 3 | console.log(true && false); 4 | console.log(false && true); 5 | console.log(false && false); 6 | 7 | console.log("-------"); 8 | 9 | console.log(true || true); 10 | console.log(true || false); 11 | console.log(false || true); 12 | console.log(false || false); 13 | 14 | console.log("-------"); 15 | 16 | console.log(!true); 17 | console.log(!false); 18 | -------------------------------------------------------------------------------- /005-boolean-operators/video-examples/boolean-assignment.js: -------------------------------------------------------------------------------- 1 | const fruit = true && "bananas"; 2 | console.log(fruit); 3 | 4 | console.log(false && "oranges"); 5 | console.log(0 && "cucumbers"); 6 | 7 | console.log("-------"); 8 | 9 | console.log(true || "bananas"); 10 | console.log(false || "oranges"); 11 | console.log("" || "cucumbers"); 12 | 13 | console.log("-------"); 14 | 15 | console.log(0 ?? "monkeys"); 16 | console.log("" ?? "koalas"); 17 | console.log(null ?? "elephants"); 18 | -------------------------------------------------------------------------------- /005-boolean-operators/video-examples/boolean-operators.js: -------------------------------------------------------------------------------- 1 | // strict equality 2 | // ligatures 3 | console.log(5 === 5); 4 | console.log(5 === 4); 5 | console.log(4 === 5); 6 | 7 | console.log("-----------"); 8 | // strict not equal 9 | console.log(5 !== 5); 10 | console.log(5 !== 4); 11 | console.log(4 !== 5); 12 | 13 | console.log("-----------"); 14 | // boolean "mathematical" operators 15 | console.log(9 > 7); 16 | console.log(6 < 5); 17 | console.log(3 < 3); 18 | console.log(3 <= 3); 19 | console.log(4 >= 2); 20 | -------------------------------------------------------------------------------- /006-conditional-statements/exercise-solutions/problem-set-2.js: -------------------------------------------------------------------------------- 1 | /* 2 | Create a program that starts with a number variable. 3 | The program will print out whether the variable is 4 | even or odd to the screen when run. 5 | 6 | Change the variable to test it works in both cases. 7 | 8 | HINT: modulus operator ( % ) is your friend 9 | */ 10 | 11 | let hp = 10002; 12 | 13 | if (hp % 2 === 0) { 14 | console.log("even!"); 15 | } else { 16 | console.log("odd!"); 17 | } 18 | -------------------------------------------------------------------------------- /006-conditional-statements/exercise-solutions/problem-set-3.js: -------------------------------------------------------------------------------- 1 | /* 2 | Spot the bug 🐞 3 | Should print: 4 | "Most places consider you an adult." 5 | but it doesn't, why? 6 | */ 7 | 8 | const age = 9; 9 | 10 | if (age < 3) { 11 | console.log("You're just a baby!"); 12 | } else if (age >= 18) { 13 | console.log("Most places consider you an adult."); 14 | } else if (age >= 13) { 15 | console.log("Nice, you're a teenager!"); 16 | } else if (age >= 3) { 17 | console.log("You are in elementary school, kid."); 18 | } else { 19 | console.log("What? How did this happen!?"); 20 | } 21 | -------------------------------------------------------------------------------- /006-conditional-statements/exercise-solutions/problem-set-warmup.js: -------------------------------------------------------------------------------- 1 | /* 2 | 1. Create a variable called points that starts at 40 3 | 2. Create an if statement that checks if points are greater than 20 4 | 3. If points are greater than 20, subtract 10 from points 5 | 4. Log out the points at the end of the program (this should always log) 6 | 5. Change points to start at 15 and run the program again 7 | */ 8 | 9 | let points = 15; 10 | 11 | if (points > 20) { 12 | // points = points - 10; 13 | points -= 10; 14 | } 15 | 16 | console.log(points); 17 | -------------------------------------------------------------------------------- /006-conditional-statements/exercises/problem-set-1.js: -------------------------------------------------------------------------------- 1 | /* 2 | 1. At the start of the program print out: "--- Animal Checker Program ---" 3 | 2. Create a variable called animal that starts at the value "cat" 4 | 3. Create an if statement that checks if animal is equal to "cat" 5 | 4. If it is equal to "cat", print out "Meow!" to the screen 6 | 5. If it is equal to "dog", print out "Woof!" to the screen 7 | 6. If it is neither "cat" nor "dog", print out "Must be an alien" 8 | 7. At the end of the program print out: "--- Animal check complete ---" 9 | 8. Change animal to different values to make sure it works in all cases 10 | */ 11 | -------------------------------------------------------------------------------- /006-conditional-statements/exercises/problem-set-2.js: -------------------------------------------------------------------------------- 1 | /* 2 | Create a program that starts with a number variable. 3 | The program will print out whether the variable is 4 | even or odd to the screen when run. 5 | 6 | Change the variable to test it works in both cases. 7 | 8 | HINT: modulus operator ( % ) is your friend 9 | */ 10 | -------------------------------------------------------------------------------- /006-conditional-statements/exercises/problem-set-3.js: -------------------------------------------------------------------------------- 1 | /* 2 | Spot the bug 🐞 3 | Should print: 4 | "Most places consider you an adult." 5 | but it doesn't, why? 6 | */ 7 | const age = 20; 8 | 9 | if (age < 3) { 10 | console.log("You're just a baby!"); 11 | } else if (age >= 3) { 12 | console.log("You are in elementary school, kid."); 13 | } else if (age >= 13) { 14 | console.log("Nice, you're a teenager!"); 15 | } else if (age >= 18) { 16 | console.log("Most places consider you an adult."); 17 | } else { 18 | console.log("What? How did this happen!?"); 19 | } 20 | -------------------------------------------------------------------------------- /006-conditional-statements/exercises/problem-set-warmup.js: -------------------------------------------------------------------------------- 1 | /* 2 | 1. Create a variable called points that starts at 40 3 | 2. Create an if statement that checks if points are greater than 20 4 | 3. If points are greater than 20, subtract 10 from points 5 | 4. Log out the points at the end of the program (this should always log) 6 | 5. Change points to start at 15 and run the program again 7 | */ 8 | -------------------------------------------------------------------------------- /006-conditional-statements/video-examples/if-else-if-statement.js: -------------------------------------------------------------------------------- 1 | let health = 35; 2 | 3 | if (health > 50) { 4 | console.log("You have more than 50% health!"); 5 | } else if (health > 30) { 6 | console.log("You have between 30 and 50 health!"); 7 | } else if (health > 20) { 8 | console.log("You are running low on health!"); 9 | } else { 10 | console.log("You have less than or equal to 20 health!"); 11 | } 12 | 13 | console.log("Game over!"); 14 | -------------------------------------------------------------------------------- /006-conditional-statements/video-examples/if-else-statement.js: -------------------------------------------------------------------------------- 1 | let points = 10; 2 | 3 | if (points > 20) { 4 | console.log("you have more than 20 points!"); 5 | } else { 6 | console.log("you have less than 20 points!"); 7 | } 8 | 9 | console.log("all done!"); 10 | -------------------------------------------------------------------------------- /006-conditional-statements/video-examples/if-statement.js: -------------------------------------------------------------------------------- 1 | let points = 10; 2 | 3 | if (points > 50) { 4 | console.log("You have more than 5 points!"); 5 | console.log("boo!"); 6 | } 7 | 8 | console.log("All done!"); 9 | -------------------------------------------------------------------------------- /007-while-loops/exercise-solutions/problem-set-1.js: -------------------------------------------------------------------------------- 1 | /* 2 | 1. Create a variable called "loggedIn" that starts off as false. 3 | 2. Create a while loop that loops while "loggedIn" is false. 4 | 3. Each loop, print out: "Incorrect login credentials" 5 | 3. After 3 loop iterations, change "loggedIn" to be true. 6 | 4. After the loops is done print out: "Sucessfully logged in!" 7 | 8 | HINT1: Be careful for an infinite loop! 9 | HINT2: Use CMD+C or CTRL+C to get out of an infinite loop in node 10 | */ 11 | 12 | let loggedIn = false; 13 | let loopCounter = 0; 14 | 15 | while (!loggedIn) { 16 | console.log("Incorrect login credentials"); 17 | if (loopCounter === 2) { 18 | loggedIn = true; 19 | } 20 | loopCounter++; 21 | } 22 | 23 | console.log("Successfully logged in!"); 24 | -------------------------------------------------------------------------------- /007-while-loops/exercise-solutions/problem-set-2.js: -------------------------------------------------------------------------------- 1 | /* 2 | Create a while loop that will print out all the even numbers 3 | between 10 and 40. 4 | 5 | Do the same for all odd numbers as well. 6 | */ 7 | 8 | // Printing even numbers 9 | let i = 10; 10 | while (i <= 40) { 11 | if (i % 2 === 0) { 12 | console.log(i); 13 | } 14 | i++; 15 | } 16 | 17 | // Printing odd numbers 18 | let j = 10; 19 | while (j <= 40) { 20 | if (j % 2 !== 0) { 21 | console.log(j); 22 | } 23 | j++; 24 | } 25 | -------------------------------------------------------------------------------- /007-while-loops/exercise-solutions/problem-set-warmup.js: -------------------------------------------------------------------------------- 1 | /* 2 | Create a while loop that prints out the numbers from 5 - 10 (inclusive) 3 | */ 4 | 5 | let loopNumber = 5; 6 | 7 | while (loopNumber <= 10) { 8 | console.log(loopNumber) 9 | loopNumber++; 10 | } -------------------------------------------------------------------------------- /007-while-loops/exercises/problem-set-1.js: -------------------------------------------------------------------------------- 1 | /* 2 | 1. Create a variable called "loggedIn" that starts off as false. 3 | 2. Create a while loop that loops while "loggedIn" is false. 4 | 3. Each loop, print out: "Incorrect login credentials" 5 | 3. After 3 loop iterations, change "loggedIn" to be true. 6 | 4. After the loops is done print out: "Sucessfully logged in!" 7 | 8 | HINT1: Be careful for an infinite loop! 9 | HINT2: Use CMD+C or CTRL+C to get out of an infinite loop in node 10 | */ 11 | -------------------------------------------------------------------------------- /007-while-loops/exercises/problem-set-2.js: -------------------------------------------------------------------------------- 1 | /* 2 | Create a while loop that will print out all the even numbers 3 | between 10 and 40. 4 | 5 | Do the same for all odd numbers as well. 6 | */ 7 | -------------------------------------------------------------------------------- /007-while-loops/exercises/problem-set-3.js: -------------------------------------------------------------------------------- 1 | /* 2 | 1. Create a while loop that runs from 1-100 3 | 2. Every 10 loops, print out: Checkpoint! and the loop number 4 | 3. On loop 50 print out ONLY: Half way there! 5 | 4. On the final loop (100) print out ONLY: You made it! 6 | 5. AFTER the loop is done, print out: All, done! 7 | 8 | You should see this printed out when run: 9 | Checkpoint! 10 10 | Checkpoint! 20 11 | Checkpoint! 30 12 | Checkpoint! 40 13 | Half way there! 14 | Checkpoint! 60 15 | Checkpoint! 70 16 | Checkpoint! 80 17 | Checkpoint! 90 18 | You made it! 19 | All, done! 20 | 21 | HINT: Lookup for "continue" keyword for loops 22 | */ 23 | -------------------------------------------------------------------------------- /007-while-loops/exercises/problem-set-warmup.js: -------------------------------------------------------------------------------- 1 | /* 2 | Create a while loop that prints out the numbers from 5 - 10 (inclusive) 3 | */ 4 | -------------------------------------------------------------------------------- /007-while-loops/video-examples/break-2.js: -------------------------------------------------------------------------------- 1 | let score = 0; 2 | 3 | // infinite loop 4 | while (true) { 5 | console.log("inside the loop!"); 6 | 7 | if (score >= 3) { 8 | break; 9 | } 10 | 11 | if (score === 2) { 12 | break; 13 | } 14 | 15 | score++; 16 | } 17 | 18 | console.log("Done the loop!"); 19 | -------------------------------------------------------------------------------- /007-while-loops/video-examples/break.js: -------------------------------------------------------------------------------- 1 | let counter = 5; 2 | 3 | while (counter <= 10) { 4 | console.log(counter); 5 | break; 6 | console.log("increasing counter..."); 7 | counter++; 8 | } 9 | 10 | console.log("Thanks for playing!"); 11 | -------------------------------------------------------------------------------- /007-while-loops/video-examples/while-loops.js: -------------------------------------------------------------------------------- 1 | const greeting = "hola!"; 2 | 3 | // console.log(greeting); 4 | // console.log(greeting); 5 | // console.log(greeting); 6 | // console.log(greeting); 7 | // console.log(greeting); 8 | 9 | let number = 0; 10 | 11 | while (number < 3) { 12 | console.log(greeting); 13 | number++; // number = number + 1; 14 | } 15 | 16 | console.log("All done!"); 17 | -------------------------------------------------------------------------------- /008-for-loops/exercise-solutions/problem-set-1.js: -------------------------------------------------------------------------------- 1 | /* 2 | Create a for loop that will print out all the even numbers 3 | between 10 and 40. 4 | 5 | Do the same for all odd numbers as well. 6 | */ 7 | 8 | for (let i = 10; i <= 40; i++) { 9 | if (i % 2 === 1) { 10 | console.log(i); 11 | } 12 | } 13 | -------------------------------------------------------------------------------- /008-for-loops/exercise-solutions/problem-set-2.js: -------------------------------------------------------------------------------- 1 | /* 2 | 1. Create a variable called "loggedIn" that starts off as false. 3 | 2. Create a for loop that loops while "loggedIn" is false. 4 | 3. Each loop, print out: "Incorrect login credentials" 5 | 3. After 3 loop iterations, change "loggedIn" to be true. 6 | 4. After the loops is done print out: "Sucessfully logged in!" 7 | 8 | HINT1: This is more challenging with a for loop 9 | HINT2: This is not an ideal candidate for a for loop! 10 | HINT3: You don't have to provide all parts of the for loop construct 11 | */ 12 | 13 | for (let loggedIn = false, i = 0; !loggedIn; i++) { 14 | console.log("Incorrect login credentials"); 15 | 16 | if (i === 2) { 17 | loggedIn = true; 18 | } 19 | } 20 | 21 | console.log("Sucessfully logged in!"); 22 | -------------------------------------------------------------------------------- /008-for-loops/exercise-solutions/problem-set-warmup.js: -------------------------------------------------------------------------------- 1 | /* 2 | Create a for loop that prints out the numbers from 5 - 10 (inclusive) 3 | */ 4 | 5 | for (let num = 5; num <= 10; num += 1) { 6 | console.log(num); 7 | } 8 | -------------------------------------------------------------------------------- /008-for-loops/exercises/problem-set-1.js: -------------------------------------------------------------------------------- 1 | /* 2 | Create a for loop that will print out all the even numbers 3 | between 10 and 40. 4 | 5 | Do the same for all odd numbers as well. 6 | */ 7 | -------------------------------------------------------------------------------- /008-for-loops/exercises/problem-set-2.js: -------------------------------------------------------------------------------- 1 | /* 2 | 1. Create a variable called "loggedIn" that starts off as false. 3 | 2. Create a for loop that loops while "loggedIn" is false. 4 | 3. Each loop, print out: "Incorrect login credentials" 5 | 3. After 3 loop iterations, change "loggedIn" to be true. 6 | 4. After the loops is done print out: "Sucessfully logged in!" 7 | 8 | HINT1: This is more challenging with a for loop 9 | HINT2: This is not an ideal candidate for a for loop! 10 | HINT3: You don't have to provide all parts of the for loop construct 11 | */ 12 | -------------------------------------------------------------------------------- /008-for-loops/exercises/problem-set-3.js: -------------------------------------------------------------------------------- 1 | /* 2 | 1. Create a for loop that runs from 1-100 3 | 2. Every 10 loops, print out: Checkpoint! and the loop number 4 | 3. On loop 50 print out ONLY: Half way there! 5 | 4. On the final loop (100) print out ONLY: You made it! 6 | 5. AFTER the loop is done, print out: All, done! 7 | 8 | You should see this printed out when run: 9 | Checkpoint! 10 10 | Checkpoint! 20 11 | Checkpoint! 30 12 | Checkpoint! 40 13 | Half way there! 14 | Checkpoint! 60 15 | Checkpoint! 70 16 | Checkpoint! 80 17 | Checkpoint! 90 18 | You made it! 19 | All, done! 20 | */ 21 | -------------------------------------------------------------------------------- /008-for-loops/exercises/problem-set-warmup.js: -------------------------------------------------------------------------------- 1 | /* 2 | Create a for loop that prints out the numbers from 5 - 10 (inclusive) 3 | */ 4 | -------------------------------------------------------------------------------- /008-for-loops/video-examples/break.js: -------------------------------------------------------------------------------- 1 | for (let i = 0; i < 100; i += 5) { 2 | console.log(i); 3 | 4 | if (i === 25) { 5 | console.log("ha, gotcha!"); 6 | break; 7 | } 8 | 9 | if (i === 15) { 10 | break; 11 | } 12 | 13 | console.log("This is loop", i); 14 | } 15 | -------------------------------------------------------------------------------- /008-for-loops/video-examples/continue.js: -------------------------------------------------------------------------------- 1 | for (let i = 0; i < 100; i += 10) { 2 | console.log(i); 3 | 4 | if (i === 20) { 5 | i += 20; 6 | continue; 7 | } 8 | 9 | console.log("Loop number", i); 10 | 11 | if (i === 60) { 12 | break; 13 | } 14 | } 15 | -------------------------------------------------------------------------------- /008-for-loops/video-examples/for-loops1.js: -------------------------------------------------------------------------------- 1 | for (let i = 0; i < 3; i++) { 2 | console.log(i); 3 | } 4 | 5 | -------------------------------------------------------------------------------- /008-for-loops/video-examples/for-loops2.js: -------------------------------------------------------------------------------- 1 | for (let str = "monkey", i = 0; str !== "banana"; i++) { 2 | if (i === 5) { 3 | str = "banana"; 4 | } 5 | console.log(i); 6 | } 7 | -------------------------------------------------------------------------------- /009-functions/exercise-solutions/exercise-warmup.js: -------------------------------------------------------------------------------- 1 | /* 2 | Write a function called "chill" that does the following: 3 | 1. Prints out at the start: "Doing some chilling:" 4 | 2. Then, prints out: 5 | "Chill... 1" 6 | "Chill... 2" 7 | "Chill... 3" 8 | ... 9 | "Chill... 10" 10 | 3. Then finally prints out: "That was ice cold!"" 11 | 12 | When you're done, call the function once. 13 | */ 14 | 15 | // function definition 16 | const chill = () => { 17 | console.log("Doing some chilling:"); 18 | 19 | for (let i = 1; i <= 10; i++) { 20 | console.log(`Chill... ${i}`); 21 | } 22 | 23 | console.log("That was ice cold!"); 24 | }; 25 | 26 | // call the function 27 | chill(); 28 | -------------------------------------------------------------------------------- /009-functions/exercises/exercise-1.js: -------------------------------------------------------------------------------- 1 | /* 2 | Write a function called "noRemainder": 3 | 4 | 1. This function has two parameters: 5 | - number 6 | - mod 7 | 2. The function will return: 8 | - true: if "number" is evenly divisible by "mod" (no remainder) 9 | - false: if "number" is not evenly divisible by "mod" (has a remainder) 10 | 11 | 3. Call your function like so: 12 | const result1 = noRemainder(10, 7); // result1 should be false 13 | const result2 = noRemainder(100, 10); // result2 should be true 14 | */ 15 | -------------------------------------------------------------------------------- /009-functions/exercises/exercise-3.js: -------------------------------------------------------------------------------- 1 | /* 2 | 1. Write a function called "square": 3 | 4 | square will have 1 parameter: 5 | - num: this will be a number 6 | 7 | "square" will return the square of "num" (num**2) 8 | 9 | 2. Write another function called sumOfSquares: 10 | 11 | sumOfSquares will have 2 parameters: 12 | - num1: this will be a number 13 | - num2: this will also be a number 14 | 15 | sumOfSquares will need to: 16 | 1. Use the square function inside itself 17 | 2. return back square of num1 + the square of num2 18 | 19 | 3. Test the function using these: 20 | - const sum1 = sumOfSquares(2, 3); // "sum1" should be 13 (4 + 9) 21 | - const sum2 = sumOfSquares(3, 4); // "sum1" should be 25 (9 + 16) 22 | */ 23 | -------------------------------------------------------------------------------- /009-functions/exercises/exercise-warmup.js: -------------------------------------------------------------------------------- 1 | /* 2 | Write a function called "chill" that does the following: 3 | 1. Prints out at the start: "Doing some chilling:" 4 | 2. Then, prints out: 5 | "Chill... 1" 6 | "Chill... 2" 7 | "Chill... 3" 8 | ... 9 | "Chill... 10" 10 | 3. Then finally prints out: "That was ice cold!"" 11 | 12 | When you're done, call the function once. 13 | */ 14 | -------------------------------------------------------------------------------- /009-functions/video-examples/functions-2.js: -------------------------------------------------------------------------------- 1 | const sum = (num1, num2) => { 2 | console.log(num1); 3 | console.log(num2); 4 | console.log(num1 + num2); 5 | }; 6 | 7 | // sum(5, 6); 8 | // sum(10, 10); 9 | sum(); 10 | // sum(1); 11 | -------------------------------------------------------------------------------- /009-functions/video-examples/functions-3.js: -------------------------------------------------------------------------------- 1 | const mul = (num1, num2) => { 2 | return num1 * num2; // 10 * 10 3 | // return 100 4 | }; 5 | 6 | mul(2, 3); // 6 7 | 8 | const result = mul(10, 10); 9 | // const result = 100; 10 | console.log(result); 11 | -------------------------------------------------------------------------------- /009-functions/video-examples/functions-4.js: -------------------------------------------------------------------------------- 1 | const hello = () => { 2 | console.log("yo!"); 3 | return "hello"; 4 | }; 5 | 6 | hello(); 7 | 8 | const result = hello(); 9 | // const result = "hello" 10 | console.log(result); // ??? 11 | -------------------------------------------------------------------------------- /009-functions/video-examples/functions.js: -------------------------------------------------------------------------------- 1 | // function declaration 2 | const sayHello = () => { 3 | console.log("Hello, jello!"); 4 | console.log("meow!"); 5 | }; 6 | 7 | // "Calling" the function 8 | sayHello("moo!"); 9 | sayHello("foo!"); 10 | sayHello(); 11 | sayHello(); 12 | -------------------------------------------------------------------------------- /010-arrays/exercise-solutions/exercise-1.js: -------------------------------------------------------------------------------- 1 | /* 2 | 1. Create a variable called "multiple" and initialize it to 5 3 | 2. Create an array with the numbers 10-15 (inclusive) 4 | 3. Loop through the array and on each iteration: 5 | - Multiply the number by the multiple and print out the result 6 | - As you're printing, use this format (example): 7 | 10 x 5 = 50 8 | 11 x 5 = 55 9 | ... 10 | 15 x 5 = 75 11 | 12 | BONUS: Try to see if you can make it so that all you need to change 13 | is the "multiple" variable and the program still works correctly. 14 | */ 15 | 16 | const multiple = 10; 17 | const numbers = [10, 11, 12, 13, 14, 15, 16, 17]; 18 | 19 | for (let i = 0; i < numbers.length; i++) { 20 | const result = multiple * numbers[i]; 21 | console.log(`${numbers[i]} x ${multiple} = ${result}`); 22 | } 23 | -------------------------------------------------------------------------------- /010-arrays/exercise-solutions/exercise-2.js: -------------------------------------------------------------------------------- 1 | /* 2 | Create a variable called "greeting" and initialize it to: 3 | "Hello, nice to meet you!" 4 | 5 | Use a loop to loop through this String (just like you would an array) 6 | - On each loop iteration, print out what is at that index 7 | 8 | WHY does this happen? 9 | WHAT is a String, really? 10 | */ 11 | 12 | const greeting = "Hello, nice to meet you!"; 13 | // ["H", "e", "l", "l", "o"] 14 | 15 | for (let i = 0; i < greeting.length; i++) { 16 | console.log(greeting[i]); 17 | } 18 | -------------------------------------------------------------------------------- /010-arrays/exercise-solutions/exercise-3.js: -------------------------------------------------------------------------------- 1 | /* 2 | Create a variable called "total" that starts at 0 3 | 4 | Create an array called "grades" with the following values: 5 | - 55 6 | - 63 7 | - 82 8 | - 98 9 | - 91 10 | - 43 11 | 12 | Figure out how to print out the AVERAGE grade 13 | (This is the sum of all grades divided by the number of grades) 14 | */ 15 | 16 | let total = 0; 17 | const grades = [55, 63, 82, 98, 91, 43, 100]; 18 | 19 | for (let i = 0; i < grades.length; i++) { 20 | total += grades[i]; // total = total + grades[i] 21 | } 22 | 23 | console.log(total); 24 | console.log(total / grades.length); 25 | -------------------------------------------------------------------------------- /010-arrays/exercise-solutions/exercise-warmup.js: -------------------------------------------------------------------------------- 1 | /* 2 | 1. Create an array with the following strings: 3 | - "Mercury" 4 | - "Venus" 5 | - "Earth" 6 | - "Mars" 7 | 8 | 2. Add the string "Jupiter" to the END of the array 9 | 3. Add the string "Sun" to the START of the array 10 | 4. Remove the last two strings from the array 11 | 5. Remove the first two strings from the array 12 | 13 | *Print out the array after each of these steps ^ 14 | */ 15 | 16 | const planets = ["Mercury", "Venus", "Earth", "Mars"]; 17 | console.log(planets); 18 | 19 | planets.push("Jupiter"); 20 | console.log(planets); 21 | 22 | planets.unshift("Sun"); 23 | console.log(planets); 24 | 25 | planets.pop(); 26 | planets.pop(); 27 | console.log(planets); 28 | 29 | planets.shift(); 30 | planets.shift(); 31 | console.log(planets); 32 | -------------------------------------------------------------------------------- /010-arrays/exercises/exercise-1.js: -------------------------------------------------------------------------------- 1 | /* 2 | 1. Create a variable called "multiple" and initialize it to 5 3 | 2. Create an array with the numbers 10-15 (inclusive) 4 | 3. Loop through the array and on each iteration: 5 | - Multiply the number by the multiple and print out the result 6 | - As you're printing, use this format (example): 7 | 10 x 5 = 50 8 | 11 x 5 = 55 9 | ... 10 | 15 x 5 = 75 11 | 12 | BONUS: Try to see if you can make it so that all you need to change 13 | is the "multiple" variable and the program still works correctly. 14 | */ 15 | -------------------------------------------------------------------------------- /010-arrays/exercises/exercise-2.js: -------------------------------------------------------------------------------- 1 | /* 2 | Create a variable called "greeting" and initialize it to: 3 | "Hello, nice to meet you!" 4 | 5 | Use a loop to loop through this String (just like you would an array) 6 | - On each loop iteration, print out what is at that index 7 | 8 | WHY does this happen? 9 | WHAT is a String, really? 10 | */ 11 | -------------------------------------------------------------------------------- /010-arrays/exercises/exercise-3.js: -------------------------------------------------------------------------------- 1 | /* 2 | Create a variable called "total" that starts at 0 3 | 4 | Create an array called "grades" with the following values: 5 | - 55 6 | - 63 7 | - 82 8 | - 98 9 | - 91 10 | - 43 11 | 12 | Figure out how to print out the AVERAGE grade 13 | (This is the sum of all grades divided by the number of grades) 14 | */ 15 | -------------------------------------------------------------------------------- /010-arrays/exercises/exercise-BONUS.js: -------------------------------------------------------------------------------- 1 | /* 2 | Create a variable called "bakery" that points to an array 3 | Fill the array with the following String: 4 | - "Cake" 5 | - "Cookie" 6 | - "Bread" 7 | - "Scone" 8 | 9 | Print out bakery to make sure it has these 4 Strings in it. 10 | 11 | Create another variable called "myBakery" and assign it 12 | to "bakery" that we declared previously 13 | 14 | Add the following items to "myBakery": 15 | - "Croissant" 16 | - "Granola" 17 | 18 | Print out myBakery and bakery and observe the contents. 19 | 20 | WHY is this? 21 | */ 22 | -------------------------------------------------------------------------------- /010-arrays/exercises/exercise-warmup.js: -------------------------------------------------------------------------------- 1 | /* 2 | 1. Create an array with the following strings: 3 | - "Mercury" 4 | - "Venus" 5 | - "Earth" 6 | - "Mars" 7 | 8 | 2. Add the string "Jupiter" to the END of the array 9 | 3. Add the string "Sun" to the START of the array 10 | 4. Remove the last two strings from the array 11 | 5. Remove the first two strings from the array 12 | 13 | *Print out the array after each of these steps ^ 14 | */ 15 | -------------------------------------------------------------------------------- /010-arrays/video-examples/array-pop.js: -------------------------------------------------------------------------------- 1 | const animals = ["monkey", "dog", "cat", "koala", "elephant"]; 2 | 3 | animals.push("cow"); 4 | 5 | console.log(animals); 6 | 7 | animals.pop(); 8 | animals.pop(); 9 | animals.pop(); 10 | 11 | console.log(animals); 12 | -------------------------------------------------------------------------------- /010-arrays/video-examples/array-push.js: -------------------------------------------------------------------------------- 1 | const animals = ["monkey", "dog", "cat", "koala", "elephant"]; 2 | 3 | console.log(animals); 4 | console.log(animals.length); 5 | 6 | animals.push("cow"); 7 | 8 | console.log(animals); 9 | console.log(animals.length); 10 | -------------------------------------------------------------------------------- /010-arrays/video-examples/array-shift.js: -------------------------------------------------------------------------------- 1 | const animals = ["monkey", "dog", "cat", "koala", "elephant"]; 2 | 3 | animals.unshift("llama"); 4 | 5 | console.log(animals); 6 | 7 | animals.shift(); 8 | animals.shift(); 9 | animals.shift(); 10 | 11 | console.log(animals); 12 | -------------------------------------------------------------------------------- /010-arrays/video-examples/array-unshift.js: -------------------------------------------------------------------------------- 1 | const animals = ["monkey", "dog", "cat", "koala", "elephant"]; 2 | 3 | console.log(animals); 4 | 5 | animals.unshift("llama"); 6 | 7 | console.log(animals); 8 | -------------------------------------------------------------------------------- /010-arrays/video-examples/arrays-concepts.js: -------------------------------------------------------------------------------- 1 | const veggie1 = "cucumber"; 2 | const veggie2 = "kale"; 3 | const veggie3 = "beet"; 4 | 5 | console.log(veggie1); 6 | console.log(veggie2); 7 | console.log(veggie3); 8 | -------------------------------------------------------------------------------- /010-arrays/video-examples/indices.js: -------------------------------------------------------------------------------- 1 | const animals = ["monkey", "dog", "cat", "koala", "elephant"]; 2 | 3 | console.log(animals); 4 | 5 | const monkey = animals[0]; 6 | console.log(monkey); 7 | 8 | const koala = animals[3]; 9 | console.log(koala); 10 | 11 | console.log("------"); 12 | 13 | for (let i = 0; i < animals.length; i++) { 14 | console.log(animals[i]); 15 | } 16 | -------------------------------------------------------------------------------- /011-array-map/exercise-solutions/BONUS-exercise.js: -------------------------------------------------------------------------------- 1 | /* 2 | 1. Create the following array called "row": 3 | [10, 20, 30, 40, 50] 4 | 5 | 2. Create an new array called "matrix" that: 6 | - maps over "row" and return each item, but in an array 7 | (We should have a 2-dimensional array as a result) 8 | 9 | 3. Print out both arrays 10 | 11 | "matrix" should look like this: 12 | [[10], [20], [30], [40], [50]] 13 | */ 14 | 15 | const row = [10, 20, 30, 40, 50]; 16 | 17 | const matrix = row.map((number) => { 18 | const array = []; 19 | array.push(number); 20 | return array; 21 | }); 22 | 23 | console.log(row); 24 | console.log(matrix); 25 | -------------------------------------------------------------------------------- /011-array-map/exercise-solutions/exercise-1.js: -------------------------------------------------------------------------------- 1 | /* 2 | 1. Create an array called 'bools' of the following booleans: 3 | [true, true, false, true, false, false] 4 | 5 | 2. Map over 'bools' and do the following: 6 | - if "true", return a random number in it's place 7 | - if "false", return 0 8 | 9 | 3. Print out both arrays 10 | 11 | HINT: Google for "random number js" to find a random 12 | number function built-in to Javascript to use 13 | */ 14 | 15 | const bools = [true, true, false, true, false, false]; 16 | 17 | const mappedBools = bools.map((bool) => { 18 | if (bool) { 19 | return Math.random(); 20 | } 21 | return 0; 22 | }); 23 | 24 | console.log(bools); 25 | console.log(mappedBools); 26 | -------------------------------------------------------------------------------- /011-array-map/exercise-solutions/exercise-2.js: -------------------------------------------------------------------------------- 1 | /* 2 | 1. Create an array called "prices" with the following values: 3 | [1.23, 19.99, 85.2, 32.87, 8, 5.2] 4 | 5 | 2. Create a new array using map called "taxedPrices" that: 6 | - If the price is greater than 10, add 20% tax to it 7 | - Otherwise, do not add any tax 8 | 9 | 3. Print out both arrays 10 | */ 11 | 12 | const prices = [1.23, 19.99, 85.2, 32.87, 8, 5.2]; 13 | 14 | const taxedPrices = prices.map((price) => { 15 | if (price > 10) { 16 | return price * 1.2; 17 | } 18 | return price; 19 | }); 20 | 21 | console.log(prices); 22 | console.log(taxedPrices); 23 | -------------------------------------------------------------------------------- /011-array-map/exercise-solutions/exercise-3.js: -------------------------------------------------------------------------------- 1 | /* 2 | 1. Create the following array called "items": 3 | ["light", "banana", "phone", "book", "mouse"] 4 | 5 | 2. Create an new array called "plurals" that: 6 | - maps over "items" and adds an 's' to each one 7 | 8 | 3. Print out both arrays 9 | 10 | 4. Change it so if we see "mouse", we instead return "mice" 11 | */ 12 | 13 | const items = ["light", "banana", "phone", "book", "mouse"]; 14 | 15 | const plurals = items.map((item) => { 16 | if (item === "mouse") { 17 | return "mice"; 18 | } 19 | return item + "s"; 20 | }); 21 | 22 | console.log(items); 23 | console.log(plurals); 24 | -------------------------------------------------------------------------------- /011-array-map/exercise-solutions/warmup-exercise.js: -------------------------------------------------------------------------------- 1 | /* 2 | 1. Create an array called "practice" with the numbers 25-30 (inclusive) 3 | 4 | 2. Create another array using map that squares each number in "practice" 5 | 6 | 3. Print out both "practice" and the new mapped array 7 | */ 8 | 9 | const practice = [25, 26, 27, 28, 29, 30]; 10 | 11 | const squares = practice.map((number) => { 12 | return number * number; 13 | }); 14 | 15 | console.log(practice); 16 | console.log(squares); 17 | -------------------------------------------------------------------------------- /011-array-map/exercises/BONUS-exercise.js: -------------------------------------------------------------------------------- 1 | /* 2 | 1. Create the following array called "row": 3 | [10, 20, 30, 40, 50] 4 | 5 | 2. Create an new array called "matrix" that: 6 | - maps over "row" and return each item, but in an array 7 | (We should have a 2-dimensional array as a result) 8 | 9 | 3. Print out both arrays 10 | 11 | "matrix" should look like this: 12 | [[10], [20], [30], [40], [50]] 13 | */ 14 | -------------------------------------------------------------------------------- /011-array-map/exercises/exercise-1.js: -------------------------------------------------------------------------------- 1 | /* 2 | 1. Create an array called 'bools' of the following booleans: 3 | [true, true, false, true, false, false] 4 | 5 | 2. Map over 'bools' and do the following: 6 | - if "true", return a random number in it's place 7 | - if "false", return 0 8 | 9 | 3. Print out both arrays 10 | 11 | HINT: Google for "random number js" to find a random 12 | number function built-in to Javascript to use 13 | */ 14 | -------------------------------------------------------------------------------- /011-array-map/exercises/exercise-2.js: -------------------------------------------------------------------------------- 1 | /* 2 | 1. Create an array called "prices" with the following values: 3 | [1.23, 19.99, 85.2, 32.87, 8, 5.2] 4 | 5 | 2. Create a new array using map called "taxedPrices" that: 6 | - If the price is greater than 10, add 20% tax to it 7 | - Otherwise, do not add any tax 8 | 9 | 3. Print out both arrays 10 | */ 11 | -------------------------------------------------------------------------------- /011-array-map/exercises/exercise-3.js: -------------------------------------------------------------------------------- 1 | /* 2 | 1. Create the following array called "items": 3 | ["light", "banana", "phone", "book", "mouse"] 4 | 5 | 2. Create an new array called "plurals" that: 6 | - maps over "items" and adds an 's' to each one 7 | 8 | 3. Print out both arrays 9 | 10 | 4. Change it so if we see "mouse", we instead return "mice" 11 | */ 12 | -------------------------------------------------------------------------------- /011-array-map/exercises/warmup-exercise.js: -------------------------------------------------------------------------------- 1 | /* 2 | 1. Create an array called "practice" with the numbers 25-30 (inclusive) 3 | 4 | 2. Create another array using map that squares each number in "practice" 5 | 6 | 3. Print out both "practice" and the new mapped array 7 | */ 8 | -------------------------------------------------------------------------------- /011-array-map/video-examples/map-intro.js: -------------------------------------------------------------------------------- 1 | const numbers = [5, 10, 15, 20, 25]; 2 | 3 | const timesTen = numbers.map((number) => { 4 | return number * 10; 5 | }); 6 | 7 | console.log(timesTen); 8 | console.log(numbers); 9 | -------------------------------------------------------------------------------- /011-array-map/video-examples/map-return.js: -------------------------------------------------------------------------------- 1 | const numbers = [5, 10, 15, 20, 25, 30]; 2 | 3 | const timesTen = numbers.map((number) => { 4 | console.log(number * 10); 5 | return undefined; 6 | }); 7 | 8 | console.log(timesTen); 9 | -------------------------------------------------------------------------------- /012-array-filter/exercise-solutions/exercise-1.js: -------------------------------------------------------------------------------- 1 | /* 2 | 1. Create an array called 'countries' of the following strings: 3 | ["France", "South Africa", "Brazil", "United States", "Sweden"] 4 | 5 | 2. Filter over 'countries' and keep only the countries that have 6 | a blank space in their name (South Africa and United States) 7 | 8 | 3. Print out both arrays 9 | 10 | HINT: Google for "javascript string contains" 11 | */ 12 | 13 | const countries = [ 14 | "France", 15 | "South Africa", 16 | "Brazil", 17 | "United States", 18 | "Sweden", 19 | ]; 20 | 21 | const blankCountries = countries.filter((country) => { 22 | if (country.includes(" ")) { 23 | return true; 24 | } 25 | 26 | return false; 27 | }); 28 | 29 | console.log(countries); 30 | console.log(blankCountries); 31 | -------------------------------------------------------------------------------- /012-array-filter/exercise-solutions/exercise-2.js: -------------------------------------------------------------------------------- 1 | /* 2 | 1. Create an array called "prices" with the following values: 3 | [1.23, 19.99, 85.2, 32.87, 8, 5.2] 4 | 5 | 2. Create a new array using filter called "lowPrices" that 6 | keeps all the prices where the price plus a 15% tax is 7 | less than 10.00 8 | 9 | 3. Print out both arrays 10 | */ 11 | 12 | const prices = [1.23, 19.99, 85.2, 32.87, 8, 5.2]; 13 | 14 | const lowPrices = prices.filter((price) => { 15 | if (price * 1.15 < 10) { 16 | return true; 17 | } 18 | 19 | return false; 20 | }); 21 | 22 | console.log(prices); 23 | console.log(lowPrices); 24 | -------------------------------------------------------------------------------- /012-array-filter/exercise-solutions/exercise-3.js: -------------------------------------------------------------------------------- 1 | /* 2 | 1. Create the following array called "values": 3 | [[1,2,3], [0,0,1], [3,6,9], [0,1,2]] 4 | 5 | 2. Create an new array called "hasTwos" that: 6 | - filters over "values" and keeps only the sub-arrays 7 | that have a 2 in them 8 | 9 | 3. Print out both arrays 10 | 11 | "hasTwos" should equal to: [[1,2,3], [0,1,2]] 12 | 13 | HINT: Google for "javascript array includes" 14 | */ 15 | 16 | const values = [ 17 | [1, 2, 3], 18 | [0, 0, 1], 19 | [3, 6, 9], 20 | [0, 1, 2], 21 | ]; 22 | 23 | const hasTwos = values.filter((value) => { 24 | if (value.includes(2)) { 25 | return true; 26 | } 27 | 28 | return false; 29 | }); 30 | 31 | console.log(values); 32 | console.log(hasTwos); 33 | -------------------------------------------------------------------------------- /012-array-filter/exercise-solutions/warmup-exercise.js: -------------------------------------------------------------------------------- 1 | /* 2 | 1. Create an array called "practice" with the numbers 10-20 (inclusive) 3 | 4 | 2. Create another array using filter that keeps the even numbers in "practice" 5 | 6 | 3. Print out both "practice" and the new filtered array 7 | */ 8 | 9 | const practice = [10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20]; 10 | 11 | const evens = practice.filter((num) => { 12 | if (num % 2 === 0) { 13 | return true; 14 | } 15 | 16 | return false; 17 | }); 18 | 19 | console.log(practice); 20 | console.log(evens); 21 | -------------------------------------------------------------------------------- /012-array-filter/exercises/BONUS-exercise.js: -------------------------------------------------------------------------------- 1 | /* 2 | 1. Create the following array called "nums": 3 | [10, 20, 30, 40, 50] 4 | 5 | 2. Create an new array called "timesTwo" that: 6 | - maps over "nums" and returns each number 7 | multiplied by two 8 | 9 | 3. Create an new array called "over50" that: 10 | - filters "timesTwo" to keep only values over 50 11 | 12 | 4. Print out all 3 arrays 13 | 14 | "over50" should contain: [60, 80, 100] 15 | */ 16 | -------------------------------------------------------------------------------- /012-array-filter/exercises/exercise-1.js: -------------------------------------------------------------------------------- 1 | /* 2 | 1. Create an array called 'countries' of the following strings: 3 | ["France", "South Africa", "Brazil", "United States", "Sweden"] 4 | 5 | 2. Filter over 'countries' and keep only the countries that have 6 | a blank space in their name (South Africa and United States) 7 | 8 | 3. Print out both arrays 9 | 10 | HINT: Google for "javascript string contains" 11 | */ 12 | -------------------------------------------------------------------------------- /012-array-filter/exercises/exercise-2.js: -------------------------------------------------------------------------------- 1 | /* 2 | 1. Create an array called "prices" with the following values: 3 | [1.23, 19.99, 85.2, 32.87, 8, 5.2] 4 | 5 | 2. Create a new array using filter called "lowPrices" that 6 | keeps all the prices where the price plus a 15% tax is 7 | less than 10.00 8 | 9 | 3. Print out both arrays 10 | */ 11 | -------------------------------------------------------------------------------- /012-array-filter/exercises/exercise-3.js: -------------------------------------------------------------------------------- 1 | /* 2 | 1. Create the following array called "values": 3 | [[1,2,3], [0,0,1], [3,6,9], [0,1,2]] 4 | 5 | 2. Create an new array called "hasTwos" that: 6 | - filters over "values" and keeps only the sub-arrays 7 | that have a 2 in them 8 | 9 | 3. Print out both arrays 10 | 11 | "hasTwos" should equal to: [[1,2,3], [0,1,2]] 12 | 13 | HINT: Google for "javascript array includes" 14 | */ 15 | -------------------------------------------------------------------------------- /012-array-filter/exercises/warmup-exercise.js: -------------------------------------------------------------------------------- 1 | /* 2 | 1. Create an array called "practice" with the numbers 10-20 (inclusive) 3 | 4 | 2. Create another array using filter that keeps the even numbers in "practice" 5 | 6 | 3. Print out both "practice" and the new filtered array 7 | */ 8 | -------------------------------------------------------------------------------- /012-array-filter/video-examples/filter-bugs.js: -------------------------------------------------------------------------------- 1 | const nums = [5, 6, 7, 8, 9, 10]; 2 | 3 | const oddNumbers = nums.filter((num) => { 4 | if (num % 2 === 1) { 5 | return 100; // truthy 6 | } 7 | 8 | // ??? 9 | }); 10 | 11 | console.log(nums); 12 | console.log(oddNumbers); 13 | -------------------------------------------------------------------------------- /012-array-filter/video-examples/filter-intro.js: -------------------------------------------------------------------------------- 1 | const nums = [5, 6, 7, 8, 9, 10]; 2 | 3 | const evenNumbers = nums.filter((num) => { 4 | if (num % 2 === 0) { 5 | return true; 6 | } 7 | return false; 8 | }); 9 | 10 | console.log(nums); 11 | console.log(evenNumbers); 12 | -------------------------------------------------------------------------------- /013-array-reduce/exercise-solutions/exercise-2.js: -------------------------------------------------------------------------------- 1 | /* 2 | 1. Create an array called "prices" with the following values: 3 | [1.23, 19.99, 85.2, 32.87, 8, 5.2] 4 | 5 | 2. Create a const called "afterTax" that does a sum like so: 6 | - If the price is greater than 6, add the price with no tax 7 | - Otherwise, add the price plus a tax of 20% 8 | 9 | 3. Print out "prices" and "afterTax" 10 | */ 11 | 12 | const prices = [1.23, 19.99, 85.2, 32.87, 8, 5.2]; 13 | 14 | const afterTax = prices.reduce((sum, price) => { 15 | if (price > 6) { 16 | return sum + price; 17 | } 18 | 19 | return sum + price * 1.2; 20 | }, 0); 21 | 22 | console.log(afterTax); 23 | -------------------------------------------------------------------------------- /013-array-reduce/exercise-solutions/exercise-3.js: -------------------------------------------------------------------------------- 1 | /* 2 | 1. Create the following array called "items": 3 | ["light", "banana", "phone", "book", "mouse"] 4 | 5 | 2. Create an new array called "caps" that: 6 | - maps over "items" and capitalizes each item 7 | 8 | 3. Create a const called "concat" that: 9 | - uses reduce to concatenate all the strings in "caps" 10 | using a space to separate each item 11 | 12 | 4. Print out "items", "caps" and "concat" 13 | 14 | BONUS: Can you do steps 1-3 in one line? 15 | */ 16 | 17 | const items = ["light", "banana", "phone", "book", "mouse"] 18 | .map((item) => { 19 | return item.toUpperCase(); 20 | }) 21 | .reduce((result, str) => { 22 | return result + str + " "; 23 | }, ""); 24 | 25 | console.log(items); 26 | -------------------------------------------------------------------------------- /013-array-reduce/exercise-solutions/warmup-exercise.js: -------------------------------------------------------------------------------- 1 | /* 2 | 1. Create an array called "points" with the numbers 55-60 (inclusive) 3 | 4 | 2. Create a variable called "sum" using reduce that sums up the points in "points" 5 | 6 | 3. Print out both "points" and "sum" 7 | */ 8 | 9 | const points = [55, 56, 57, 58, 59, 60, 100]; 10 | 11 | const sum = points.reduce((result, point) => { 12 | return result + point; 13 | }, 0); 14 | 15 | console.log(sum); 16 | -------------------------------------------------------------------------------- /013-array-reduce/exercises/BONUS-exercise.js: -------------------------------------------------------------------------------- 1 | /* 2 | 1. Create the following array called "nums": 3 | [10, 30, 50, 70, 90] 4 | 5 | 2. Create a new array called "squares" that: 6 | - maps over "nums" and return each item squared (x by itself) 7 | 8 | 3. Create another new array called "over1000" that: 9 | - filters "squares" to contain only values over 1000 10 | 11 | 4. Create a const called "finale" that: 12 | - reduces "over1000" to a single sum of it's elements 13 | 14 | 5. Print out "nums", "squares", "over1000" and "finale" 15 | 16 | BONUS^2: Can you do 1-4 all in one line? 17 | */ 18 | -------------------------------------------------------------------------------- /013-array-reduce/exercises/exercise-1.js: -------------------------------------------------------------------------------- 1 | /* 2 | 1. Create an array called 'companies' of the following strings: 3 | ["apple", "tesla", "spacex", "amazon", "meta", "google"] 4 | 5 | 2. Create a const called "modded" that reduces the "companies" 6 | array to a string of companies that DO NOT start with the 7 | letter 'a', separated by dashes 8 | 9 | 3. Print out "companies" and "modded" 10 | 11 | "modded" should be: "tesla-spacex-meta-google-" 12 | 13 | BONUS: How can you get rid of the trailing '-' ? 14 | TIP: Look up reduce on Google using docs like MDN 15 | */ 16 | -------------------------------------------------------------------------------- /013-array-reduce/exercises/exercise-2.js: -------------------------------------------------------------------------------- 1 | /* 2 | 1. Create an array called "prices" with the following values: 3 | [1.23, 19.99, 85.2, 32.87, 8, 5.2] 4 | 5 | 2. Create a const called "afterTax" that does a sum like so: 6 | - If the price is greater than 6, add the price with no tax 7 | - Otherwise, add the price plus a tax of 20% 8 | 9 | 3. Print out "prices" and "afterTax" 10 | */ 11 | -------------------------------------------------------------------------------- /013-array-reduce/exercises/exercise-3.js: -------------------------------------------------------------------------------- 1 | /* 2 | 1. Create the following array called "items": 3 | ["light", "banana", "phone", "book", "mouse"] 4 | 5 | 2. Create an new array called "caps" that: 6 | - maps over "items" and capitalizes each item 7 | 8 | 3. Create a const called "concat" that: 9 | - uses reduce to concatenate all the strings in "caps" 10 | using a space to separate each item 11 | 12 | 4. Print out "items", "caps" and "concat" 13 | 14 | BONUS: Can you do steps 1-3 in one line? 15 | */ 16 | -------------------------------------------------------------------------------- /013-array-reduce/exercises/warmup-exercise.js: -------------------------------------------------------------------------------- 1 | /* 2 | 1. Create an array called "points" with the numbers 55-60 (inclusive) 3 | 4 | 2. Create a variable called "sum" using reduce that sums up the points in "points" 5 | 6 | 3. Print out both "points" and "sum" 7 | */ 8 | -------------------------------------------------------------------------------- /013-array-reduce/video-examples/reduce-array.js: -------------------------------------------------------------------------------- 1 | const nums = [5, 10, 15, 20, 25, 30, 35]; 2 | 3 | const reduced = nums.reduce((result, num) => { 4 | console.log(result, num); 5 | result.push(num); 6 | 7 | return result; 8 | }, []); 9 | 10 | console.log(reduced); 11 | -------------------------------------------------------------------------------- /013-array-reduce/video-examples/reduce-intro.js: -------------------------------------------------------------------------------- 1 | const nums = [5, 10, 15, 20, 25, 30, 35]; 2 | 3 | let sum = 0; 4 | for (let i = 0; i < nums.length; i++) { 5 | // console.log(sum, nums[i]); 6 | sum += nums[i]; 7 | } 8 | 9 | // console.log(sum); 10 | 11 | const sum2 = nums.reduce((result, number) => { 12 | console.log(result, number); 13 | 14 | if (number < 20) { 15 | return result + number; 16 | } 17 | 18 | return result; 19 | 20 | // end up here ?? 21 | }, 0); 22 | 23 | console.log("-----"); 24 | console.log(sum2); 25 | -------------------------------------------------------------------------------- /013-array-reduce/video-examples/reduce-string.js: -------------------------------------------------------------------------------- 1 | const cities = ["Vancouver", "Berlin", "Seattle", "Toronto"]; 2 | 3 | const concatCities = cities.reduce((concatStrings, city) => { 4 | if (city === "Vancouver") { 5 | return concatStrings; 6 | } 7 | return concatStrings + city + "-"; 8 | }, ""); 9 | 10 | console.log(concatCities); 11 | -------------------------------------------------------------------------------- /014-objects/exercise-solutions/BONUS-exercise.js: -------------------------------------------------------------------------------- 1 | /* 2 | 1. Create an object called "myConsole" 3 | 4 | 2. Assign "myConsole" the key "log" with a value that is 5 | an arrow function. 6 | 7 | This arrow function will have one parameter called "message" 8 | 9 | The function will just console.log out the "message" 10 | 11 | 3. How would you call this "log" function inside the object? 12 | 13 | You should be able to do: myConsole.log("Hello, friend!"); 14 | 15 | BONUS: How might the built-in "console" work? 16 | */ 17 | 18 | const myConsole = { 19 | log: (message) => { 20 | console.log(message); 21 | }, 22 | }; 23 | 24 | // myConsole.log("Hello, friend!!!!!"); 25 | 26 | console.log(console); 27 | -------------------------------------------------------------------------------- /014-objects/exercises/BONUS-exercise.js: -------------------------------------------------------------------------------- 1 | /* 2 | 1. Create an object called "myConsole" 3 | 4 | 2. Assign "myConsole" the key "log" with a value that is 5 | an arrow function. 6 | 7 | This arrow function will have one parameter called "message" 8 | 9 | The function will just console.log out the "message" 10 | 11 | 3. How would you call this "log" function inside the object? 12 | 13 | You should be able to do: myConsole.log("Hello, friend!"); 14 | 15 | BONUS: How might the built-in "console" work? 16 | */ 17 | -------------------------------------------------------------------------------- /014-objects/exercises/exercise-1.js: -------------------------------------------------------------------------------- 1 | /* 2 | 1. Create an object called "myPet" with the following properties: 3 | - name -> "Sudo" 4 | - type -> "Dog" 5 | - breed -> "Poodle" 6 | - age -> 7 7 | - friends -> ["Bit", "Byte", "Data"] 8 | 9 | 2. Print out "myPet" to the terminal 10 | 11 | 3. Add a new property: colour -> "Black" 12 | 13 | 4. Change "breed" to be "Beagle" 14 | 15 | 5. Remove "Data" from the list of friends for "myPet" 16 | 17 | 6. Print out "myPet" to the terminal again 18 | 19 | 7. Add "Chip" to the list of friends for "myPet" 20 | 21 | 8. Print out "myPet" to the terminal again 22 | */ 23 | -------------------------------------------------------------------------------- /014-objects/exercises/exercise-3.js: -------------------------------------------------------------------------------- 1 | /* 2 | 1. Create an object called "houseForSale" with the following properties: 3 | - area -> 940 4 | - value -> 320000 5 | - streetName -> "Fifth Street" 6 | - built -> "2012" 7 | - owner -> {name: "Blake", age: 29} 8 | - offers -> [290000, 295000, 315000, 312000] 9 | 10 | 2. Print out "houseForSale" to the terminal 11 | 12 | 3. Delete the property with the key "built" 13 | 14 | 4. Change the age of the owner to be 30 inside "houseForSale" 15 | 16 | 5. Print out the maximum offerPrice (use reduce) 17 | 18 | 6. Add a new property: "sale price" -> 312000 19 | 20 | 7. Print out "houseForSale" to the terminal 21 | 22 | *This is a challenging exercise - take it slow and step by step 23 | */ 24 | -------------------------------------------------------------------------------- /014-objects/exercises/warmup-exercise.js: -------------------------------------------------------------------------------- 1 | /* 2 | 1. Create an object called "mexico" with the following properties: 3 | - id -> 24 4 | - name -> "Mexico" 5 | - capital -> "Mexico City" 6 | - neighbours -> ["USA", "Guatemala", "Belize"] 7 | 8 | 2. Print out "mexico" to the terminal 9 | 10 | 3. Change "id" to be 25 11 | 12 | 4. Add "Honduras" to the list of neighbours to "mexico" 13 | 14 | 5. Print out "mexico" to the terminal again 15 | */ 16 | -------------------------------------------------------------------------------- /014-objects/video-examples/objects-delete.js: -------------------------------------------------------------------------------- 1 | const animal = { 2 | id: 42, 3 | name: "rawr", 4 | type: "dog", 5 | "num legs": 4, 6 | numLegs: 4, 7 | }; 8 | 9 | delete animal.type; 10 | delete animal["id"]; 11 | 12 | console.log(animal); 13 | -------------------------------------------------------------------------------- /014-objects/video-examples/objects-in.js: -------------------------------------------------------------------------------- 1 | const animal = { 2 | id: 42, 3 | name: "rawr", 4 | type: "dog", 5 | "num legs": 4, 6 | numLegs: 4, 7 | }; 8 | 9 | console.log("rawr" in animal); 10 | -------------------------------------------------------------------------------- /014-objects/video-examples/objects-intro.js: -------------------------------------------------------------------------------- 1 | const animal = { 2 | id: 42, 3 | name: "rawr", 4 | type: "dog", 5 | "num legs": 4, 6 | numLegs: 4, 7 | }; 8 | 9 | console.log(animal); 10 | 11 | animal["name"] = "moo"; 12 | 13 | console.log(animal); 14 | 15 | animal.type = "cow"; 16 | 17 | console.log(animal); 18 | 19 | animal["num legs"] = 5; 20 | // animal.num legs = 5; 21 | 22 | console.log(animal); 23 | 24 | animal.numLegs = 5; 25 | 26 | console.log(animal); 27 | -------------------------------------------------------------------------------- /014-objects/video-examples/objects-methods.js: -------------------------------------------------------------------------------- 1 | const animal = { 2 | id: 42, 3 | name: "rawr", 4 | type: "dog", 5 | "num legs": 4, 6 | numLegs: 4, 7 | }; 8 | 9 | // console.log(animal.keys()); 10 | console.log(Object.keys(animal)); 11 | 12 | console.log(Object.values(animal)); 13 | 14 | console.log(Object.entries(animal)); 15 | -------------------------------------------------------------------------------- /015-maps/exercise-solutions/warmup-exercise.js: -------------------------------------------------------------------------------- 1 | /* 2 | 1. Create a Map called "mexico" with the following entries: 3 | - id -> 24 4 | - name -> "Mexico" 5 | - capital -> "Mexico City" 6 | - neighbours -> ["USA", "Guatemala", "Belize"] 7 | 8 | 2. Print out "mexico" to the terminal 9 | 10 | 3. Change "id" to be 25 11 | 12 | 4. Add "Honduras" to the list of neighbours to "mexico" 13 | 14 | 5. Print out "mexico" to the terminal again 15 | */ 16 | 17 | const mexico = new Map(); 18 | mexico.set("id", 24); 19 | mexico.set("name", "Mexico"); 20 | mexico.set("capital", "Mexico City"); 21 | mexico.set("neighbours", ["USA", "Guatemala", "Belize"]); 22 | console.log(mexico); 23 | 24 | mexico.set("id", 25); 25 | // ["USA", "Guatemala", "Belize"] 26 | mexico.get("neighbours").push("Honduras"); 27 | 28 | console.log(mexico); 29 | -------------------------------------------------------------------------------- /015-maps/exercises/BONUS-exercise-1.js: -------------------------------------------------------------------------------- 1 | /* 2 | 1. Create a Map called "myConsole" 3 | 4 | 2. Assign "myConsole" the key "log" with a value that is 5 | an arrow function. 6 | 7 | This arrow function will have one parameter called "message" 8 | 9 | The function will just console.log out the "message" 10 | 11 | 3. Call the function with a message. How does this compare to Objects? 12 | 13 | 4. Add the following key-value pairs to the map: 14 | - 1 : "number one" 15 | - "1" : "string one" 16 | 17 | 5. Print out each of the 2 values for the keys you just added. 18 | How does this differ from an Object? 19 | */ 20 | -------------------------------------------------------------------------------- /015-maps/exercises/BONUS-exercise-2.js: -------------------------------------------------------------------------------- 1 | /* 2 | 1. Create an array called "numbers" with the following values: 3 | [10, 20, 15, 30, 15, 20, 35, 60, 10] 4 | 5 | 2. Find the first duplicate value in "numbers" and print 6 | out the INDEX of that value as well as the INDEX 7 | of where it was first found in "numbers" 8 | 9 | 3. In this case, we will print: 10 | 4 2 11 | 12 | (4 is where the duplicate index was) 13 | (2 is where the first pair of that duplicate was, as an index) 14 | 15 | HINT: Use a Map to keep track of number->index pairs 16 | 17 | *This is very challenging and is a common interview question 18 | */ 19 | -------------------------------------------------------------------------------- /015-maps/exercises/exercise-1.js: -------------------------------------------------------------------------------- 1 | /* 2 | 1. Create a Map called "myPet" with the following entries: 3 | - name -> "Sudo" 4 | - type -> "Dog" 5 | - breed -> "Poodle" 6 | - age -> 7 7 | - friends -> ["Bit", "Byte", "Data"] 8 | 9 | 2. Print out "myPet" to the terminal 10 | 11 | 3. Add a new entry: colour -> "Black" 12 | 13 | 4. Change "breed" to be "Beagle" 14 | 15 | 5. Remove "Data" from the list of friends for "myPet" 16 | 17 | 6. Print out "myPet" to the terminal again 18 | 19 | 7. Add "Chip" to the list of friends for "myPet" 20 | 21 | 8. Print out "myPet" to the terminal again 22 | */ 23 | -------------------------------------------------------------------------------- /015-maps/exercises/exercise-3.js: -------------------------------------------------------------------------------- 1 | /* 2 | 1. Create a Map called "houseForSale" with the following entries: 3 | - area -> 940 4 | - value -> 320000 5 | - streetName -> "Fifth Street" 6 | - built -> "2012" 7 | - owner -> {name: "Blake", age: 29} 8 | - offers -> [290000, 295000, 315000, 312000] 9 | 10 | 2. Print out "houseForSale" to the terminal 11 | 12 | 3. Delete the entry with the key "built" 13 | 14 | 4. Change the age of the owner to be 30 inside "houseForSale" 15 | 16 | 5. Print out the maximum offerPrice (use reduce) 17 | 18 | 6. Add a new entry: "sale price" -> 312000 19 | 20 | 7. Print out "houseForSale" to the terminal 21 | 22 | *This is a challenging exercise - take it slow and step by step 23 | */ 24 | -------------------------------------------------------------------------------- /015-maps/exercises/warmup-exercise.js: -------------------------------------------------------------------------------- 1 | /* 2 | 1. Create a Map called "mexico" with the following entries: 3 | - id -> 24 4 | - name -> "Mexico" 5 | - capital -> "Mexico City" 6 | - neighbours -> ["USA", "Guatemala", "Belize"] 7 | 8 | 2. Print out "mexico" to the terminal 9 | 10 | 3. Change "id" to be 25 11 | 12 | 4. Add "Honduras" to the list of neighbours to "mexico" 13 | 14 | 5. Print out "mexico" to the terminal again 15 | */ 16 | -------------------------------------------------------------------------------- /015-maps/video-examples/map-intro.js: -------------------------------------------------------------------------------- 1 | const myMap = new Map(); 2 | 3 | console.log(myMap); 4 | 5 | // { 6 | // name: 'nader', 7 | // age: 10 8 | // } 9 | 10 | myMap.set("name", "nader"); 11 | myMap.set("age", 10); 12 | 13 | console.log(myMap); 14 | 15 | const age = myMap.get("age"); 16 | console.log(age); 17 | 18 | myMap.set("age", 11); 19 | console.log(myMap); 20 | 21 | console.log(myMap.has("name")); 22 | console.log(myMap.has("last name")); 23 | 24 | console.log(myMap.size); 25 | 26 | myMap.delete("age"); 27 | console.log(myMap); 28 | console.log(myMap.size); 29 | -------------------------------------------------------------------------------- /016-sets/exercise-solutions/exercise-1.js: -------------------------------------------------------------------------------- 1 | /* 2 | 1. Create an array called "points" with the following values: 3 | [10, 20, 10, 30, 15, 15, 35, 60, 10] 4 | 5 | 2. How can you print out all the UNIQUE points inside "points"? 6 | */ 7 | 8 | const points = [10, 20, 10, 30, 15, 15, 35, 60, 10]; 9 | 10 | const uniquePoints = new Set(); 11 | 12 | for (let i = 0; i < points.length; i++) { 13 | uniquePoints.add(points[i]); 14 | } 15 | 16 | console.log(uniquePoints); 17 | 18 | const cheatUniquePoints = new Set(points); 19 | console.log(cheatUniquePoints); 20 | -------------------------------------------------------------------------------- /016-sets/exercise-solutions/warmup-exercise.js: -------------------------------------------------------------------------------- 1 | /* 2 | 1. Create a variable called "numbers" that points to a new Set 3 | 4 | 2. Add the following numbers to "numbers" (each a separate line): 5 | 1, 2, 3, 4, 5, 2, 3, 4 6 | 7 | 3. Print out "numbers" and note what is inside it 8 | 9 | 4. Repeat the same steps above but with an array 10 | How does this differ? 11 | */ 12 | 13 | const numbers = new Set(); 14 | 15 | numbers.add(1); 16 | numbers.add(2); 17 | numbers.add(3); 18 | numbers.add(4); 19 | numbers.add(5); 20 | numbers.add(2); 21 | numbers.add(3); 22 | numbers.add(4); 23 | 24 | console.log(numbers); 25 | 26 | const numbersArray = [1, 2, 3, 4, 5, 2, 3, 4]; 27 | console.log(numbersArray); 28 | -------------------------------------------------------------------------------- /016-sets/exercises/exercise-1.js: -------------------------------------------------------------------------------- 1 | /* 2 | 1. Create an array called "points" with the following values: 3 | [10, 20, 10, 30, 15, 15, 35, 60, 10] 4 | 5 | 2. How can you print out all the UNIQUE points inside "points"? 6 | */ 7 | -------------------------------------------------------------------------------- /016-sets/exercises/exercise-2.js: -------------------------------------------------------------------------------- 1 | /* 2 | 1. Create an array called "numbers" with the following values: 3 | [10, 20, 15, 30, 15, 20, 35, 60, 10] 4 | 5 | 2. Find the first duplicate value in "numbers" and print 6 | it out to the terminal 7 | 8 | HINT: Add the numbers to a Set as you for-loop over "numbers" 9 | 10 | *This is quite challenging and is a common interview question 11 | */ 12 | -------------------------------------------------------------------------------- /016-sets/exercises/warmup-exercise.js: -------------------------------------------------------------------------------- 1 | /* 2 | 1. Create a variable called "numbers" that points to a new Set 3 | 4 | 2. Add the following numbers to "numbers" (each a separate line): 5 | 1, 2, 3, 4, 5, 2, 3, 4 6 | 7 | 3. Print out "numbers" and note what is inside it 8 | 9 | 4. Repeat the same steps above but with an array 10 | How does this differ? 11 | */ 12 | -------------------------------------------------------------------------------- /016-sets/video-examples/set-basics.js: -------------------------------------------------------------------------------- 1 | const mySet = new Set(); 2 | 3 | mySet.add(10); 4 | mySet.add(20); 5 | mySet.add(30); 6 | mySet.add(40); 7 | 8 | console.log(mySet); 9 | 10 | mySet.add(10); 11 | mySet.add(10); 12 | mySet.add(10); 13 | 14 | console.log(mySet); 15 | 16 | mySet.add("10"); 17 | 18 | console.log(mySet); 19 | 20 | mySet.delete(20); 21 | console.log(mySet); 22 | 23 | console.log(mySet.has(30)); 24 | console.log(mySet.has(300)); 25 | 26 | console.log(mySet.size); 27 | -------------------------------------------------------------------------------- /017-for-of-loops/exercise-solutions/exercise-2.js: -------------------------------------------------------------------------------- 1 | /* 2 | 1. Create an empty Set called "names" 3 | 4 | 2. Create another empty Set called "capsNames" 5 | 6 | 2. Add the following names to the set "names": 7 | - Bilbo 8 | - Hermione 9 | - Spock 10 | - Leia 11 | 12 | 3. Use a for-of loop to loop over "names" and 13 | adds the capitalized version of each name 14 | to the "capsNames" set 15 | 16 | 4. Print out "capsNames" 17 | */ 18 | 19 | const names = new Set(); 20 | const capsNames = new Set(); 21 | 22 | names.add("Bilbo"); 23 | names.add("Hermione"); 24 | names.add("Spock"); 25 | names.add("Leia"); 26 | 27 | for (const name of names) { 28 | capsNames.add(name.toUpperCase()); 29 | } 30 | 31 | console.log(capsNames); 32 | -------------------------------------------------------------------------------- /017-for-of-loops/exercise-solutions/warmup-exercise.js: -------------------------------------------------------------------------------- 1 | /* 2 | 1. Create a variable called "numbers" that points to this array: 3 | [10, 20, 40, 50, 20, 100] 4 | 5 | 2. Use a for-of loop to print out each number squared 6 | */ 7 | 8 | const numbers = [10, 20, 40, 50, 20, 100]; 9 | 10 | for (const number of numbers) { 11 | console.log(number ** 2); 12 | } 13 | -------------------------------------------------------------------------------- /017-for-of-loops/exercises/exercise-1.js: -------------------------------------------------------------------------------- 1 | /* 2 | 1. Create a variable called "ages" that points to this array: 3 | [10, 42, 15, 22, 11, 74, 39, 2] 4 | 5 | 2. Create an array called "results" that starts off empty 6 | 7 | 3. Use a for-of loop to loop over "ages" and add an Object 8 | to "results" with an "age" key having the value of the "age" 9 | being looped over. Also, add a "name" key that is always "Dragon". 10 | Eg: {age: 10, name: "Dragon"}, {age: 42, name: "Dragon"} 11 | 12 | 4. Print out "results" 13 | 14 | 5. "results" should be: 15 | [{age: 10, name: "Dragon"}, {age: 42, name: "Dragon"}, 16 | {age: 15, name: "Dragon"}, {age: 22, name: "Dragon"}, 17 | {age: 11, name: "Dragon"}, {age: 74, name: "Dragon"}, 18 | {age: 39, name: "Dragon"}, {age: 2, name: "Dragon"}] 19 | */ 20 | -------------------------------------------------------------------------------- /017-for-of-loops/exercises/exercise-2.js: -------------------------------------------------------------------------------- 1 | /* 2 | 1. Create an empty Set called "names" 3 | 4 | 2. Create another empty Set called "capsNames" 5 | 6 | 2. Add the following names to the set "names": 7 | - Bilbo 8 | - Hermione 9 | - Spock 10 | - Leia 11 | 12 | 3. Use a for-of loop to loop over "names" and 13 | adds the capitalized version of each name 14 | to the "capsNames" set 15 | 16 | 4. Print out "capsNames" 17 | */ 18 | -------------------------------------------------------------------------------- /017-for-of-loops/exercises/exercise-3.js: -------------------------------------------------------------------------------- 1 | /* 2 | 1. Create a Map called "backpack" and add the following entries: 3 | - 1 => {name: "Sword", value: 300} 4 | - 2 => {name: "Banana", value: 5} 5 | - 3 => {name: "Gold Nugget", value: 10000} 6 | - 4 => {name: "Pants", value: 100} 7 | 8 | 2. Use a for-of loop to loop over "backpack" and print out 9 | the name and the value for each item in the following format: 10 | Name: $Value 11 | For example: Sword: $300 12 | 13 | 3. Also print out the total value of all items in the backpack 14 | */ 15 | -------------------------------------------------------------------------------- /017-for-of-loops/exercises/warmup-exercise.js: -------------------------------------------------------------------------------- 1 | /* 2 | 1. Create a variable called "numbers" that points to this array: 3 | [10, 20, 40, 50, 20, 100] 4 | 5 | 2. Use a for-of loop to print out each number squared 6 | */ 7 | -------------------------------------------------------------------------------- /017-for-of-loops/video-examples/for-of-arrays.js: -------------------------------------------------------------------------------- 1 | const characters = ["Frodo", "Harry", "Thanos", "Gandalf", "Yoda"]; 2 | 3 | for (let i = 0; i < characters.length; i++) { 4 | // characters[i] = characters[i].toUpperCase(); 5 | // console.log(characters[i + 1]); 6 | } 7 | 8 | console.log(characters); 9 | console.log("-----"); 10 | 11 | for (let character of characters) { 12 | console.log(character); 13 | character = character.toUpperCase(); 14 | console.log(character); 15 | } 16 | 17 | console.log(characters); 18 | -------------------------------------------------------------------------------- /017-for-of-loops/video-examples/for-of-maps.js: -------------------------------------------------------------------------------- 1 | const myMap = new Map(); 2 | 3 | myMap.set("name", "Nader"); 4 | myMap.set("age", 20); 5 | myMap.set("friend", "Mr. Monkey"); 6 | 7 | console.log(myMap); 8 | 9 | for (const item of myMap) { 10 | console.log(item[0], item[1]); 11 | } 12 | -------------------------------------------------------------------------------- /017-for-of-loops/video-examples/for-of-objects.js: -------------------------------------------------------------------------------- 1 | const stockItem = { 2 | id: 54, 3 | price: 1.32, 4 | name: "Apple", 5 | quantity: 6, 6 | }; 7 | 8 | // console.log(Object.entries(stockItem)); 9 | 10 | for (const item of Object.values(stockItem)) { 11 | console.log(item); 12 | } 13 | -------------------------------------------------------------------------------- /017-for-of-loops/video-examples/for-of-sets.js: -------------------------------------------------------------------------------- 1 | const mySet = new Set(); 2 | 3 | mySet.add("hello"); 4 | mySet.add("monkey"); 5 | mySet.add("monkey"); 6 | mySet.add("monkey"); 7 | mySet.add(10); 8 | mySet.add(11); 9 | mySet.add(true); 10 | 11 | console.log(mySet); 12 | 13 | for (const item of mySet) { 14 | console.log(item); 15 | } 16 | -------------------------------------------------------------------------------- /017-for-of-loops/video-examples/for-of-strings.js: -------------------------------------------------------------------------------- 1 | const message = "Today is a wonderful day!"; 2 | 3 | for (const char of message) { 4 | console.log(char.toUpperCase()); 5 | } 6 | 7 | console.log(message); 8 | -------------------------------------------------------------------------------- /018-Project-1-Blackjack-Game/exercises/advice.js: -------------------------------------------------------------------------------- 1 | /* 2 | General Advice: 3 | 4 | - You will get stuck! Embrace it and treat it as part of the process and learning 5 | - If you get stuck for too long, take a break or try another section of the program 6 | and come back later. 7 | - Google is your friend 8 | - Careful not to copy and paste code off the Internet - write it out yourself again 9 | and make sure you understand each line 10 | - Break down the problems in to smaller sub-problems and solve those as independently 11 | as you can 12 | - Have fun with it! 13 | */ 14 | -------------------------------------------------------------------------------- /018-Project-1-Blackjack-Game/exercises/example-demos.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Nooder/javascript-in-depth/ba8447af2e4edf784606f946da4a682539fa52da/018-Project-1-Blackjack-Game/exercises/example-demos.png -------------------------------------------------------------------------------- /018-Project-1-Blackjack-Game/exercises/pre-requisites.js: -------------------------------------------------------------------------------- 1 | /* 2 | Pre-requisites: 3 | 4 | - Variables 5 | - Conditionals 6 | - Loops 7 | - Functions 8 | - Arrays 9 | - Objects 10 | 11 | * VSCode and NodeJS 12 | */ 13 | -------------------------------------------------------------------------------- /018-Project-1-Blackjack-Game/video-examples/advice.js: -------------------------------------------------------------------------------- 1 | /* 2 | General Advice: 3 | 4 | - You will get stuck! Embrace it and treat it as part of the process and learning 5 | - If you get stuck for too long, take a break or try another section of the program 6 | and come back later. 7 | - Google is your friend 8 | - Careful not to copy and paste code off the Internet - write it out yourself again 9 | and make sure you understand each line 10 | - Break down the problems in to smaller sub-problems and solve those as independently 11 | as you can 12 | - Have fun with it! 13 | */ 14 | -------------------------------------------------------------------------------- /018-Project-1-Blackjack-Game/video-examples/example-demos.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Nooder/javascript-in-depth/ba8447af2e4edf784606f946da4a682539fa52da/018-Project-1-Blackjack-Game/video-examples/example-demos.png -------------------------------------------------------------------------------- /018-Project-1-Blackjack-Game/video-examples/pre-requisites.js: -------------------------------------------------------------------------------- 1 | /* 2 | Pre-requisites: 3 | 4 | - Variables 5 | - Conditionals 6 | - Loops 7 | - Functions 8 | - Arrays 9 | - Objects 10 | 11 | * VSCode and NodeJS 12 | */ 13 | -------------------------------------------------------------------------------- /019-promises/exercise-solutions/warmup-exercise.js: -------------------------------------------------------------------------------- 1 | /* 2 | 1. Print out "Program started" at the start of your code 3 | 2. Create a Promise that resolves after 3 seconds 4 | 3. Log out the promise while it's pending 5 | 4. Print out "Program in progress..." as well 6 | 5. Print out "Program complete" when the promise completes after 3 seconds 7 | 8 | HINT: Use setTimeout for the delay 9 | */ 10 | 11 | console.log("Program Started"); 12 | 13 | const myPromise = new Promise((resolve, reject) => { 14 | setTimeout(() => { 15 | // "Program complete" 16 | resolve("Program complete"); 17 | }, 3000); 18 | }); 19 | 20 | console.log(myPromise); 21 | console.log("Program in progress..."); 22 | 23 | myPromise.then((value) => { 24 | console.log(value); 25 | }); 26 | -------------------------------------------------------------------------------- /019-promises/exercises/BONUS-exercise.js: -------------------------------------------------------------------------------- 1 | /* 2 | 1. Create a Promise that resolves with the number 10 after 3 | 3 seconds 4 | 2. Create another Promise that resolves with the number 5 | 20 after 5 seconds 6 | 7 | How can we log out the sum (30) of these two resolved values 8 | once, after BOTH promises successfully fulfill? 9 | 10 | HINT: Use Google/Documentation to help find an answer 11 | HINT2: You can Google for something like: 12 | "resolve 2 promises at the same time javascript" 13 | */ 14 | -------------------------------------------------------------------------------- /019-promises/exercises/exercise-1.js: -------------------------------------------------------------------------------- 1 | /* 2 | 1. Print out "Program started" at the start of your code 3 | 2. Create a Promise that resolves after 3 seconds 4 | and rejects after 2 seconds 5 | 3. Log out the promise while it's pending 6 | 4. Print out "Program in progress..." as well 7 | 8 | 5. Print out "Program complete" if the promise fulfills 9 | 6. Print out "Program failure" if the promise rejects 10 | 11 | HINT: Use setTimeout for the delay 12 | */ 13 | -------------------------------------------------------------------------------- /019-promises/exercises/exercise-2.js: -------------------------------------------------------------------------------- 1 | /* 2 | 1. Print out "Program started" at the start of your code 3 | 2. Create a Promise that resolves after 3 seconds 4 | 3. Log out the promise while it's pending 5 | 4. Print out "Program in progress..." as well 6 | 7 | 5. Print out "Step 1 complete" when the first promise fulfills 8 | 6. Have the first promise return another new Promise that will 9 | fulfill after 3 seconds with the message: "Step 2 Complete" 10 | 11 | 7. Print out the message from the second promise after it 12 | fulfills ("Step 2 Complete") 13 | 14 | HINT: Use setTimeout for the delay 15 | */ 16 | -------------------------------------------------------------------------------- /019-promises/exercises/warmup-exercise.js: -------------------------------------------------------------------------------- 1 | /* 2 | 1. Print out "Program started" at the start of your code 3 | 2. Create a Promise that resolves after 3 seconds 4 | 3. Log out the promise while it's pending 5 | 4. Print out "Program in progress..." as well 6 | 5. Print out "Program complete" when the promise completes after 3 seconds 7 | 8 | HINT: Use setTimeout for the delay 9 | */ 10 | -------------------------------------------------------------------------------- /019-promises/video-examples/newPromise.js: -------------------------------------------------------------------------------- 1 | const myPromise = new Promise((resolve, reject) => { 2 | setTimeout(() => { 3 | console.log("Hello my friend!"); 4 | // resolve("Here is your ice cream!"); 5 | reject("Sorry, no ice cream for you!"); 6 | }, 2000); 7 | }); 8 | 9 | myPromise 10 | .then((resolvedValue) => { 11 | console.log("promise seems to be done!"); 12 | console.log(resolvedValue); 13 | console.log(myPromise); 14 | return "yo!"; 15 | }) 16 | .then((anotherValue) => { 17 | console.log(anotherValue); 18 | }) 19 | .catch((error) => { 20 | console.log(error); 21 | console.log(myPromise); 22 | }); 23 | 24 | console.log("Hello?"); 25 | console.log(myPromise); 26 | -------------------------------------------------------------------------------- /020-error-handling/exercise-solutions/exercise-1.js: -------------------------------------------------------------------------------- 1 | /* 2 | 1. Create a loop that loops 10 times starting at 1 3 | 2. On each loop iteration, print out the loop number 4 | 3. On loop number 5, throw an Error Object with the message "Boom!" 5 | 6 | 4. Catch the error and console.error the loop number 7 | 5. Make sure the loop goes all the way to 10 8 | */ 9 | let i; 10 | try { 11 | for (i = 1; i <= 10; i++) { 12 | console.log(i); 13 | 14 | // try { 15 | if (i === 5) { 16 | throw new Error("Boom!"); 17 | } 18 | // } catch (error) { 19 | // console.error(`Error on loop # ${i}`); 20 | // } 21 | } 22 | } catch (error) { 23 | console.error(`Error on loop # ${i}`); 24 | } 25 | -------------------------------------------------------------------------------- /020-error-handling/exercise-solutions/exercise-2.js: -------------------------------------------------------------------------------- 1 | /* 2 | 1. Assign the following object to a variable called "user": 3 | { name: "Misha", age: 22, settings: {colour: "blue"} } 4 | 2. Log out "Creating user..." 5 | 3. Try to log out: user.profile.colour 6 | 4. Log out "User created!" 7 | 5. Run the code and observe the behaviour 8 | 9 | 6. How would you fix this code (without changing steps 1-4 10 | or the user Object)? Also, add any appropriate logging 11 | you feel makes sense. 12 | */ 13 | 14 | try { 15 | const user = { name: "Misha", age: 22, settings: { colour: "blue" } }; 16 | 17 | console.log("Creating user..."); 18 | 19 | console.log(user.profile.colour); // undefined.colour 20 | 21 | console.log("User created!"); 22 | } catch (error) { 23 | console.error(error); 24 | } 25 | 26 | console.log("Program complete!"); 27 | -------------------------------------------------------------------------------- /020-error-handling/exercise-solutions/warmup-exercise.js: -------------------------------------------------------------------------------- 1 | /* 2 | 1. Log out "Program started" 3 | 2. Throw an Error Object with the message "Uh oh!" 4 | 3. At the end of the program log out "Program complete!" 5 | 4. Run the program and watch it crash 6 | 7 | 5. Create a try/catch block that console.error's out 8 | the error message 9 | 6. Run the program again and see the difference 10 | */ 11 | 12 | try { 13 | console.log("Program started"); 14 | 15 | throw new Error("Uh oh!"); 16 | } catch (error) { 17 | console.error(error); 18 | } 19 | 20 | console.log("Program complete!"); 21 | -------------------------------------------------------------------------------- /020-error-handling/exercises/exercise-1.js: -------------------------------------------------------------------------------- 1 | /* 2 | 1. Create a loop that loops 10 times starting at 1 3 | 2. On each loop iteration, print out the loop number 4 | 3. On loop number 5, throw an Error Object with the message "Boom!" 5 | 6 | 4. Catch the error and console.error the loop number 7 | 5. Make sure the loop goes all the way to 10 8 | */ 9 | -------------------------------------------------------------------------------- /020-error-handling/exercises/exercise-2.js: -------------------------------------------------------------------------------- 1 | /* 2 | 1. Assign the following object to a variable called "user": 3 | { name: "Misha", age: 22, settings: {colour: "blue"} } 4 | 2. Log out "Creating user..." 5 | 3. Try to log out: user.profile.colour 6 | 4. Log out "User created!" 7 | 5. Run the code and observe the behaviour 8 | 9 | 6. How would you fix this code (without changing steps 1-4 10 | or the user Object)? Also, add any appropriate logging 11 | you feel makes sense. 12 | */ 13 | -------------------------------------------------------------------------------- /020-error-handling/exercises/exercise-3.js: -------------------------------------------------------------------------------- 1 | /* 2 | 1. Create a try block that does the following: 3 | - Create a variable called "number" and initialize 4 | it to the number 1337 5 | - Add a random number between 0-1000 to "number" 6 | - Logs out "number" 7 | - If number is less than 2000: 8 | - Throws an Error Object with the message: "You lose!" 9 | - Otherwise, log out "You win!" with no throw/error 10 | 2. Create a catch block that catches the error and logs it 11 | 3. Inside the catch block, log out "number" as well 12 | 13 | 4. What is the issue with this setup/code? 14 | 5. How can we fix it so we can access "number" in the catch? 15 | */ 16 | -------------------------------------------------------------------------------- /020-error-handling/exercises/warmup-exercise.js: -------------------------------------------------------------------------------- 1 | /* 2 | 1. Log out "Program started" 3 | 2. Throw an Error Object with the message "Uh oh!" 4 | 3. At the end of the program log out "Program complete!" 5 | 4. Run the program and watch it crash 6 | 7 | 5. Create a try/catch block that console.error's out 8 | the error message 9 | 6. Run the program again and see the difference 10 | */ 11 | -------------------------------------------------------------------------------- /020-error-handling/video-examples/throw.js: -------------------------------------------------------------------------------- 1 | throw "there was a bad thing that happened!"; 2 | 3 | console.log("hello?"); 4 | 5 | // code 6 | -------------------------------------------------------------------------------- /020-error-handling/video-examples/try-catch-object.js: -------------------------------------------------------------------------------- 1 | try { 2 | const user = { 3 | name: "Alex", 4 | age: 21, 5 | // profile: { 6 | // // colour: "blue", 7 | // }, 8 | }; 9 | console.log(user.profile.colour); 10 | // user.undefined.colour 11 | console.log("do I get here??"); 12 | } catch (error) { 13 | console.error("something bad happened.."); 14 | console.error(error); 15 | } 16 | 17 | // ... 18 | -------------------------------------------------------------------------------- /020-error-handling/video-examples/try-catch.js: -------------------------------------------------------------------------------- 1 | try { 2 | const message = "hello there!"; 3 | console.log(message); 4 | throw new Error("boom!"); 5 | } catch (error) { 6 | console.error(error); 7 | console.error("caught!"); 8 | } 9 | 10 | console.log("hi?"); 11 | -------------------------------------------------------------------------------- /020-error-handling/video-examples/try-scope.js: -------------------------------------------------------------------------------- 1 | const message = "meow"; 2 | 3 | try { 4 | // const message = "hello"; 5 | console.log(message); 6 | throw new Error("Oh no!"); 7 | } catch (err) { 8 | console.error(err); 9 | console.error(message); 10 | } 11 | 12 | console.log("Program complete!"); 13 | 14 | console.log(message); 15 | -------------------------------------------------------------------------------- /021-async-await/exercises/exercise-1.js: -------------------------------------------------------------------------------- 1 | /* 2 | 1. Create a function called "fetchUser" that returns 3 | a Promise that resolves with the value : 4 | { data: {user: "Monkey", admin: true} } after 3 seconds 5 | 2. Create a function called "login" that takes an Object 6 | as an argument. If the object has a property called 7 | "admin" with a value of true, then log out 8 | "Successfully logged in!", otherwise log out 9 | "Failed to log in, please try again." 10 | 11 | 3. Print out "Program starting..." 12 | 13 | 4. Create an async function that uses await to wait for 14 | the data to comes back from "fetchUser". 15 | 16 | 5. Pass the user that comes back from "fetchUser" to the 17 | "login" function you created above 18 | 19 | 6. Call the async function you created 20 | 7. Log out "Program complete!" 21 | */ 22 | -------------------------------------------------------------------------------- /021-async-await/exercises/exercise-2.js: -------------------------------------------------------------------------------- 1 | /* 2 | 1. Create a function called "fetchFast" that returns 3 | a Promise that resolves with the String "Fast Done!" 4 | after 2 seconds 5 | 2. Create a function called "fetchSlow" that returns 6 | a Promise that resolves with the String "Slow Done" 7 | after 6 seconds 8 | 3. Print out "Program starting..." 9 | 10 | 4. Create an async function that uses await to wait for 11 | the data to comes back from "fetchFast" then log out 12 | the data. Then use await to wait for the data to come 13 | back from "fetchSlow" and log it out right after. 14 | 15 | 5. Call the async function you created 16 | 6. Log out "Program complete!" 17 | 18 | 7. How long does this take and why? 19 | 8. How could you speed it up? 20 | */ 21 | -------------------------------------------------------------------------------- /021-async-await/exercises/warmup-exercise.js: -------------------------------------------------------------------------------- 1 | /* 2 | 1. Create a function called "fetchPokemon" that returns 3 | a Promise that resolves with the value : 4 | { data: {name: "Pickachu", power: 20} } after 2 seconds 5 | 2. Print out "Program starting..." 6 | 7 | 3. Create an async function that uses await to wait for 8 | the data to comes back from "fetchPokemon" then log out 9 | the data 10 | 11 | 4. Call the async function you created 12 | 5. Log out "Program complete!" 13 | 14 | After your're done the above ^: 15 | 6. Change "fetchPokemon" to reject after 2 seconds instead 16 | with a new Error Object with the message "Danger, danger!" 17 | 7. How can you modify your async function to catch this error? 18 | */ 19 | -------------------------------------------------------------------------------- /021-async-await/video-examples/async-await.js: -------------------------------------------------------------------------------- 1 | const makeTimeout = (ms) => { 2 | const timeout = new Promise((resolve, reject) => { 3 | setTimeout(() => { 4 | resolve("All done!"); 5 | }, ms); 6 | }); 7 | 8 | return timeout; 9 | }; 10 | 11 | console.log("Program starting..."); // 1 12 | 13 | makeTimeout(1000) 14 | .then((result) => { 15 | console.log("from .then", result); // 3 16 | }) 17 | .then(() => { 18 | return "hello"; 19 | }); 20 | 21 | const fetchStuff = async () => { 22 | const result = await makeTimeout(500); 23 | console.log("from async func", result); 24 | }; 25 | 26 | fetchStuff(); 27 | fetchStuff(); 28 | 29 | console.log("Program complete..."); // 2 30 | -------------------------------------------------------------------------------- /021-async-await/video-examples/errors.js: -------------------------------------------------------------------------------- 1 | const makeTimeout = (ms) => { 2 | const timeout = new Promise((resolve, reject) => { 3 | setTimeout(() => { 4 | resolve("All done!"); 5 | // reject("there was an error!"); 6 | }, ms); 7 | }); 8 | 9 | return timeout; 10 | }; 11 | 12 | const causeError = async () => { 13 | // let result; 14 | try { 15 | const result = await makeTimeout(2000); 16 | console.log(result); 17 | } catch (error) { 18 | console.log("we are in the error case, all done"); 19 | console.error(error); 20 | } 21 | // down here 22 | }; 23 | 24 | console.log("program started"); 25 | causeError(); 26 | console.log("program done"); 27 | -------------------------------------------------------------------------------- /021-async-await/video-examples/pausing.js: -------------------------------------------------------------------------------- 1 | const makeTimeout = (ms) => { 2 | const timeout = new Promise((resolve, reject) => { 3 | setTimeout(() => { 4 | resolve("All done!"); 5 | }, ms); 6 | }); 7 | 8 | return timeout; 9 | }; 10 | 11 | console.log("Program starting..."); // 1 12 | 13 | const fetchData = async () => { 14 | console.log("Fetching first set of data..."); // 2 15 | const result1 = makeTimeout(2000); 16 | console.log("Fetching second set of data...", result1); // 4 17 | const result2 = makeTimeout(2000); 18 | const finalResult = await Promise.all([result1, result2]); 19 | console.log("Done fetching data!", finalResult); // 5 20 | }; 21 | 22 | fetchData(); 23 | 24 | console.log("Program complete..."); // 3 25 | -------------------------------------------------------------------------------- /021-async-await/video-examples/return.js: -------------------------------------------------------------------------------- 1 | const fetchData = async () => { 2 | return "hello!"; 3 | }; 4 | 5 | const result = fetchData(); 6 | console.log(result); 7 | 8 | result 9 | .then((value) => { 10 | console.log(value); 11 | }) 12 | .catch((error) => { 13 | console.error(error); 14 | }); 15 | 16 | const useHello = async () => { 17 | const result = await fetchData(); 18 | console.log(result); 19 | }; 20 | 21 | useHello(); 22 | -------------------------------------------------------------------------------- /022-array-object-spread-syntax/exercise-solutions/warmup-exercise.js: -------------------------------------------------------------------------------- 1 | /* 2 | 1. Create an variable called "points" that points at this array: 3 | [10, 15, 20, 30, 5] 4 | 5 | 2. Create another variable called "pointsCopy" that creates a 6 | copy of "points" using the spread operator, but also adds 7 | 2 extra values at the end: 50 and 75 8 | 9 | 3. Print out both "pointsCopy" and "points" 10 | */ 11 | 12 | const points = [10, 15, 20, 30, 5]; 13 | 14 | const pointsCopy = [...points, 50, 75]; 15 | 16 | console.log(points); 17 | console.log(pointsCopy); 18 | -------------------------------------------------------------------------------- /022-array-object-spread-syntax/exercises/exercise-1.js: -------------------------------------------------------------------------------- 1 | /* 2 | 1. Create an variable called "views" that points at this array: 3 | [ [5, 10, 20], [10, 20, 30] ] 4 | 5 | 2. Create another variable called "viewsCopy" that creates a 6 | copy of "views" using the spread operator 7 | 8 | 3. Print out "views" and "viewsCopy" 9 | 10 | 4. Add the number 40 to the end of the second array inside "viewsCopy" 11 | and delete the last number (20) inside the first array 12 | 13 | 5. Add the array [100, 200] to the end of "viewsCopy" 14 | 15 | 6. Print out "views" and "viewsCopy" 16 | 17 | *Explain this behaviour 18 | */ 19 | -------------------------------------------------------------------------------- /022-array-object-spread-syntax/exercises/warmup-exercise.js: -------------------------------------------------------------------------------- 1 | /* 2 | 1. Create an variable called "points" that points at this array: 3 | [10, 15, 20, 30, 5] 4 | 5 | 2. Create another variable called "pointsCopy" that creates a 6 | copy of "points" using the spread operator, but also adds 7 | 2 extra values at the end: 50 and 75 8 | 9 | 3. Print out both "pointsCopy" and "points" 10 | */ 11 | -------------------------------------------------------------------------------- /022-array-object-spread-syntax/video-examples/array-shallow.js: -------------------------------------------------------------------------------- 1 | const prices = [[10], [20], [30]]; 2 | 3 | console.log(prices); 4 | 5 | const copy = [...prices]; 6 | 7 | console.log(copy); 8 | 9 | console.log("-------"); 10 | 11 | prices[0].pop(); 12 | console.log(prices); 13 | 14 | console.log(copy); 15 | -------------------------------------------------------------------------------- /022-array-object-spread-syntax/video-examples/intro.js: -------------------------------------------------------------------------------- 1 | const array = [10, 20, 30, 40, 50]; 2 | 3 | const arrayCopy1 = []; 4 | for (const value of array) { 5 | arrayCopy1.push(value); 6 | } 7 | arrayCopy1.push(60); 8 | arrayCopy1.push(70); 9 | arrayCopy1.push(80); 10 | 11 | console.log(array); 12 | console.log(arrayCopy1); 13 | 14 | const arrayCopy2 = [10, 20, ...array, 60, 70, 80]; 15 | console.log(arrayCopy2); 16 | -------------------------------------------------------------------------------- /022-array-object-spread-syntax/video-examples/maps.js: -------------------------------------------------------------------------------- 1 | const myMap = new Map(); 2 | 3 | myMap.set("Monkey", 5); 4 | myMap.set("Tiger", 1); 5 | myMap.set("Elephant", 2); 6 | 7 | console.log(myMap); 8 | 9 | const myMapArray = [...myMap, "boo!"]; 10 | 11 | console.log(myMapArray); 12 | -------------------------------------------------------------------------------- /022-array-object-spread-syntax/video-examples/obj-shallow.js: -------------------------------------------------------------------------------- 1 | const countryPop = { 2 | Germany: 83, 3 | Brazil: 212, 4 | Egypt: 102, 5 | Canada: { 6 | pop: 38, 7 | }, 8 | }; 9 | 10 | const countryPopCopy = { ...countryPop }; 11 | 12 | console.log(countryPop); 13 | console.log(countryPopCopy); 14 | 15 | console.log("-----"); 16 | 17 | countryPop.Canada.capital = "Ottawa"; 18 | 19 | console.log(countryPop); 20 | 21 | console.log(countryPopCopy); 22 | -------------------------------------------------------------------------------- /022-array-object-spread-syntax/video-examples/object-dups.js: -------------------------------------------------------------------------------- 1 | const countryPop = { 2 | Germany: 83, 3 | Brazil: 212, 4 | Egypt: 102, 5 | }; 6 | 7 | const countryPopCopy = { 8 | Germany: 999, 9 | ...countryPop, 10 | Indonesia: 273, 11 | }; 12 | 13 | console.log(countryPopCopy); 14 | -------------------------------------------------------------------------------- /022-array-object-spread-syntax/video-examples/objects.js: -------------------------------------------------------------------------------- 1 | const countryPop = { 2 | Germany: 83, 3 | Brazil: 212, 4 | Egypt: 102, 5 | }; 6 | 7 | console.log(countryPop); 8 | 9 | const countryPopExtended = {}; 10 | for (const entry of Object.entries(countryPop)) { 11 | const country = entry[0]; 12 | const pop = entry[1]; 13 | countryPopExtended[country] = pop; 14 | } 15 | countryPopExtended["Indonesia"] = 273; 16 | countryPopExtended["Japan"] = 125; 17 | 18 | const countryPopExtended2 = { 19 | ...countryPop, 20 | Indonesia: 273, 21 | Japan: 125, 22 | }; 23 | 24 | console.log(countryPopExtended); 25 | -------------------------------------------------------------------------------- /022-array-object-spread-syntax/video-examples/sets.js: -------------------------------------------------------------------------------- 1 | const mySet = new Set(); 2 | 3 | mySet.add("Batman"); 4 | mySet.add("Robin"); 5 | mySet.add("Spiderman"); 6 | mySet.add("Batman"); 7 | 8 | console.log(mySet); 9 | 10 | const mySetCopy = ["Robin", ...mySet, "Batman"]; 11 | 12 | console.log(mySetCopy); 13 | -------------------------------------------------------------------------------- /022-array-object-spread-syntax/video-examples/strings.js: -------------------------------------------------------------------------------- 1 | const phrase = "Hello, my friend!"; 2 | 3 | const copy = [...phrase]; 4 | 5 | console.log(copy); 6 | -------------------------------------------------------------------------------- /023-destructuring-syntax/exercise-solutions/warmup-exercise.js: -------------------------------------------------------------------------------- 1 | /* 2 | 1. Create an variable called "jungle" that points at the array: 3 | ["Monkey", "Lion", "Panda", "Rabbit", "Squirrel"] 4 | 5 | 2. Use array destructuring to destructure out "Lion", and 6 | "Rabbit" while ignoring the other animals 7 | 8 | 3. Print out your variables containing "Lion" and "Rabbit" 9 | */ 10 | 11 | // const jungle = ["Monkey", "Lion", "Panda", "Rabbit", "Squirrel"]; 12 | 13 | // const [, lion, , rabbit] = jungle; 14 | 15 | const [, lion, , rabbit] = ["Monkey", "Lion", "Panda", "Rabbit", "Squirrel"]; 16 | 17 | console.log(lion, rabbit); 18 | -------------------------------------------------------------------------------- /023-destructuring-syntax/exercises/exercise-1.js: -------------------------------------------------------------------------------- 1 | /* 2 | 1. Create a variable called "snacks" that points to the Object: 3 | { 4 | chips: {name: "Pringles", salty: true}, 5 | candy: {name: "Twizzlers", salty: false}, 6 | chocolate: {name: "Mars", salty: false}, 7 | } 8 | 9 | 2. Destructure out "candy" from "snacks" using the Objects 10 | destructuring syntax. Also destructure out the key 11 | "fruit" which will be set to a default value of: 12 | {name: "Banana", salty: false} if it doesn't exist inside 13 | of "snacks". 14 | 15 | 3. Print out the variables pointing at the "candy" and "fruit" Objects 16 | */ 17 | -------------------------------------------------------------------------------- /023-destructuring-syntax/exercises/exercise-2.js: -------------------------------------------------------------------------------- 1 | /* 2 | 1. Create a variable called "store" that is a Map. Then add 3 | the following entries to the "store": 4 | - "Cups" with a value of 46 5 | - "Candles" with a value of 121 6 | - "Vases" with a value of 15 7 | 8 | 2. Use a for...of loop to loop through "store" but inside 9 | the loop's (const ____ of ____) syntax, use destructuring 10 | to destructure out the key and value using Array style 11 | destructuring. 12 | 13 | 3. Within the loop, print out the key and value on the 14 | same line seperated by a " => ". Eg: Cups => 46 15 | (The loop's body should only have one line of code) 16 | */ 17 | -------------------------------------------------------------------------------- /023-destructuring-syntax/exercises/warmup-exercise.js: -------------------------------------------------------------------------------- 1 | /* 2 | 1. Create an variable called "jungle" that points at the array: 3 | ["Monkey", "Lion", "Panda", "Rabbit", "Squirrel"] 4 | 5 | 2. Use array destructuring to destructure out "Lion", and 6 | "Rabbit" while ignoring the other animals 7 | 8 | 3. Print out your variables containing "Lion" and "Rabbit" 9 | */ 10 | -------------------------------------------------------------------------------- /023-destructuring-syntax/video-examples/array-intro.js: -------------------------------------------------------------------------------- 1 | const cities = ["Vancouver", "Mexico City", "Toronto", "London", "Berlin"]; 2 | 3 | // const vancouver = cities[0]; 4 | // const mexicoCity = cities[1]; 5 | 6 | const [, mexicoCity, ...theRest] = cities; 7 | 8 | // console.log(vancouver); 9 | console.log(mexicoCity); 10 | console.log(theRest); 11 | -------------------------------------------------------------------------------- /023-destructuring-syntax/video-examples/objects-intro.js: -------------------------------------------------------------------------------- 1 | const movie = { 2 | title: "Dune", 3 | year: "2021", 4 | length: 155, 5 | book: true, 6 | }; 7 | 8 | const { book, ...theRest } = movie; 9 | 10 | console.log(book); 11 | console.log(theRest); 12 | console.log(movie.rating); 13 | -------------------------------------------------------------------------------- /024-ternary-operator/exercise-solutions/exercise-1.js: -------------------------------------------------------------------------------- 1 | /* 2 | 1. Create a function called "over9000" that has a single 3 | parameter which is a Number. This function: 4 | - Returns "It's over 9000!!!" if the argument is > 9000 5 | - Returns "Taking a Nappa..." in all other cases 6 | 7 | 2. Do step 1 with a regular if/else clause first 8 | 9 | 3. Re-do step 1 with a ternary expressions 10 | 11 | BONUS: Can you shorten this with the short "arrow function 12 | expression" syntax? 13 | */ 14 | 15 | // const over9000 = (power) => { 16 | // if (power > 9000) { 17 | // return "It's over 9000!!!"; 18 | // } else { 19 | // return "Taking a Nappa..."; 20 | // } 21 | // }; 22 | 23 | const over9000 = (power) => 24 | power > 9000 ? "It's over 9000!!!" : "Taking a Nappa..."; 25 | 26 | const result = over9000(10000); 27 | console.log(result); 28 | -------------------------------------------------------------------------------- /024-ternary-operator/exercise-solutions/warmup-exercise.js: -------------------------------------------------------------------------------- 1 | /* 2 | 1. Create a variable called "hungry" that start as true; 3 | 4 | 2. Create an if/else statement that: 5 | - If "hungry" is true, print out "Have a cookie!" 6 | - Otherwise, print out: "No cookies for you!"; 7 | 8 | 3. Execute the code to make sure it works. 9 | 10 | 4. Repeat steps 2-3 but with a ternary expression. 11 | */ 12 | 13 | const hungry = true; 14 | 15 | // if (hungry === true) { 16 | // console.log("Have a cookie!"); 17 | // } else { 18 | // console.log("No cookies for you!"); 19 | // } 20 | 21 | hungry === true 22 | ? console.log("Have a cookie!") 23 | : console.log("No cookies for you!"); 24 | -------------------------------------------------------------------------------- /024-ternary-operator/exercises/exercise-1.js: -------------------------------------------------------------------------------- 1 | /* 2 | 1. Create a function called "over9000" that has a single 3 | parameter which is a Number. This function: 4 | - Returns "It's over 9000!!!" if the argument is > 9000 5 | - Returns "Taking a Nappa..." in all other cases 6 | 7 | 2. Do step 1 with a regular if/else clause first 8 | 9 | 3. Re-do step 1 with a ternary expressions 10 | 11 | BONUS: Can you shorten this with the short "arrow function 12 | expression" syntax? 13 | */ 14 | -------------------------------------------------------------------------------- /024-ternary-operator/exercises/exercise-2.js: -------------------------------------------------------------------------------- 1 | /* 2 | 1. Create a variable called "wizards" that points at the array: 3 | ["Gandalf", "Voldemort", "Harry", "Jafar", "Saruman", "Merlin"] 4 | 5 | 2. Map over "wizards" to create a new array that does the following: 6 | - If the name contains the letter "n" return the name but with 7 | all the "n"'s replaced with a "*" character 8 | - Otherwise return the name, but upper-cased 9 | - Use a regular if/else statement for this 10 | 11 | 3. Repeat step 2 but with a ternary expression 12 | 13 | BONUS: Can you shorten this with the short "arrow function 14 | expression" syntax? 15 | */ 16 | -------------------------------------------------------------------------------- /024-ternary-operator/exercises/exercise-3.js: -------------------------------------------------------------------------------- 1 | /* 2 | 1. Create a variable called "characters" that points at the array: 3 | ["Han Solo", "Spock", "Darth Vader", "Yoda", "Neo", "Sarah Connor"] 4 | 5 | 2. Filter over "characters" to create a new array that does the following: 6 | - If the name has a space in it " ", keep it in the result (return true) 7 | - Otherwise, filter it out (return false) 8 | - Use a regular if/else statement for this 9 | 10 | 3. Repeat step 2 but with a ternary expression 11 | 12 | BONUS: Can you shorten this with the short "arrow function 13 | expression" syntax? 14 | */ 15 | -------------------------------------------------------------------------------- /024-ternary-operator/exercises/warmup-exercise.js: -------------------------------------------------------------------------------- 1 | /* 2 | 1. Create a variable called "hungry" that start as true; 3 | 4 | 2. Create an if/else statement that: 5 | - If "hungry" is true, print out "Have a cookie!" 6 | - Otherwise, print out: "No cookies for you!"; 7 | 8 | 3. Execute the code to make sure it works. 9 | 10 | 4. Repeat steps 2-3 but with a ternary expression. 11 | */ 12 | -------------------------------------------------------------------------------- /024-ternary-operator/video-examples/functions.js: -------------------------------------------------------------------------------- 1 | const happyCheck = (happy) => { 2 | if (happy === true) { 3 | return "Yay!"; 4 | } else { 5 | return "Nope"; 6 | } 7 | }; 8 | 9 | const result1 = happyCheck(true); 10 | const result2 = happyCheck(false); 11 | 12 | console.log(result1, result2); 13 | 14 | const happyCheck2 = (happy) => { 15 | // return "Yay!" 16 | // return "Nope" 17 | return happy === true ? "Yay!" : "Nope"; 18 | }; 19 | 20 | const result3 = happyCheck2(true); 21 | const result4 = happyCheck2(false); 22 | 23 | console.log(result3, result4); 24 | 25 | const happyCheck3 = (happy) => (happy === true ? "Yay!" : "Nope"); 26 | 27 | const result5 = happyCheck3(true); 28 | const result6 = happyCheck3(false); 29 | 30 | console.log(result5, result6); 31 | -------------------------------------------------------------------------------- /024-ternary-operator/video-examples/intro.js: -------------------------------------------------------------------------------- 1 | const happy = false; 2 | 3 | happy === true ? console.log("Yay!") : console.log("Nope"); 4 | -------------------------------------------------------------------------------- /024-ternary-operator/video-examples/map.js: -------------------------------------------------------------------------------- 1 | const numbers = [5, 10, 15, 20, 25]; 2 | 3 | const overUnder = numbers.map((number) => (number > 10 ? "Over!" : "Under!")); 4 | 5 | console.log(overUnder); 6 | -------------------------------------------------------------------------------- /025-switch-statement/exercises/exercise-1.js: -------------------------------------------------------------------------------- 1 | /* 2 | 1. Create a variable called "activities" that points at the Array: 3 | ["Swimming", "Hiking", "Rock Climbing", "Biking", "Running"] 4 | 5 | 2. Create a loop that loops over "activities" and inside the loop 6 | use a switch statement that has these cases: 7 | - "Swimming": only print out "Like a fish!" 8 | - "Rock Climbing": only print out "Like a mountain goat!" 9 | - "Running": only print out "Like a cheetah!" 10 | - Otherwise only print out "I'm sure some animal does that..." 11 | 12 | 3. Run the code and make sure the correct messages get printed out 13 | */ 14 | -------------------------------------------------------------------------------- /025-switch-statement/exercises/exercise-2.js: -------------------------------------------------------------------------------- 1 | /* 2 | 1. Create a variable called "enemies" that points at the Object: 3 | { 4 | rat: { atk: 3, def: 2, hp: 20, class: 1 }, 5 | goblin: { atk: 10, def: 6, hp: 50, class: 1 }, 6 | troll: { atk: 30, def: 20, hp: 200, class: 2 }, 7 | giant: { atk: 50, def: 40, hp: 500, class: 2 }, 8 | } 9 | 10 | 2. Create a loop that loops over "enemies" and inside the loop use 11 | a switch statement on the "class" property that has these cases: 12 | - 1: print out only "This is an easy fight" 13 | - 2: print out only "This will require some training" 14 | - Otherwise only print out "Not implemented yet..." 15 | 16 | 3. Run the code and make sure the correct messages get printed out 17 | */ 18 | -------------------------------------------------------------------------------- /025-switch-statement/exercises/exercise-3.js: -------------------------------------------------------------------------------- 1 | /* 2 | 1. Create a variable called "points" that points at the Array: 3 | [3, 4, 1, 0, 1, 5, 6] 4 | 5 | 2. Create a loop that loops over "points" and inside the loop use 6 | a switch statement that has these cases: 7 | - 0-2: print out only "Good try!" 8 | - 3-5: print out only "Very well done!" 9 | - Otherwise only print out "Wow, shooting for the moon!" 10 | 11 | 3. Run the code and make sure the correct messages get printed out 12 | */ 13 | -------------------------------------------------------------------------------- /025-switch-statement/video-examples/intro.js: -------------------------------------------------------------------------------- 1 | const animal = "Tiger"; 2 | 3 | // switch ("Monkey") 4 | switch (animal) { 5 | case "Tiger": { 6 | console.log("You are a tiger!"); 7 | // break; 8 | } 9 | 10 | case "Koala": 11 | case "Monkey": { 12 | console.log("The best animal!"); 13 | // break; 14 | } 15 | 16 | default: { 17 | console.log("Must be something else!"); 18 | break; 19 | } 20 | } 21 | 22 | console.log("All done!"); 23 | -------------------------------------------------------------------------------- /026-generators/exercise-solutions/exercise-1.js: -------------------------------------------------------------------------------- 1 | /* 2 | 1. Create a generator function called "randomNumber" 3 | that will generate a new random number infinitely 4 | 5 | 2. Use a loop to generate 10 random numbers using the 6 | generator Object you get from calling "randomNumber" 7 | */ 8 | 9 | const randomNumber = function* () { 10 | while (true) { 11 | yield Math.random(); 12 | } 13 | }; 14 | 15 | const generatorObject = randomNumber(); 16 | 17 | // for (let i = 0; i < 10; i++) { 18 | // console.log(generatorObject.next().value); 19 | // } 20 | 21 | // let i = 0; 22 | // while (i < 10) { 23 | // console.log(generatorObject.next().value); 24 | // i++; 25 | // } 26 | 27 | // let i = 0; 28 | // for (const item of generatorObject) { 29 | // console.log(item); 30 | // i++; 31 | // if (i === 10) { 32 | // break; 33 | // } 34 | // } 35 | -------------------------------------------------------------------------------- /026-generators/exercise-solutions/warmup-exercise.js: -------------------------------------------------------------------------------- 1 | /* 2 | 1. Create a generator function called "countTo10" that will 3 | yield the numbers 0-10 (inclusive) then stop. 4 | 5 | 2. Create the generator object by calling the generator 6 | function and iterate through the generator using a 7 | for...of loop. 8 | */ 9 | 10 | const countTo10 = function* () { 11 | let i = 0; 12 | while (i <= 10) { 13 | yield i; 14 | i++; 15 | } 16 | }; 17 | 18 | const generatorObject = countTo10(); 19 | 20 | console.log(generatorObject.next()); 21 | 22 | for (const value of generatorObject) { 23 | console.log(value); 24 | } 25 | -------------------------------------------------------------------------------- /026-generators/exercises/exercise-1.js: -------------------------------------------------------------------------------- 1 | /* 2 | 1. Create a generator function called "randomNumber" 3 | that will generate a new random number infinitely 4 | 5 | 2. Use a loop to generate 10 random numbers using the 6 | generator Object you get from calling "randomNumber" 7 | */ 8 | -------------------------------------------------------------------------------- /026-generators/exercises/exercise-2.js: -------------------------------------------------------------------------------- 1 | /* 2 | 1. Create a generator function called "randomAmountFromRange" 3 | which has 3 parameters: amount, min, and max 4 | 5 | 2. ^ This function will generate the amount of random numbers 6 | provided as an argument, between the min and max (inclusive) 7 | Eg: randomAmountFromRange(3, 10, 20) => 13, 12, 19 8 | 9 | 3. Create a for...of loop that will loop through the following 10 | generator objects to test it: 11 | - randomAmountFromRange(3, 10, 20) 12 | - randomAmountFromRange(5, 100, 200) 13 | - randomAmountFromRange(10, 1000, 2000) 14 | */ 15 | -------------------------------------------------------------------------------- /026-generators/exercises/warmup-exercise.js: -------------------------------------------------------------------------------- 1 | /* 2 | 1. Create a generator function called "countTo10" that will 3 | yield the numbers 0-10 (inclusive) then stop. 4 | 5 | 2. Create the generator object by calling the generator 6 | function and iterate through the generator using a 7 | for...of loop. 8 | */ 9 | -------------------------------------------------------------------------------- /026-generators/video-examples/delegation.js: -------------------------------------------------------------------------------- 1 | const counter = function* () { 2 | yield 1; 3 | yield* [2, 3, 4]; 4 | yield 5; 5 | }; 6 | 7 | const generatorObject = counter(); 8 | 9 | for (const value of generatorObject) { 10 | console.log(value); 11 | } 12 | 13 | for (const value of [2, 3, 4]) { 14 | console.log(value); 15 | } 16 | -------------------------------------------------------------------------------- /026-generators/video-examples/infinite.js: -------------------------------------------------------------------------------- 1 | const counter = function* () { 2 | let i = 0; 3 | while (true) { 4 | yield i; 5 | i++; 6 | } 7 | }; 8 | 9 | const counterGenerator = counter(); 10 | 11 | // for (const value of counterGenerator) { 12 | // console.log(value); 13 | // } 14 | 15 | let count = 0; 16 | 17 | while (count < 5) { 18 | console.log(counterGenerator.next()); 19 | count++; 20 | } 21 | -------------------------------------------------------------------------------- /026-generators/video-examples/intro.js: -------------------------------------------------------------------------------- 1 | const counter = function* () { 2 | // pause here and return the generator 3 | console.log("This is the first log"); 4 | yield 1; 5 | console.log("this is after yield 1"); 6 | yield 2; 7 | yield 3; 8 | }; 9 | 10 | console.log(counter); 11 | 12 | const counterGenerator = counter(); 13 | console.log(counterGenerator); 14 | 15 | console.log(counterGenerator.next()); 16 | console.log(counterGenerator.next()); 17 | console.log(counterGenerator.next()); 18 | console.log(counterGenerator.next()); 19 | console.log(counterGenerator.next()); 20 | console.log(counterGenerator.next()); 21 | -------------------------------------------------------------------------------- /026-generators/video-examples/loops.js: -------------------------------------------------------------------------------- 1 | const counter = function* () { 2 | // pause here and return the generator 3 | yield 1; 4 | yield 2; 5 | yield 3; 6 | }; 7 | 8 | console.log(counter); 9 | 10 | const counterGenerator = counter(); 11 | // const counterGenerator2 = counter(); 12 | console.log(counterGenerator); 13 | 14 | for (const count of counterGenerator) { 15 | console.log(count); 16 | } 17 | 18 | let counterObject = counterGenerator.next(); 19 | console.log(counterObject); 20 | 21 | while (counterObject.done === false) { 22 | console.log(counterObject.value); 23 | counterObject = counterGenerator.next(); 24 | console.log(counterObject); 25 | } 26 | 27 | console.log("All done!"); 28 | -------------------------------------------------------------------------------- /026-generators/video-examples/return.js: -------------------------------------------------------------------------------- 1 | const counter = function* () { 2 | // pause here and return the generator 3 | yield 1; 4 | yield 2; 5 | return; 6 | yield 3; 7 | }; 8 | 9 | console.log(counter); 10 | 11 | const counterGenerator = counter(); 12 | // const counterGenerator2 = counter(); 13 | console.log(counterGenerator); 14 | 15 | for (const value of counterGenerator) { 16 | console.log(value); 17 | } 18 | 19 | console.log(counterGenerator.next()); 20 | -------------------------------------------------------------------------------- /027-async-generators/exercises/exercise-1.js: -------------------------------------------------------------------------------- 1 | /* 2 | 1. Create an async Generator function that has a 50% 3 | chance of yielding either of the following Promises: 4 | - Resolve after 500ms with the value "Fast!" 5 | - Resolve after 3000ms with the value "Slow!" 6 | 7 | 2. Create the generator object by calling the function ^ 8 | 9 | 3. Use a for-await-of loop to loop through the generator 10 | indefinitely (ctrl-c to force exit the program) 11 | 12 | *HINT: Math.random() is your friend 13 | */ 14 | -------------------------------------------------------------------------------- /027-async-generators/exercises/exercise-2.js: -------------------------------------------------------------------------------- 1 | /* 2 | 1. Create an async Generator function that has a single 3 | parameter called "sentence". The function will loop through 4 | "sentence" letter by letter, and for each letter it will 5 | yield a Promise that resolves after 100ms that: 6 | - If the letter is a vowel (aeiou) then resolve with a "*" 7 | - Otherwise resolve with the letter, but uppercased 8 | 9 | 2. Create the generator object by calling the function ^ 10 | with a value of "Monkeys are the coolest animal!" 11 | 12 | 3. Use a for-await-of loop to loop through the generator 13 | 14 | *There are MANY ways to check if a string has any of several letters 15 | */ 16 | -------------------------------------------------------------------------------- /027-async-generators/exercises/exercise-3.js: -------------------------------------------------------------------------------- 1 | /* 2 | 1. Create an async Generator function that has a single 3 | parameter called "time". This function will yield a 4 | Promise that resolves with the time taken after that 5 | many milliseconds. The time for each subsequent Promise 6 | will take TWICE as long. 7 | 8 | 2. Create the generator object by calling the function ^ 9 | with the value 100 to start. 10 | 11 | 3. Use a for-await-of loop to loop through the generator 12 | indefinitely (ctrl-c to force exit the program) 13 | 14 | 4. Example output if we started with: 15 | const timeGeneratorObject = timeGenerator(100) 16 | for await (const time of timeGeneratorObject) 17 | - ^ If we logged "time" each loop we'd get: 18 | - 100, 200, 400, 800, 1600, 3200 ... etc 19 | */ 20 | -------------------------------------------------------------------------------- /027-async-generators/exercises/warmup-exercise.js: -------------------------------------------------------------------------------- 1 | /* 2 | 1. Create an async Generator function that will yield 3 | a Promise that resolves after 1 second with a random 4 | number between 0-9 (integer and inclusive) 5 | 6 | 2. Create the generator object by calling the function ^ 7 | 8 | 3. Use a for-await-of loop to loop through the generator 9 | indefinitely (ctrl-c to force exit the program) 10 | */ 11 | -------------------------------------------------------------------------------- /027-async-generators/video-examples/async.js: -------------------------------------------------------------------------------- 1 | const asyncGenerator = async function* () { 2 | yield new Promise((resolve, reject) => { 3 | setTimeout(() => { 4 | resolve(1); 5 | }, 1000); 6 | }); 7 | }; 8 | 9 | const asyncGeneratorObject = asyncGenerator(); 10 | 11 | console.log(asyncGenerator); 12 | console.log(asyncGeneratorObject); 13 | 14 | const asyncGeneratorExecuter = async () => { 15 | for await (const promise of asyncGeneratorObject) { 16 | console.log(promise); 17 | } 18 | }; 19 | 20 | asyncGeneratorExecuter(); 21 | -------------------------------------------------------------------------------- /027-async-generators/video-examples/infinite.js: -------------------------------------------------------------------------------- 1 | const asyncGenerator = async function* () { 2 | let i = 0; 3 | while (true) { 4 | yield new Promise((resolve, reject) => { 5 | setTimeout(() => { 6 | resolve(i); 7 | }, 1000); 8 | }); 9 | i++; 10 | yield* [1, 2, 3]; 11 | } 12 | }; 13 | 14 | const asyncGeneratorObject = asyncGenerator(); 15 | 16 | console.log(asyncGenerator); 17 | console.log(asyncGeneratorObject); 18 | 19 | const asyncStarter = async () => { 20 | for await (const number of asyncGeneratorObject) { 21 | console.log(number); 22 | } 23 | }; 24 | 25 | asyncStarter(); 26 | console.log("Hello???"); 27 | -------------------------------------------------------------------------------- /028-symbols/exercise-solutions/warmup-exercise.js: -------------------------------------------------------------------------------- 1 | /* 2 | 1. Create a variable called "baboon" that points to a Symbol 3 | with a description of "Monkey" 4 | 5 | 2. Create a variable called "gorilla" that points to a Symbol 6 | with a description of "Monkey" as well 7 | 8 | 3. Print out the types of each of the symbols as well as their 9 | description property 10 | 11 | 4. Are the two symbols equivalent? (Equality check) 12 | Why or why not? 13 | */ 14 | 15 | const baboon = Symbol("Monkey"); 16 | const gorilla = Symbol("Monkey"); 17 | 18 | console.log(typeof baboon); 19 | console.log(typeof gorilla); 20 | 21 | console.log(baboon.description); 22 | console.log(gorilla.description); 23 | 24 | console.log(baboon === gorilla); 25 | -------------------------------------------------------------------------------- /028-symbols/exercises/exercise-1.js: -------------------------------------------------------------------------------- 1 | /* 2 | 1. Create a variable "movie" that points at this Object: 3 | { name: "Blade Runner", director: "Ridley Scott", 4 | year: 1982, rating: 89, genre: "Science Fiction" } 5 | 6 | 2. Add the two more properties to the "movie" Object: 7 | [Symbol("budget")]: 30 8 | [Symbol("boxOffice")]: 41.6 9 | 10 | 3. Use a for-of loop to loop through all the entries inside 11 | "movie" and print out their key-value pairs: 12 | Eg: name => Blade Runner, director => Ridley Scott 13 | 14 | 4. How would you access and print out the symbols in "movie"? 15 | */ 16 | -------------------------------------------------------------------------------- /028-symbols/exercises/exercise-2.js: -------------------------------------------------------------------------------- 1 | /* 2 | 1. Create a variable "book" that points at this Object: 3 | { name: "1984", author: "George Orwell", year: 1949, 4 | rating: 4.6, genre: "Science Fiction", movie: true } 5 | 6 | 2. Create a Symbol.iterator property on "book" that will 7 | allow you to loop over it using a for-of-loop that will 8 | give you back the key-value pairs each loop as a paired 9 | array (similar to a Map): ["name", "1984"] ["rating", 4.6] 10 | 11 | 3. Test your loop with a for-of-loop to make sure it works 12 | 13 | HINT: A generator function is the easiest way to do this 14 | */ 15 | -------------------------------------------------------------------------------- /028-symbols/exercises/exercise-3.js: -------------------------------------------------------------------------------- 1 | /* 2 | 1. Create a variable "book" that points at this Object: 3 | { name: "1984", author: "George Orwell", year: 1949, 4 | rating: 4.6, genre: "Science Fiction", movie: true } 5 | 6 | 2. Create a Symbol.asyncIterator property on "book" that 7 | will allow you to loop over it using a for-await-of-loop 8 | that will give you back the key-value pairs each loop but 9 | delayed by 1 second each as a paired array 10 | (similar to a Map): ["name", "1984"] ["rating", 4.6] 11 | 12 | 3. Test your loop with a for-await-of-loop to make sure it works 13 | 14 | HINT: An async generator function is the easiest way to do this 15 | */ 16 | -------------------------------------------------------------------------------- /028-symbols/exercises/warmup-exercise.js: -------------------------------------------------------------------------------- 1 | /* 2 | 1. Create a variable called "baboon" that points to a Symbol 3 | with a description of "Monkey" 4 | 5 | 2. Create a variable called "gorilla" that points to a Symbol 6 | with a description of "Monkey" as well 7 | 8 | 3. Print out the types of each of the symbols as well as their 9 | description property 10 | 11 | 4. Are the two symbols equivalent? (Equality check) 12 | Why or why not? 13 | */ 14 | -------------------------------------------------------------------------------- /028-symbols/video-examples/admin.js: -------------------------------------------------------------------------------- 1 | const character = { 2 | name: "Rick Axley", 3 | class: "Axe Wielder", 4 | quote: "I'll never let you down", 5 | __admin__: false, 6 | }; 7 | 8 | for (const key of Object.keys(character)) { 9 | console.log(key); 10 | } 11 | -------------------------------------------------------------------------------- /028-symbols/video-examples/intro.js: -------------------------------------------------------------------------------- 1 | const mySymbol = Symbol(); 2 | const namedSymbol = Symbol("monkey"); 3 | 4 | console.log(mySymbol); 5 | console.log(namedSymbol); 6 | 7 | console.log(typeof mySymbol); 8 | console.log(typeof namedSymbol); 9 | console.log(typeof "hello"); 10 | 11 | console.log(Symbol() === mySymbol); 12 | console.log(Symbol("monkey") === namedSymbol); 13 | console.log(mySymbol === mySymbol); 14 | console.log(mySymbol.description); 15 | console.log(namedSymbol.description); 16 | -------------------------------------------------------------------------------- /028-symbols/video-examples/iterator.js: -------------------------------------------------------------------------------- 1 | const character = { 2 | name: "Rick Axley", 3 | class: "Axe Wielder", 4 | quote: "I'll never let you down", 5 | __admin__: false, 6 | [Symbol.iterator]: function* () { 7 | yield 1; 8 | yield 2; 9 | yield "hello"; 10 | }, 11 | }; 12 | 13 | for (const value of character) { 14 | console.log(value); 15 | } 16 | -------------------------------------------------------------------------------- /028-symbols/video-examples/symbol.js: -------------------------------------------------------------------------------- 1 | const character = { 2 | name: "Rick Axley", 3 | class: "Axe Wielder", 4 | quote: "I'll never let you down", 5 | [Symbol("name")]: false, 6 | [Symbol("age")]: 10, 7 | [4 + 5]: "age", 8 | }; 9 | 10 | for (const key of Object.keys(character)) { 11 | console.log(key); 12 | } 13 | 14 | console.log(Object.getOwnPropertySymbols(character)); 15 | -------------------------------------------------------------------------------- /029-regular-expressions/exercise-solutions/exercise-1.js: -------------------------------------------------------------------------------- 1 | /* 2 | 1. Create a variable called "email" that points at: 3 | "monkey@trees.com" 4 | 5 | 2. Create a variable called "emailPattern" that is 6 | a regular expression that will look for a string 7 | that ENDS with ".com" 8 | 9 | 3. Test "email" against "emailPattern" to see if 10 | it returns true/false using .test on "emailPattern" 11 | 12 | 4. Find a match using .match on "email" with the 13 | "emailPattern regex" 14 | 15 | 5. Print out the results from 3 and 4. 16 | 17 | BONUS: What is an issue with this pattern? 18 | */ 19 | 20 | const email = "monkey@tree.com"; 21 | 22 | const emailPattern = /\.com$/; 23 | 24 | const test = emailPattern.test(email); 25 | console.log(test); 26 | 27 | const match = email.match(emailPattern); 28 | console.log(match); 29 | -------------------------------------------------------------------------------- /029-regular-expressions/exercise-solutions/warmup-exercise.js: -------------------------------------------------------------------------------- 1 | /* 2 | 1. Create a variable called "quote" that points at: 3 | "What is this? A center for ants?" 4 | 5 | 2. Create a variable called "pattern" that points at 6 | a regular expression to search for "ant" in a string 7 | 8 | 3. Use the .test method on the "pattern" in step 9 | 2 to check if "quote" has the pattern in it 10 | 11 | 4. Use the .match method on the "quote" string to return 12 | a match for the "pattern" regexp 13 | 14 | 5. Print out the results from steps 3 and 4 15 | */ 16 | 17 | const quote = "What is this? A center for ants?"; 18 | 19 | const pattern = /ant/; 20 | 21 | const test = pattern.test(quote); 22 | console.log(test); 23 | 24 | const match = quote.match(pattern); 25 | console.log(match); 26 | -------------------------------------------------------------------------------- /029-regular-expressions/exercises/exercise-1.js: -------------------------------------------------------------------------------- 1 | /* 2 | 1. Create a variable called "email" that points at: 3 | "monkey@trees.com" 4 | 5 | 2. Create a variable called "emailPattern" that is 6 | a regular expression that will look for a string 7 | that ENDS with ".com" 8 | 9 | 3. Test "email" against "emailPattern" to see if 10 | it returns true/false using .test on "emailPattern" 11 | 12 | 4. Find a match using .match on "email" with the 13 | "emailPattern regex" 14 | 15 | 5. Print out the results from 3 and 4. 16 | 17 | BONUS: What is an issue with this pattern? 18 | */ 19 | -------------------------------------------------------------------------------- /029-regular-expressions/exercises/exercise-2.js: -------------------------------------------------------------------------------- 1 | /* 2 | *Building on exercise 2 3 | 4 | 1. Create a variable called "email" that points at: 5 | "monkey@trees.com" 6 | 7 | 2. Create a variable called "emailPattern" that is 8 | a regular expression that will look for a string 9 | that ENDS with ".com" AND has ANY number of letters 10 | followed by the '@' char followed by ANY number of 11 | letters and ending with the "".com" 12 | 13 | 3. Test "email" against "emailPattern" to see if 14 | it returns true/false using .test on "emailPattern" 15 | 16 | 4. Find a match using .match on "email" with the 17 | "emailPattern regex" 18 | 19 | 5. Print out the results from 3 and 4. 20 | 21 | BONUS: What is an issue with this pattern? 22 | */ 23 | -------------------------------------------------------------------------------- /029-regular-expressions/exercises/exercise-3.js: -------------------------------------------------------------------------------- 1 | /* 2 | 1. Create a variable called "phoneNumber" that points at: 3 | the string: "020-382-6940" 4 | 5 | 2. Create a regular expression called "phonePattern" that 6 | is a regular expression that would match a phone number 7 | with the format above in "phoneNumber" (including dashes) 8 | 9 | 3. Test "phoneNumber" against "phonePattern" to see if 10 | it returns true/false using .test on "phonePattern" 11 | 12 | 4. Find a match using .match on "phoneNumber" with the 13 | "phonePattern regex" 14 | 15 | 5. Print out the results from 3 and 4. 16 | 17 | BONUS: What is an issue with this pattern? 18 | */ 19 | -------------------------------------------------------------------------------- /029-regular-expressions/exercises/warmup-exercise.js: -------------------------------------------------------------------------------- 1 | /* 2 | 1. Create a variable called "quote" that points at: 3 | "What is this? A center for ants?" 4 | 5 | 2. Create a variable called "pattern" that points at 6 | a regular expression to search for "ant" in a string 7 | 8 | 3. Use the .test method on the "pattern" in step 9 | 2 to check if "quote" has the pattern in it 10 | 11 | 4. Use the .match method on the "quote" string to return 12 | a match for the "pattern" regexp 13 | 14 | 5. Print out the results from steps 3 and 4 15 | */ 16 | -------------------------------------------------------------------------------- /029-regular-expressions/video-examples/intro.js: -------------------------------------------------------------------------------- 1 | const sentence = "There once was a monkey who knew Javascript..."; 2 | 3 | const pattern = /\.\.\./; 4 | 5 | const test = pattern.test(sentence); 6 | console.log(test); 7 | 8 | const match = sentence.match(pattern); 9 | console.log(match); 10 | -------------------------------------------------------------------------------- /030-modules/exercise-solutions/exercise1/main.js: -------------------------------------------------------------------------------- 1 | import myGreeting, { square as sq } from "./utils.js"; 2 | 3 | const num = sq(20); 4 | 5 | console.log(num); 6 | 7 | myGreeting("monkey"); 8 | -------------------------------------------------------------------------------- /030-modules/exercise-solutions/exercise1/package.json: -------------------------------------------------------------------------------- 1 | { 2 | "type": "module" 3 | } -------------------------------------------------------------------------------- /030-modules/exercise-solutions/exercise1/utils.js: -------------------------------------------------------------------------------- 1 | const square = (number) => { 2 | return number * number; 3 | }; 4 | 5 | const greeting = (name) => { 6 | console.log(`Hello ${name}!`); 7 | }; 8 | 9 | export { square }; 10 | export default greeting; 11 | -------------------------------------------------------------------------------- /030-modules/exercise-solutions/exercise2/main.js: -------------------------------------------------------------------------------- 1 | import { checkMovie, topMovies } from "./modules.js"; 2 | 3 | console.log(topMovies); 4 | 5 | console.log(checkMovie("Jurrasic Park")); 6 | console.log(checkMovie("Zoolander")); 7 | -------------------------------------------------------------------------------- /030-modules/exercise-solutions/exercise2/moduleA.js: -------------------------------------------------------------------------------- 1 | import { topMovies } from "./moduleB.js"; 2 | 3 | const checkMovie = (movieName) => { 4 | return topMovies.includes(movieName); 5 | }; 6 | 7 | export { checkMovie }; 8 | -------------------------------------------------------------------------------- /030-modules/exercise-solutions/exercise2/moduleB.js: -------------------------------------------------------------------------------- 1 | const topMovies = ["Spirited Away", "The Matrix", "Star Wars", "Zoolander"]; 2 | 3 | export { topMovies }; 4 | -------------------------------------------------------------------------------- /030-modules/exercise-solutions/exercise2/modules.js: -------------------------------------------------------------------------------- 1 | // import { checkMovie } from "./moduleA.js"; 2 | // import { topMovies } from "./moduleB.js"; 3 | 4 | // export { checkMovie, topMovies }; 5 | 6 | export { checkMovie } from "./moduleA.js"; 7 | export { topMovies } from "./moduleB.js"; 8 | -------------------------------------------------------------------------------- /030-modules/exercise-solutions/exercise2/package.json: -------------------------------------------------------------------------------- 1 | { 2 | "type": "module" 3 | } -------------------------------------------------------------------------------- /030-modules/exercise-solutions/exercise3/main.js: -------------------------------------------------------------------------------- 1 | import { b } from "./moduleB.js"; 2 | 3 | console.log("MAIN"); 4 | -------------------------------------------------------------------------------- /030-modules/exercise-solutions/exercise3/moduleA.js: -------------------------------------------------------------------------------- 1 | console.log("Module A"); 2 | 3 | const a = "A"; 4 | 5 | export { a }; 6 | -------------------------------------------------------------------------------- /030-modules/exercise-solutions/exercise3/moduleB.js: -------------------------------------------------------------------------------- 1 | import { a } from "./moduleA.js"; 2 | 3 | console.log("Module B"); 4 | 5 | const b = "B"; 6 | 7 | export { b }; 8 | -------------------------------------------------------------------------------- /030-modules/exercise-solutions/exercise3/package.json: -------------------------------------------------------------------------------- 1 | { 2 | "type": "module" 3 | } -------------------------------------------------------------------------------- /030-modules/exercise-solutions/warmup-exercise.js: -------------------------------------------------------------------------------- 1 | /* 2 | 1. Create a new folder called "warmup" 3 | 2. Inside of "warmup" create 2 files: 4 | - main.js 5 | - utils.js 6 | 7 | 3. Inside of utils.js create a function called "capsLock" 8 | that takes a single parameter called "string" and RETURNS 9 | "string", but upper-cased 10 | 11 | 4. Export "capsLock" as a NAMED export from utils.js 12 | 13 | 5. Import "capsLock" inside main.js and call it with 14 | any string as an argument, then print the result. 15 | Run main.js using Node. 16 | 17 | HINT: Make sure to make a package.json file inside of 18 | "warmup" with this inside: { "type": "module" } 19 | */ 20 | -------------------------------------------------------------------------------- /030-modules/exercise-solutions/warmup/main.js: -------------------------------------------------------------------------------- 1 | import { capsLock } from "./utils.js"; 2 | 3 | const caps = capsLock("hello there!"); 4 | 5 | console.log(caps); 6 | -------------------------------------------------------------------------------- /030-modules/exercise-solutions/warmup/package.json: -------------------------------------------------------------------------------- 1 | { 2 | "type": "module" 3 | } -------------------------------------------------------------------------------- /030-modules/exercise-solutions/warmup/utils.js: -------------------------------------------------------------------------------- 1 | const capsLock = (string) => { 2 | return string.toUpperCase(); 3 | }; 4 | 5 | // capsLock('hi') => 'HI' 6 | 7 | export { capsLock }; 8 | -------------------------------------------------------------------------------- /030-modules/exercises/warmup-exercise.js: -------------------------------------------------------------------------------- 1 | /* 2 | 1. Create a new folder called "warmup" 3 | 2. Inside of "warmup" create 2 files: 4 | - main.js 5 | - utils.js 6 | 7 | 3. Inside of utils.js create a function called "capsLock" 8 | that takes a single parameter called "string" and RETURNS 9 | "string", but upper-cased 10 | 11 | 4. Export "capsLock" as a NAMED export from utils.js 12 | 13 | 5. Import "capsLock" inside main.js and call it with 14 | any string as an argument, then print the result. 15 | Run main.js using Node. 16 | 17 | HINT: Make sure to make a package.json file inside of 18 | "warmup" with this inside: { "type": "module" } 19 | */ 20 | -------------------------------------------------------------------------------- /030-modules/video-examples/async-jungle.js: -------------------------------------------------------------------------------- 1 | import { awaitedMonkey } from "./monkey.js"; 2 | 3 | console.log("Welcome to the jungle!"); 4 | console.log(awaitedMonkey); 5 | -------------------------------------------------------------------------------- /030-modules/video-examples/jungle.js: -------------------------------------------------------------------------------- 1 | // import { printMonkey as PM } from "./monkey.js"; // es modules 2 | // import PM, { monkey, tiger } from "./monkey.js"; 3 | // const printMonkey = require("monkey.js"); // commonjs 4 | // import * as Everything from "./monkey.js"; 5 | 6 | // console.log(monkey); 7 | // PM(); 8 | // console.log(monkey); 9 | // console.log(tiger); 10 | 11 | console.log(Everything); 12 | 13 | Everything.default(); 14 | 15 | console.log(Everything.monkey); 16 | console.log(Everything.tiger); 17 | 18 | await Promise.resolve(2); 19 | -------------------------------------------------------------------------------- /030-modules/video-examples/monkey.js: -------------------------------------------------------------------------------- 1 | const monkey = { 2 | name: "Abu", 3 | species: "Capuchin", 4 | hobbies: ["stealing"], 5 | age: 10, 6 | }; 7 | 8 | const tiger = "Rajah"; 9 | 10 | const printMonkey = () => { 11 | return new Promise((resolve, reject) => { 12 | setTimeout(() => { 13 | monkey.age++; 14 | console.log(monkey); 15 | resolve(monkey); 16 | }, 2000); 17 | }); 18 | }; 19 | 20 | console.log("hello????"); 21 | 22 | const awaitedMonkey = await printMonkey(); 23 | 24 | export { awaitedMonkey }; 25 | export default printMonkey; 26 | -------------------------------------------------------------------------------- /030-modules/video-examples/package.json: -------------------------------------------------------------------------------- 1 | { 2 | "type": "module" 3 | } -------------------------------------------------------------------------------- /031-npm/exercise-solutions/exercise-1.js: -------------------------------------------------------------------------------- 1 | /* 2 | 1. Create a folder for this exercise called 'exercise1' 3 | 2. Inside 'exercise1' run 'npm init' to create a default 4 | package.json file (press enter to skip answers) 5 | 3. Add "type": "module" to the package.json so we can 6 | use es modules (import/export) 7 | 8 | 4. Use NPM to install the "chalk" package 9 | 5. Create a file called "main.js" and import chalk 10 | (refer to the npm page or the docs as to how) 11 | 6. Use chalk to print out some Strings in different colours 12 | like blue and red. 13 | 7. Use node to run "main.js" 14 | 15 | *BONUS: What dependencies does chalk rely on? 16 | Where would you find this info ^? 17 | */ 18 | -------------------------------------------------------------------------------- /031-npm/exercise-solutions/exercise-2.js: -------------------------------------------------------------------------------- 1 | /* 2 | 1. Create a folder for this exercise called 'exercise2' 3 | 2. Inside 'exercise2' run 'npm init' to create a default 4 | package.json file (press enter to skip answers) 5 | 6 | 3. Use NPM to install the "fs-extra" package 7 | 4. Create a file called "main.js" and import fs-extra 8 | (refer to the npm page or the docs as to how) 9 | NOTE: This package uses the CommonJS syntax, NOT ES Modules 10 | 6. Use fs-extra to create a text file in the current directory 11 | with the text "Hello, from NodeJS!" "hello.txt" 12 | 7. Use node to run "main.js" 13 | 14 | *BONUS: What are the other functions fs-extra has that might 15 | be useful? 16 | */ 17 | -------------------------------------------------------------------------------- /031-npm/exercise-solutions/exercise1/main.js: -------------------------------------------------------------------------------- 1 | import chalk from "chalk"; 2 | 3 | const blueString = chalk.green("Omg, is this really blue?"); 4 | console.log(blueString); 5 | -------------------------------------------------------------------------------- /031-npm/exercise-solutions/exercise1/package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "exercise1", 3 | "version": "1.0.0", 4 | "description": "", 5 | "main": "index.js", 6 | "scripts": { 7 | "test": "echo \"Error: no test specified\" && exit 1" 8 | }, 9 | "keywords": [], 10 | "author": "", 11 | "license": "ISC", 12 | "type": "module", 13 | "dependencies": { 14 | "chalk": "^5.1.2" 15 | } 16 | } 17 | -------------------------------------------------------------------------------- /031-npm/exercise-solutions/exercise2/hello.txt: -------------------------------------------------------------------------------- 1 | Hello, from NodeJS! -------------------------------------------------------------------------------- /031-npm/exercise-solutions/exercise2/main.js: -------------------------------------------------------------------------------- 1 | const fs = require("fs-extra"); // CommonJS 2 | // import fs from 'fs-extra'; 3 | 4 | const file = "hello.txt"; 5 | 6 | fs.outputFileSync(file, "Hello, from NodeJS!"); 7 | -------------------------------------------------------------------------------- /031-npm/exercise-solutions/exercise2/package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "exercise2", 3 | "version": "1.0.0", 4 | "description": "", 5 | "main": "index.js", 6 | "scripts": { 7 | "test": "echo \"Error: no test specified\" && exit 1" 8 | }, 9 | "keywords": [], 10 | "author": "", 11 | "license": "ISC", 12 | "dependencies": { 13 | "fs-extra": "^10.1.0" 14 | } 15 | } 16 | -------------------------------------------------------------------------------- /031-npm/exercise-solutions/exercise3/hello.js: -------------------------------------------------------------------------------- 1 | import { Command } from "commander"; 2 | const program = new Command(); 3 | 4 | program.option("-n, --name ", "your name"); 5 | program.parse(); 6 | 7 | const options = program.opts(); 8 | 9 | // console.log(options); 10 | // console.log(options.name); 11 | 12 | console.log(`Hello, ${options.name}!`); 13 | -------------------------------------------------------------------------------- /031-npm/exercise-solutions/exercise3/package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "exercise3", 3 | "version": "1.0.0", 4 | "description": "", 5 | "main": "index.js", 6 | "scripts": { 7 | "test": "echo \"Error: no test specified\" && exit 1" 8 | }, 9 | "keywords": [], 10 | "author": "", 11 | "license": "ISC", 12 | "dependencies": { 13 | "commander": "^9.4.1" 14 | }, 15 | "type": "module" 16 | } 17 | -------------------------------------------------------------------------------- /031-npm/exercise-solutions/warmup-exercise.js: -------------------------------------------------------------------------------- 1 | /* 2 | 1. Create a folder for this exercise called 'warmup' 3 | 2. Inside 'warmup' run 'npm init' to create a default 4 | package.json file (press enter to skip answers) 5 | 3. Add "type": "module" to the package.json so we can 6 | use es modules (import/export) 7 | 8 | 4. Use NPM to install the "lodash-es" package 9 | 5. Create a file called "main.js" and import "camelCase" 10 | from lodash-es 11 | 6. Use the function on the String "I love Javascript!" to 12 | test if it works and print it out 13 | 7. Use node to run "main.js" 14 | 15 | *BONUS: Find the camelCase function/file inside of 16 | node_modules and read through it 17 | */ 18 | -------------------------------------------------------------------------------- /031-npm/exercise-solutions/warmup/main.js: -------------------------------------------------------------------------------- 1 | import { camelCase } from "lodash-es"; 2 | 3 | const result = camelCase("I love Javascript!"); 4 | console.log(result); 5 | -------------------------------------------------------------------------------- /031-npm/exercise-solutions/warmup/package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "warmup", 3 | "version": "1.0.0", 4 | "description": "", 5 | "main": "index.js", 6 | "scripts": { 7 | "test": "echo \"Error: no test specified\" && exit 1" 8 | }, 9 | "author": "", 10 | "license": "ISC", 11 | "type": "module", 12 | "dependencies": { 13 | "lodash-es": "^4.17.21" 14 | } 15 | } 16 | -------------------------------------------------------------------------------- /031-npm/exercises/exercise-1.js: -------------------------------------------------------------------------------- 1 | /* 2 | 1. Create a folder for this exercise called 'exercise1' 3 | 2. Inside 'exercise1' run 'npm init' to create a default 4 | package.json file (press enter to skip answers) 5 | 3. Add "type": "module" to the package.json so we can 6 | use es modules (import/export) 7 | 8 | 4. Use NPM to install the "chalk" package 9 | 5. Create a file called "main.js" and import chalk 10 | (refer to the npm page or the docs as to how) 11 | 6. Use chalk to print out some Strings in different colours 12 | like blue and red. 13 | 7. Use node to run "main.js" 14 | 15 | *BONUS: What dependencies does chalk rely on? 16 | Where would you find this info ^? 17 | */ 18 | -------------------------------------------------------------------------------- /031-npm/exercises/exercise-2.js: -------------------------------------------------------------------------------- 1 | /* 2 | 1. Create a folder for this exercise called 'exercise2' 3 | 2. Inside 'exercise2' run 'npm init' to create a default 4 | package.json file (press enter to skip answers) 5 | 6 | 3. Use NPM to install the "fs-extra" package 7 | 4. Create a file called "main.js" and import fs-extra 8 | (refer to the npm page or the docs as to how) 9 | NOTE: This package uses the CommonJS syntax, NOT ES Modules 10 | 6. Use fs-extra to create a text file in the current directory 11 | with the text "Hello, from NodeJS!" "hello.txt" 12 | 7. Use node to run "main.js" 13 | 14 | *BONUS: What are the other functions fs-extra has that might 15 | be useful? 16 | */ 17 | -------------------------------------------------------------------------------- /031-npm/exercises/exercise-3.js: -------------------------------------------------------------------------------- 1 | /* 2 | 1. Create a folder for this exercise called 'exercise3' 3 | 2. Inside 'exercise3' run 'npm init' to create a default 4 | package.json file (press enter to skip answers) 5 | 3. Add "type": "module" to the package.json so we can 6 | use es modules (import/export) 7 | 8 | 4. Use NPM to install the "commander" package 9 | 5. Create a file called "hello.js" and import { program } 10 | from commander (refer to the npm page or the docs as to how) 11 | 6. Write code to allow us to run: node hello.js -n monkey 12 | Which will output: Hello, monkey! 13 | (-n will be a flag for the "name" argument which can be any 14 | single user-provided word) 15 | 16 | *This is challenging and requires a lot of trial and error and back 17 | and forth on NPM's website and this package's examples/docs 18 | */ 19 | -------------------------------------------------------------------------------- /031-npm/exercises/warmup-exercise.js: -------------------------------------------------------------------------------- 1 | /* 2 | 1. Create a folder for this exercise called 'warmup' 3 | 2. Inside 'warmup' run 'npm init' to create a default 4 | package.json file (press enter to skip answers) 5 | 3. Add "type": "module" to the package.json so we can 6 | use es modules (import/export) 7 | 8 | 4. Use NPM to install the "lodash-es" package 9 | 5. Create a file called "main.js" and import "camelCase" 10 | from lodash-es 11 | 6. Use the function on the String "I love Javascript!" to 12 | test if it works and print it out 13 | 7. Use node to run "main.js" 14 | 15 | *BONUS: Find the camelCase function/file inside of 16 | node_modules and read through it 17 | */ 18 | -------------------------------------------------------------------------------- /031-npm/video-examples/main.js: -------------------------------------------------------------------------------- 1 | import { head } from "lodash-es"; 2 | 3 | const first = head([1, 2, 3, 4, 5]); 4 | console.log(first); 5 | -------------------------------------------------------------------------------- /031-npm/video-examples/package-lock.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "code", 3 | "lockfileVersion": 2, 4 | "requires": true, 5 | "packages": {} 6 | } 7 | -------------------------------------------------------------------------------- /031-npm/video-examples/package.json: -------------------------------------------------------------------------------- 1 | { 2 | "type": "module", 3 | "scripts": { 4 | "list": "ls", 5 | "hello": "echo 'hello there! :)'" 6 | } 7 | } 8 | -------------------------------------------------------------------------------- /031-npm/video-examples/utilities/package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "utilities", 3 | "version": "1.0.0", 4 | "description": "", 5 | "main": "util.js", 6 | "scripts": { 7 | "test": "echo \"Error: no test specified\" && exit 1" 8 | }, 9 | "author": "", 10 | "license": "ISC", 11 | "type": "module" 12 | } 13 | -------------------------------------------------------------------------------- /031-npm/video-examples/utilities/util.js: -------------------------------------------------------------------------------- 1 | import { head } from "lodash-es"; 2 | 3 | console.log(head); 4 | -------------------------------------------------------------------------------- /032-fetch-api/exercise-solutions/exercise-1.js: -------------------------------------------------------------------------------- 1 | /* 2 | 1. Install node-fetch if your Node version is less than 18 3 | using NPM, and import it in to your file (ES Module style) 4 | 5 | 2. Make a request to: 6 | https://jsonplaceholder.typicode.com/posts/1 7 | and print out the resulting JSON using Fetch 8 | 9 | BONUS: How does this differ from text content and what might 10 | fetch be doing with the JSON response for us? 11 | */ 12 | 13 | import fetch from "node-fetch"; 14 | 15 | fetch("https://jsonplaceholder.typicode.com/posts/1") 16 | .then((response) => response.json()) 17 | .then((result) => { 18 | console.log(typeof result); 19 | console.log(result); 20 | console.log(result.title); 21 | // result.userId 22 | }); 23 | -------------------------------------------------------------------------------- /032-fetch-api/exercise-solutions/exercise-2.js: -------------------------------------------------------------------------------- 1 | /* 2 | 1. Install node-fetch if your Node version is less than 18 3 | using NPM, and import it in to your file (ES Module style) 4 | 5 | 2. Have a read through pokeapi.co 6 | 7 | 2. Make a request to: 8 | https://pokeapi.co/api/v2/pokemon/pikachu 9 | and print out pikachu's "official-artwork"'s URL for 10 | their image (png). Visit this URL to make sure it works 11 | using your Browser. 12 | 13 | HINT: Be careful with the naming of the keys here when trying 14 | to access the parsed JSON 15 | */ 16 | 17 | import fetch from "node-fetch"; 18 | 19 | fetch("https://pokeapi.co/api/v2/pokemon/pikachu") 20 | .then((response) => response.json()) 21 | .then((pokemonObject) => { 22 | console.log(pokemonObject.sprites.other["official-artwork"].front_default); 23 | }); 24 | -------------------------------------------------------------------------------- /032-fetch-api/exercise-solutions/package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "code", 3 | "version": "1.0.0", 4 | "description": "", 5 | "main": "exercise-1.js", 6 | "scripts": { 7 | "test": "echo \"Error: no test specified\" && exit 1" 8 | }, 9 | "keywords": [], 10 | "author": "", 11 | "license": "ISC", 12 | "type": "module", 13 | "dependencies": { 14 | "node-fetch": "^3.3.0" 15 | } 16 | } 17 | -------------------------------------------------------------------------------- /032-fetch-api/exercise-solutions/warmup-exercise.js: -------------------------------------------------------------------------------- 1 | /* 2 | 1. Install node-fetch if your Node version is less than 18 3 | using NPM, and import it in to your file (ES Module style) 4 | 5 | 2. Make a request to: https://www.craigslist.org/about/ 6 | and print out the resulting HTML (text) String, using Fetch 7 | 3. Compare what you see in Node to visiting the actual page in 8 | your Browser - what matches up? 9 | */ 10 | 11 | import fetch from "node-fetch"; 12 | 13 | fetch("https://www.craigslist.org/about/") 14 | .then((response) => { 15 | return response.text(); 16 | }) 17 | .then((html) => { 18 | console.log(html); 19 | }); 20 | -------------------------------------------------------------------------------- /032-fetch-api/exercises/exercise-1.js: -------------------------------------------------------------------------------- 1 | /* 2 | 1. Install node-fetch if your Node version is less than 18 3 | using NPM, and import it in to your file (ES Module style) 4 | 5 | 2. Make a request to: 6 | https://jsonplaceholder.typicode.com/posts/1 7 | and print out the resulting JSON using Fetch 8 | 9 | BONUS: How does this differ from text content and what might 10 | fetch be doing with the JSON response for us? 11 | */ 12 | -------------------------------------------------------------------------------- /032-fetch-api/exercises/exercise-2.js: -------------------------------------------------------------------------------- 1 | /* 2 | 1. Install node-fetch if your Node version is less than 18 3 | using NPM, and import it in to your file (ES Module style) 4 | 5 | 2. Have a read through pokeapi.co 6 | 7 | 2. Make a request to: 8 | https://pokeapi.co/api/v2/pokemon/pikachu 9 | and print out pikachu's "official-artwork"'s URL for 10 | their image (png). Visit this URL to make sure it works 11 | using your Browser. 12 | 13 | HINT: Be careful with the naming of the keys here when trying 14 | to access the parsed JSON 15 | */ 16 | -------------------------------------------------------------------------------- /032-fetch-api/exercises/warmup-exercise.js: -------------------------------------------------------------------------------- 1 | /* 2 | 1. Install node-fetch if your Node version is less than 18 3 | using NPM, and import it in to your file (ES Module style) 4 | 5 | 2. Make a request to: https://www.craigslist.org/about/ 6 | and print out the resulting HTML (text) String, using Fetch 7 | 3. Compare what you see in Node to visiting the actual page in 8 | your Browser - what matches up? 9 | */ 10 | -------------------------------------------------------------------------------- /032-fetch-api/video-examples/package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "code", 3 | "version": "1.0.0", 4 | "description": "", 5 | "main": "fetch.js", 6 | "scripts": { 7 | "test": "echo \"Error: no test specified\" && exit 1" 8 | }, 9 | "keywords": [], 10 | "author": "", 11 | "license": "ISC", 12 | "dependencies": { 13 | "node-fetch": "^3.3.0" 14 | }, 15 | "type": "module" 16 | } 17 | -------------------------------------------------------------------------------- /033-Project-2-Pokemon-Downloader-CLI/exercise-solutions/package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "code", 3 | "version": "1.0.0", 4 | "description": "", 5 | "main": "prompts.js", 6 | "scripts": { 7 | "test": "echo \"Error: no test specified\" && exit 1" 8 | }, 9 | "author": "", 10 | "license": "ISC", 11 | "type": "module", 12 | "dependencies": { 13 | "inquirer": "^9.1.4", 14 | "node-fetch": "^3.3.0" 15 | } 16 | } 17 | -------------------------------------------------------------------------------- /033-Project-2-Pokemon-Downloader-CLI/exercise-solutions/pokemon-downloader.js: -------------------------------------------------------------------------------- 1 | import { promptUser } from "./prompts.js"; 2 | 3 | console.log("=== POKEMON DOWNLOADER ==="); 4 | 5 | promptUser(); 6 | -------------------------------------------------------------------------------- /033-Project-2-Pokemon-Downloader-CLI/exercises/advice.js: -------------------------------------------------------------------------------- 1 | /* 2 | General Advice: 3 | 4 | - You will get stuck! Embrace it and treat it as part of the process and learning 5 | - If you get stuck for too long, take a break or try another section of the program 6 | and come back later. 7 | - Google is your friend 8 | - Careful not to copy and paste code off the Internet - write it out yourself again 9 | and make sure you understand each line 10 | - Break down the problems in to smaller sub-problems and solve those as independently 11 | as you can 12 | - Have fun with it! 13 | */ 14 | -------------------------------------------------------------------------------- /033-Project-2-Pokemon-Downloader-CLI/exercises/mew_downloaded.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Nooder/javascript-in-depth/ba8447af2e4edf784606f946da4a682539fa52da/033-Project-2-Pokemon-Downloader-CLI/exercises/mew_downloaded.png -------------------------------------------------------------------------------- /033-Project-2-Pokemon-Downloader-CLI/exercises/pikachu_downloaded.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Nooder/javascript-in-depth/ba8447af2e4edf784606f946da4a682539fa52da/033-Project-2-Pokemon-Downloader-CLI/exercises/pikachu_downloaded.png -------------------------------------------------------------------------------- /033-Project-2-Pokemon-Downloader-CLI/exercises/pokemon-downloader-demo.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Nooder/javascript-in-depth/ba8447af2e4edf784606f946da4a682539fa52da/033-Project-2-Pokemon-Downloader-CLI/exercises/pokemon-downloader-demo.png -------------------------------------------------------------------------------- /033-Project-2-Pokemon-Downloader-CLI/exercises/pre-requisites.js: -------------------------------------------------------------------------------- 1 | /* 2 | Pre-requisites: 3 | 4 | - Variables 5 | - Conditionals 6 | - Loops 7 | - Functions 8 | - Arrays 9 | - Objects 10 | 11 | - Promises 12 | - Async/Await 13 | - ES Modules 14 | - NPM 15 | - Fetch API 16 | 17 | * VSCode and NodeJS 18 | */ 19 | -------------------------------------------------------------------------------- /033-Project-2-Pokemon-Downloader-CLI/exercises/stats_example.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Nooder/javascript-in-depth/ba8447af2e4edf784606f946da4a682539fa52da/033-Project-2-Pokemon-Downloader-CLI/exercises/stats_example.png -------------------------------------------------------------------------------- /033-Project-2-Pokemon-Downloader-CLI/video-examples/advice.js: -------------------------------------------------------------------------------- 1 | /* 2 | General Advice: 3 | 4 | - You will get stuck! Embrace it and treat it as part of the process and learning 5 | - If you get stuck for too long, take a break or try another section of the program 6 | and come back later. 7 | - Google is your friend 8 | - Careful not to copy and paste code off the Internet - write it out yourself again 9 | and make sure you understand each line 10 | - Break down the problems in to smaller sub-problems and solve those as independently 11 | as you can 12 | - Have fun with it! 13 | */ 14 | -------------------------------------------------------------------------------- /033-Project-2-Pokemon-Downloader-CLI/video-examples/mew_downloaded.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Nooder/javascript-in-depth/ba8447af2e4edf784606f946da4a682539fa52da/033-Project-2-Pokemon-Downloader-CLI/video-examples/mew_downloaded.png -------------------------------------------------------------------------------- /033-Project-2-Pokemon-Downloader-CLI/video-examples/pikachu_downloaded.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Nooder/javascript-in-depth/ba8447af2e4edf784606f946da4a682539fa52da/033-Project-2-Pokemon-Downloader-CLI/video-examples/pikachu_downloaded.png -------------------------------------------------------------------------------- /033-Project-2-Pokemon-Downloader-CLI/video-examples/pokemon-downloader-demo.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Nooder/javascript-in-depth/ba8447af2e4edf784606f946da4a682539fa52da/033-Project-2-Pokemon-Downloader-CLI/video-examples/pokemon-downloader-demo.png -------------------------------------------------------------------------------- /033-Project-2-Pokemon-Downloader-CLI/video-examples/pre-requisites.js: -------------------------------------------------------------------------------- 1 | /* 2 | Pre-requisites: 3 | 4 | - Variables 5 | - Conditionals 6 | - Loops 7 | - Functions 8 | - Arrays 9 | - Objects 10 | 11 | - Promises 12 | - Async/Await 13 | - ES Modules 14 | - NPM 15 | - Fetch API 16 | 17 | * VSCode and NodeJS 18 | */ 19 | -------------------------------------------------------------------------------- /033-Project-2-Pokemon-Downloader-CLI/video-examples/stats_example.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Nooder/javascript-in-depth/ba8447af2e4edf784606f946da4a682539fa52da/033-Project-2-Pokemon-Downloader-CLI/video-examples/stats_example.png -------------------------------------------------------------------------------- /034-recursion/exercises/exercise-1.js: -------------------------------------------------------------------------------- 1 | /* 2 | 1. Create a function called "palindrome" that will take 3 | a single String as an argument 4 | 5 | 2. The function will return true if the String is a palindrome 6 | or false if it's not 7 | 8 | 3. A String is a palindrome if it reads the same start-end 9 | as it does end-start 10 | 11 | 4. Examples of palindromes: 12 | - racecar 13 | - level 14 | - mom 15 | - kayak 16 | 17 | 5. Solve this using recursion instead of loops 18 | 19 | HINT: What are the base-cases? (I thought of 4) 20 | */ 21 | -------------------------------------------------------------------------------- /034-recursion/exercises/exercise-2.js: -------------------------------------------------------------------------------- 1 | /* 2 | 1. Create a function called "flatten" that will take 3 | a single Array as an argument 4 | 5 | 2. The function will return a flattened version of the Array 6 | no matter the nested levels 7 | 8 | 3. Solve this using recursion 9 | 10 | Examples: 11 | console.log(flatten([1, 2, 3])); 12 | // [ 1, 2, 3 ] 13 | 14 | console.log(flatten([1, 2, 3, [1, 2, 3]])); 15 | // [ 1, 2, 3, 1, 2, 3 ] 16 | 17 | console.log(flatten([1, [4, 5, 6, [7, 8, 9]], 2, 3])); 18 | // [1, 4, 5, 6, 7,8, 9, 2, 3] 19 | 20 | HINT: Look up "how to check if something is an Array in js" 21 | on Google/MDN 22 | HINT2: What are the base-cases and what do we want to return? 23 | */ 24 | -------------------------------------------------------------------------------- /034-recursion/exercises/warmup-exercise.js: -------------------------------------------------------------------------------- 1 | /* 2 | 1. Create a function called "fizzbuzz" that takes two 3 | number arguments: "startNum" and "endNum" 4 | 2. The function will count from "startNum" to the "endNum" 5 | incrementing by 1 each time and do the following: 6 | 3. If the number is: 7 | - Divisible by 3: Print "Fizz" followed by the number 8 | - Divisible by 5: Print "Buzz" followed by the number 9 | - Divisible by both 3 AND 5: 10 | - Print "FizzBuzz" followed by the number (no fizz or buzz) 11 | - In all other cases, just print the number itself 12 | 13 | 3. You must solve this using recursion 14 | 4. Test it with different start and end values 15 | 16 | HINT: What is the base-case vs the "regular" cases here? 17 | */ 18 | -------------------------------------------------------------------------------- /034-recursion/video-examples/counter.js: -------------------------------------------------------------------------------- 1 | // const counter = (number) => { 2 | // while (number >= 0) { 3 | // console.log(number); 4 | // number--; 5 | // } 6 | // }; 7 | 8 | // counter(7); 9 | 10 | const counter = (number) => { 11 | // check for 0 then stop 12 | console.log(number); 13 | if (number === 0) return; 14 | counter(number - 1); 15 | }; 16 | counter(5); 17 | -------------------------------------------------------------------------------- /034-recursion/video-examples/mine.js: -------------------------------------------------------------------------------- 1 | const mine = { 2 | gold: 3, 3 | left: { 4 | gold: 2, 5 | left: { 6 | gold: 4, 7 | }, 8 | right: { 9 | gold: 1, 10 | }, 11 | }, 12 | right: { 13 | gold: 5, 14 | right: { 15 | gold: 1, 16 | }, 17 | }, 18 | }; 19 | 20 | const countGold = (level) => { 21 | let total = level.gold; 22 | // 23 | if (level.left) total += countGold(level.left); 24 | // 25 | if (level.right) total += countGold(level.right); 26 | // 27 | 28 | return total; 29 | }; 30 | 31 | const result = countGold(mine); 32 | console.log(result); 33 | -------------------------------------------------------------------------------- /034-recursion/video-examples/nums.js: -------------------------------------------------------------------------------- 1 | const nums = [1, 2, 3, 4, 5, 6]; 2 | 3 | const sum = (array, index) => { 4 | // stop 5 | if (index === array.length - 1) { 6 | console.log(`BASE CASE: Index ${index}`); 7 | return array[index]; // array[array.length - 1] 8 | } 9 | 10 | console.log(`At index: ${index}`); 11 | const total = array[index] + sum(array, index + 1); 12 | console.log(`Total at index: ${index} is ${total}`); 13 | return total; 14 | }; 15 | 16 | const result = sum(nums, 0); 17 | 18 | console.log(result); 19 | -------------------------------------------------------------------------------- /035-closure/exercise-solutions/package.json: -------------------------------------------------------------------------------- 1 | { 2 | "dependencies": { 3 | "node-fetch": "^3.3.0" 4 | } 5 | } 6 | -------------------------------------------------------------------------------- /035-closure/exercises/exercise-1.js: -------------------------------------------------------------------------------- 1 | /* 2 | 1. Create a function called "stringBuilder" that has no 3 | parameters 4 | 2. Create a String inside "stringBuilder" named "result" 5 | that starts as an empty String 6 | 3. Create a Function inside "stringBuilder" called "add" 7 | that has a single parameter called "characters" 8 | - This function will add/concatenate the "characters" 9 | to the "result" String and then return the "result" 10 | 4. Return the "add" function from "stringBuilder" 11 | 12 | 5. Test out stringBuilder a few times like so: 13 | const builder = stringBuilder(); 14 | let text = builder("Hello "); 15 | text = builder("there "); 16 | text = builder("friend!"); 17 | console.log(text); // "Hello there friend!" 18 | */ 19 | -------------------------------------------------------------------------------- /035-closure/exercises/warmup-exercise.js: -------------------------------------------------------------------------------- 1 | /* 2 | 1. Create a function called "createCounter" that has 3 | no parameters 4 | 2. Inside "createCounter" create: 5 | - a variable called "counter" that starts at 0 6 | - a function called "incrementCounter" that increments 7 | the "counter" variable and then logs it out. 8 | 3. Return "incrementCounter" from the "createCounter" function 9 | 10 | 4. Test createCounter using different numbers like so: 11 | const counter = createCounter(); 12 | counter(); // 1 13 | counter(); // 2 14 | counter(); // 3 15 | counter(); // 4 16 | 17 | * Why is this considered "closure"? 18 | */ 19 | -------------------------------------------------------------------------------- /035-closure/video-examples/closure.js: -------------------------------------------------------------------------------- 1 | // global scope 2 | // const prices = [1337]; // 3 3 | 4 | const wrapperFunction = () => { 5 | // prices? 6 | const prices = [100]; // 2 7 | 8 | const logPrices = () => { 9 | // const prices = [10, 15, 20, 25]; // 1 10 | // prices? 11 | console.log(prices); 12 | }; 13 | 14 | return logPrices; 15 | }; 16 | 17 | const result = wrapperFunction(); 18 | console.log(result); 19 | 20 | result(); 21 | // console.log(prices); 22 | -------------------------------------------------------------------------------- /035-closure/video-examples/intro.js: -------------------------------------------------------------------------------- 1 | const wrapperFunction = () => { 2 | const prices = [10, 15, 20, 25]; 3 | 4 | const logPrices = () => { 5 | console.log(prices); 6 | }; 7 | 8 | logPrices(); 9 | 10 | // console.log(prices); 11 | }; 12 | 13 | wrapperFunction(); 14 | 15 | // console.log(prices); 16 | -------------------------------------------------------------------------------- /036-prototypes/exercise-solutions/exercise-1.js: -------------------------------------------------------------------------------- 1 | /* 2 | 1. Log out all the properties within the Object 3 | prototype. (Only it's own properties) 4 | 5 | 2. Log out all the properties within the Array 6 | prototype. (Only it's own properties) 7 | 8 | 3. Log out all the properties within the Array 9 | prototype's prototype. 10 | 11 | 4. Does this make sense? Why? 12 | */ 13 | 14 | // console.log(Object.getOwnPropertyNames(Object.prototype)); // [[ Prototype ]] 15 | 16 | console.log(Object.getOwnPropertyNames(Array.prototype.__proto__)); 17 | 18 | // console.log(Object.getOwnPropertyNames(Array.prototype.prototype)); 19 | // console.log(Array.prototype.prototype); 20 | 21 | // console.log(Object.getOwnPropertyNames([].__proto__.__proto__)); 22 | 23 | // Array -> Object -> null 24 | -------------------------------------------------------------------------------- /036-prototypes/exercise-solutions/exercise-2.js: -------------------------------------------------------------------------------- 1 | /* 2 | 1. Create a new Object and assign it to a variable 3 | called "fakeArray". Give it the following value: 4 | { "0": "Zero", "1": "One", "2": "Two", length: 3} 5 | 6 | 2. Set the prototype of "fakeArray" to be Array.prototype 7 | 8 | 3. Use the map method on "fakeArray" to log out each item 9 | in the array. 10 | 11 | 4. What is happening here and why does this work? 12 | */ 13 | 14 | const fakeArray = { 0: "Zero", 1: "One", 2: "Two", length: 3 }; 15 | 16 | // console.log(Object.getOwnPropertyNames(fakeArray.__proto__)); 17 | 18 | fakeArray.__proto__ = Array.prototype; 19 | 20 | // console.log(Object.getOwnPropertyNames(fakeArray.__proto__)); 21 | 22 | fakeArray.map((item) => console.log(item)); 23 | -------------------------------------------------------------------------------- /036-prototypes/exercise-solutions/warmup-exercise.js: -------------------------------------------------------------------------------- 1 | /* 2 | 1. Add a new function called "boop" to the prototype 3 | of String. This function should simply log out the 4 | String "Boop!". 5 | 6 | 2. Create a new String with the value "meow" and 7 | assign it to a variable called "cat". 8 | 9 | 3. Call the "boop" method on "cat" to make sure it 10 | works correctly. 11 | */ 12 | 13 | String.prototype.boop = () => { 14 | console.log("Boop!"); 15 | }; 16 | 17 | // String.prototype.boop(); 18 | 19 | const cat = "meow"; 20 | cat.boop(); 21 | 22 | console.log(Object.getOwnPropertyNames(cat.__proto__)); 23 | -------------------------------------------------------------------------------- /036-prototypes/exercises/BONUS-exercise.js: -------------------------------------------------------------------------------- 1 | /* 2 | 1. Create the following function: 3 | 4 | function Person(name) { 5 | this.name = name; 6 | } 7 | 8 | 2. Create an instance of person in 2 ways: 9 | const cleo = Person("Cleo") 10 | const taylor = new Person("Taylor") 11 | 12 | 3. Log out the own property names of each of these 13 | variables. What happens? 14 | 15 | 4. Log out just taylor's own property names. Does this 16 | work? Why? 17 | 18 | 5. Log out the prototype of cleo and taylor. What is 19 | happening? What about just taylor? 20 | */ 21 | -------------------------------------------------------------------------------- /036-prototypes/exercises/exercise-1.js: -------------------------------------------------------------------------------- 1 | /* 2 | 1. Log out all the properties within the Object 3 | prototype. (Only it's own properties) 4 | 5 | 2. Log out all the properties within the Array 6 | prototype. (Only it's own properties) 7 | 8 | 3. Log out all the properties within the Array 9 | prototype's prototype. 10 | 11 | 4. Does this make sense? Why? 12 | */ 13 | -------------------------------------------------------------------------------- /036-prototypes/exercises/exercise-2.js: -------------------------------------------------------------------------------- 1 | /* 2 | 1. Create a new Object and assign it to a variable 3 | called "fakeArray". Give it the following value: 4 | { "0": "Zero", "1": "One", "2": "Two", length: 3} 5 | 6 | 2. Set the prototype of "fakeArray" to be Array.prototype 7 | 8 | 3. Use the map method on "fakeArray" to log out each item 9 | in the array. 10 | 11 | 4. What is happening here and why does this work? 12 | */ 13 | -------------------------------------------------------------------------------- /036-prototypes/exercises/warmup-exercise.js: -------------------------------------------------------------------------------- 1 | /* 2 | 1. Add a new function called "boop" to the prototype 3 | of String. This function should simply log out the 4 | String "Boop!". 5 | 6 | 2. Create a new String with the value "meow" and 7 | assign it to a variable called "cat". 8 | 9 | 3. Call the "boop" method on "cat" to make sure it 10 | works correctly. 11 | */ 12 | -------------------------------------------------------------------------------- /036-prototypes/video-examples/animal.js: -------------------------------------------------------------------------------- 1 | const animal = { 2 | type: "monkey", 3 | numLegs: 2, 4 | }; 5 | 6 | console.log(animal); 7 | console.log(animal.numLegs); 8 | // console.log(animal.hello()); 9 | console.log(animal.toString()); 10 | console.log(animal.hasOwnProperty("type")); 11 | console.log(animal.hasOwnProperty("numLegs")); 12 | console.log(animal.hasOwnProperty("hello")); 13 | console.log(animal.hasOwnProperty("toString")); 14 | 15 | const myObject = {}; 16 | const myObject2 = new Object(); 17 | -------------------------------------------------------------------------------- /036-prototypes/video-examples/array.js: -------------------------------------------------------------------------------- 1 | const animal = { 2 | type: "monkey", 3 | __proto__: Array.prototype, 4 | }; 5 | 6 | console.log(animal); 7 | console.log(Object.getOwnPropertyNames(animal)); 8 | // console.log(Object.getOwnPropertyNames(animal.__proto__)); 9 | console.log(Object.getOwnPropertyNames(animal.__proto__.__proto__)); 10 | 11 | console.log(animal.__proto__.__proto__.__proto__); 12 | console.log(animal.length); 13 | -------------------------------------------------------------------------------- /036-prototypes/video-examples/getters.js: -------------------------------------------------------------------------------- 1 | Object.prototype.speak = () => { 2 | console.log("hi from prototype"); 3 | }; 4 | 5 | const animal = { 6 | type: "monkey", 7 | numLegs: 2, 8 | // speak: () => { 9 | // console.log("hi"); 10 | // }, 11 | }; 12 | 13 | const animal2 = { 14 | type: "cat", 15 | }; 16 | 17 | // console.log(animal); 18 | 19 | // console.log(animal.__proto__); 20 | // console.log(animal.__proto__.__proto__); 21 | 22 | // console.log(Object.getPrototypeOf(animal)); 23 | 24 | // console.log(Object.getOwnPropertyNames(animal)); 25 | console.log(Object.getOwnPropertyNames(animal.__proto__)); 26 | 27 | animal.speak(); 28 | animal2.speak(); 29 | -------------------------------------------------------------------------------- /036-prototypes/video-examples/object.js: -------------------------------------------------------------------------------- 1 | Object.keys({ name: "hi" }); 2 | 3 | Object.hello = () => console.log("hello there!"); 4 | 5 | Object.prototype.hello = () => console.log("hello there from animal"); 6 | Object.prototype.hello2 = () => "hello"; 7 | 8 | const animal = { 9 | type: "monkey", 10 | }; 11 | 12 | // animal.keys(); 13 | animal.hello(); 14 | 15 | Object.hello(); 16 | 17 | console.log(Object.getOwnPropertyNames(Object)); 18 | console.log(Object.getOwnPropertyNames(animal)); 19 | console.log(Object.getOwnPropertyNames(animal.__proto__)); 20 | -------------------------------------------------------------------------------- /037-this-keyword/exercises/exercise-1.js: -------------------------------------------------------------------------------- 1 | /* 2 | 1. Create the following Object and assign it to a variable 3 | named "book": 4 | { 5 | name: "Harry Potter", 6 | author: "J.K. Rowling", 7 | characters: { 8 | mainChars: ["Harry", "Ron", "Hermione"], 9 | list: function() { 10 | for (const char of this.mainChars) { 11 | console.log(char) 12 | } 13 | } 14 | } 15 | } 16 | 17 | 2. Call the list function on the book and explain the behaviour 18 | 19 | 3. How would you make the "list" method temporarily (for one 20 | function call) log out this array instead: 21 | ["Draco", "Severus", "Voldemort"] ? 22 | 23 | HINT* What methods can we use on Functions to manipulate "this"? 24 | */ 25 | -------------------------------------------------------------------------------- /037-this-keyword/exercises/exercise-2.js: -------------------------------------------------------------------------------- 1 | /* 2 | 1. Create the following Object and assign it to a variable 3 | named "book": 4 | { 5 | name: "Harry Potter", 6 | author: "J.K. Rowling", 7 | characters: { 8 | mainChars: ["Harry", "Ron", "Hermione"], 9 | list: function() { 10 | for (const char of this.mainChars) { 11 | console.log(char) 12 | } 13 | } 14 | } 15 | } 16 | 17 | 2. Make it so if we do: book.characters.list() 18 | It will always use this Array of mainChars permanently: 19 | ["Draco", "Severus", "Voldemort"] 20 | 21 | ^ Do not modify "mainChars", you can only change "list" 22 | Also, you cannot modify the "list" function itself 23 | 24 | HINT* What methods can we use on Functions to manipulate "this"? 25 | */ 26 | -------------------------------------------------------------------------------- /037-this-keyword/exercises/exercise-3.js: -------------------------------------------------------------------------------- 1 | /* 2 | 1. Create a function called "Person". It will have 3 3 | parameters: name, age, and favouriteFood. (function 4 | syntax, not arrow function!) 5 | 6 | 2. Inside of Person, directly set these values: 7 | this.name = name; 8 | this.age = age; 9 | this.favouriteFood = favouriteFood 10 | (no return value is needed) 11 | 12 | 3. Create a the following two variables: 13 | const avery = Person("Avery", 20, "Dark Chocolate"); 14 | const jackie = new Person("Jackie", 35, "Sourdough Bread"); 15 | 16 | 4. Log out "avery" and "jackie" and explain what you see 17 | 18 | 5. Log out the entire prototype chain of "jackie" (one by one) 19 | 20 | 6. How would you explain what is happening when we use the 21 | "new" operator with a function in JS? 22 | */ 23 | -------------------------------------------------------------------------------- /037-this-keyword/exercises/warmup-exercise.js: -------------------------------------------------------------------------------- 1 | /* 2 | 1. Create the following Object and assign it to a variable 3 | named "pet": 4 | { name: "Nemo", type: "fish", age: 2 } 5 | 6 | 2. Add a 'sayHello' function to the Object prototype. When 7 | called, it should log out the Object's name, 8 | type and age to match the following example: 9 | "Nemo is a fish and is 2 years old. Nemo says hi!" 10 | 11 | ^ This would be logged if we did pet.sayHello(); 12 | 13 | 3. Create another pet with different property values 14 | to make sure it works as well. 15 | */ 16 | -------------------------------------------------------------------------------- /037-this-keyword/video-examples/alex.js: -------------------------------------------------------------------------------- 1 | const alex = { 2 | name: "Alex", 3 | greet: function () { 4 | console.log(this); 5 | console.log(`${this.name} says hi!`); 6 | }, 7 | arrowGreet: () => { 8 | console.log(this); 9 | console.log(`${this.name} says hi!`); 10 | }, 11 | friend: { 12 | name: "Alex's friend", 13 | greet: function () { 14 | console.log(this); 15 | console.log(`${this.name} says hi!`); 16 | }, 17 | }, 18 | }; 19 | 20 | // alex.greet(); 21 | // alex.arrowGreet(); 22 | alex.friend.greet(); 23 | -------------------------------------------------------------------------------- /037-this-keyword/video-examples/bind.js: -------------------------------------------------------------------------------- 1 | const alex = { 2 | name: "Alex", 3 | greet: function (a, b) { 4 | console.log(this); 5 | console.log(a, b); 6 | console.log(`${this.name} says hi!`); 7 | }, 8 | arrowGreet: () => { 9 | console.log(this); 10 | console.log(`${this.name} says hi!`); 11 | }, 12 | friend: { 13 | name: "Alex's friend", 14 | greet: function (a, b) { 15 | console.log(this); 16 | // console.log(args); 17 | console.log(a, b); 18 | console.log(`${this.name} says hi!`); 19 | }, 20 | }, 21 | }; 22 | 23 | const boundGreet = alex.greet.bind({ name: "Iron Man" }); 24 | // console.log(boundGreet); 25 | // boundGreet("hello", "there"); 26 | 27 | alex.friend.greet = alex.friend.greet.bind({ name: "Iron Man" }); 28 | alex.friend.greet(1, 2); 29 | -------------------------------------------------------------------------------- /037-this-keyword/video-examples/call.js: -------------------------------------------------------------------------------- 1 | const alex = { 2 | name: "Alex", 3 | greet: function (a, b) { 4 | console.log(this); 5 | console.log(a, b); 6 | console.log(`${this.name} says hi!`); 7 | }, 8 | arrowGreet: () => { 9 | console.log(this); 10 | console.log(`${this.name} says hi!`); 11 | }, 12 | friend: { 13 | name: "Alex's friend", 14 | greet: function (a, b) { 15 | console.log(this); 16 | // console.log(args); 17 | console.log(a, b); 18 | console.log(`${this.name} says hi!`); 19 | }, 20 | }, 21 | }; 22 | 23 | alex.greet(); 24 | alex.friend.greet(); 25 | 26 | console.log("------"); 27 | alex.greet.apply({ name: "Iron Man", age: 40 }, ["hello", 100]); 28 | alex.friend.greet.call({ name: "Wonder Woman", age: 45 }, "hello", 100); 29 | -------------------------------------------------------------------------------- /037-this-keyword/video-examples/new.js: -------------------------------------------------------------------------------- 1 | function Hero(name) { 2 | this.name = name; 3 | this.greet = function () { 4 | console.log(this); 5 | console.log(`${this.name} says awesome!`); 6 | }; 7 | } 8 | 9 | const storm = new Hero("Storm"); 10 | console.log(storm); 11 | 12 | storm.greet(); 13 | storm.greet.call({ name: "Cyborg" }); 14 | 15 | console.log("--------"); 16 | 17 | console.log(Object.getOwnPropertyNames(storm)); 18 | console.log(Object.getOwnPropertyNames(storm.__proto__)); 19 | 20 | console.log(storm.__proto__.constructor.name); 21 | console.log(storm.__proto__.__proto__.constructor.name); 22 | console.log(storm.__proto__.__proto__.__proto__); 23 | 24 | // Hero => Object => null 25 | -------------------------------------------------------------------------------- /037-this-keyword/video-examples/prototype.js: -------------------------------------------------------------------------------- 1 | Object.prototype.greet = function () { 2 | console.log(this); 3 | console.log(`${this.name} says hello there!`); 4 | }; 5 | 6 | const nader = { 7 | name: "nader", 8 | }; 9 | 10 | const thor = { 11 | namee: "thor", 12 | }; 13 | 14 | nader.greet(); 15 | thor.greet(); 16 | 17 | // Array.prototype.map = 18 | -------------------------------------------------------------------------------- /038-classes-oop-intro/exercises/BONUS-exercise-1.js: -------------------------------------------------------------------------------- 1 | /* 2 | Let's see how a "Factory" class/function might work 3 | 4 | 1. Create a class called "EnemyFactory" 5 | 6 | 2. Make the following work to produce the output shown: 7 | 8 | const factory = new EnemyFactory(); 9 | const flying = factory.generateFlyingEnemy("batman"); 10 | flying.fly(); // batman can fly! 11 | 12 | const swimming = EnemyFactory.generateSwimmingEnemy("aquaman"); 13 | swimming.swim(); // aquaman can swim! 14 | 15 | * What is the difference between these two? When might you 16 | even use this? Where are the property keys of each of these: 17 | - EnemyFactory 18 | - factory 19 | - factory.__proto__ 20 | - flying.__proto__ 21 | - swimming.__proto__ 22 | */ 23 | -------------------------------------------------------------------------------- /038-classes-oop-intro/exercises/exercise-3.js: -------------------------------------------------------------------------------- 1 | /* 2 | 1. Lookup the retro arcade game: Space Invaders 3 | on Google for some pictures 4 | Eg: https://en.wikipedia.org/wiki/Space_Invaders 5 | 6 | 2. How would you build a class to model the Player 7 | (Spaceship) and the Enemy (Flying Alien)? 8 | 9 | 3. Try to think of all the different fields and 10 | methods each would have in a real game. What 11 | would you want to have in them? 12 | 13 | 4. Write these out first on paper/text to 14 | brainstorm, then implement the classes in JS 15 | 16 | * This is purposefully open-ended to allow you 17 | the creative freedom to design these classes 18 | */ 19 | -------------------------------------------------------------------------------- /038-classes-oop-intro/exercises/warmup-exercise.js: -------------------------------------------------------------------------------- 1 | /* 2 | 1. Create a class called "Animal" 3 | 4 | 2. Allow us to pass in 2 properties/fields to the 5 | Animal constructor which get set to the instance: 6 | - type (String) 7 | - name (String) 8 | 9 | 3. Create two instances of the Animal class of your 10 | choice passing in different "type" and "name" for each 11 | 12 | 4. Print out both animal instances 13 | 14 | 5. Change the "name" of one of your animals and print it 15 | out again. 16 | 17 | *HINT: "this" will refer to the instance inside the class 18 | */ 19 | -------------------------------------------------------------------------------- /038-classes-oop-intro/video-examples/badIntro.js: -------------------------------------------------------------------------------- 1 | const player = { 2 | name: "?", 3 | hp: 100, 4 | mp: 0, 5 | items: [], 6 | }; 7 | 8 | const hanSolo = player; 9 | hanSolo.name = "Han Solo"; 10 | hanSolo.hp = 80; 11 | hanSolo.mp = 20; 12 | hanSolo.items = ["Blaster"]; 13 | 14 | const darthVader = player; 15 | 16 | console.log(hanSolo); 17 | console.log(darthVader); 18 | -------------------------------------------------------------------------------- /038-classes-oop-intro/video-examples/slightlyBetter.js: -------------------------------------------------------------------------------- 1 | const createPlayer = (name, hp, mp, items) => { 2 | return { 3 | name, 4 | hp, 5 | mp, 6 | items, 7 | }; 8 | }; 9 | 10 | const hanSolo = createPlayer("Han Solo", 100, 10, ["Blaster"]); 11 | hanSolo.hp = 150; 12 | console.log(hanSolo); 13 | 14 | const darthVader = createPlayer("Darth Vader", 200, 50, ["Saber"]); 15 | console.log(darthVader); 16 | -------------------------------------------------------------------------------- /039-classes-oop-inheritance-polymorphism/exercises/exercise-3.js: -------------------------------------------------------------------------------- 1 | /* 2 | 1. Lookup the retro arcade game: Space Invaders 3 | on Google for some pictures 4 | Eg: https://en.wikipedia.org/wiki/Space_Invaders 5 | 6 | 2. How would you build a class to model the Player 7 | (Spaceship) and the Enemies (Flying Aliens)? 8 | * There are multiple different Aliens 9 | 10 | 3. Try to think of all the different fields and 11 | methods each would have in a real game. What 12 | would you want to have in them? 13 | 14 | 4. Write these out first on paper/text to 15 | brainstorm, then implement the classes in JS 16 | 17 | * This is purposefully open-ended to allow you 18 | the creative freedom to design these classes 19 | */ 20 | -------------------------------------------------------------------------------- /039-classes-oop-inheritance-polymorphism/video-examples/subclass.js: -------------------------------------------------------------------------------- 1 | class Player { 2 | constructor(name, hp, mp, items) { 3 | this.name = name; 4 | this.hp = hp; 5 | this.mp = mp; 6 | this.items = items; 7 | console.log("player this", this); 8 | } 9 | } 10 | 11 | class Warrior extends Player { 12 | constructor(name, hp, mp, items, shield) { 13 | super(name, hp, mp, items); 14 | this.shield = shield; 15 | console.log("warrior this", this); 16 | } 17 | } 18 | 19 | const player = new Player("Player", 100, 50, ["banana"]); 20 | console.log(player); 21 | 22 | const warrior = new Warrior( 23 | "Genghis Khan", 24 | 500, 25 | 50, 26 | ["Sabre"], 27 | "Leather Shield" 28 | ); 29 | console.log(warrior); 30 | -------------------------------------------------------------------------------- /040-encapsulation-static/exercise-solutions/BONUS-exercise-1.js: -------------------------------------------------------------------------------- 1 | /* 2 | 1. If you were to design your own class for your 3 | project, what questions would you ask while 4 | deciding whether to make something a static or 5 | instance field/method/property? 6 | 7 | 2. How about private or public accessors for these 8 | static or instance fields/methods/properties? 9 | */ 10 | -------------------------------------------------------------------------------- /040-encapsulation-static/exercise-solutions/exercise-3.js: -------------------------------------------------------------------------------- 1 | /* 2 | 1. Go to the MDN javascript documentation online 3 | and lookup "Array". 4 | 5 | 2. What are all the STATIC properties and methods 6 | on the Array Object? 7 | 8 | 3. What are all the INSTANCE properties and methods 9 | on Array instances? 10 | 11 | 4. Explain why some of these are static and why some 12 | are instance fields/properties/methods 13 | */ 14 | 15 | console.log(Array.isArray([])); 16 | 17 | const str = "hello"; 18 | Array.isArray(str); // false 19 | const arr = new Array(); 20 | arr.isArray(str); 21 | 22 | console.log(Array.isArray("hello")); 23 | console.log(Array.length); 24 | console.log(Array.name); 25 | console.log(Array.prototype); 26 | console.log(Object.getOwnPropertyNames(Array)); 27 | console.log(Object.getOwnPropertyNames(Array.prototype)); 28 | -------------------------------------------------------------------------------- /040-encapsulation-static/exercises/BONUS-exercise-1.js: -------------------------------------------------------------------------------- 1 | /* 2 | 1. If you were to design your own class for your 3 | project, what questions would you ask while 4 | deciding whether to make something a static or 5 | instance field/method/property? 6 | 7 | 2. How about private or public accessors for these 8 | static or instance fields/methods/properties? 9 | */ 10 | -------------------------------------------------------------------------------- /040-encapsulation-static/exercises/exercise-3.js: -------------------------------------------------------------------------------- 1 | /* 2 | 1. Go to the MDN javascript documentation online 3 | and lookup "Array". 4 | 5 | 2. What are all the STATIC properties and methods 6 | on the Array Object? 7 | 8 | 3. What are all the INSTANCE properties and methods 9 | on Array instances? 10 | 11 | 4. Explain why some of these are static and why some 12 | are instance fields/properties/methods 13 | */ 14 | -------------------------------------------------------------------------------- /040-encapsulation-static/video-examples/static.js: -------------------------------------------------------------------------------- 1 | class Utils { 2 | static description = "Awesome utilities!"; 3 | description = "Another description?"; 4 | 5 | static caps(str) { 6 | return str.toUpperCase(); 7 | } 8 | 9 | lower(str) { 10 | return str.toLowerCase(); 11 | } 12 | } 13 | 14 | Utils.hello = "hello"; 15 | Utils.prototype.camelCase = () => {}; 16 | 17 | console.log(Utils.description); 18 | console.log(Utils.caps); 19 | 20 | console.log(Object.getOwnPropertyNames(Utils)); 21 | 22 | const utils = new Utils(); 23 | console.log(utils); 24 | console.log(Object.getOwnPropertyNames(utils)); 25 | console.log(Object.getOwnPropertyNames(utils.__proto__)); 26 | -------------------------------------------------------------------------------- /041-Capstone-project-rpg-game/exercise-solutions/GridObject.js: -------------------------------------------------------------------------------- 1 | class GridObject { 2 | #backgroundSprites = ["🌳", "🌲", "🌴", "🌵"]; 3 | 4 | constructor(sprite, type = "undiscovered") { 5 | if (!sprite) { 6 | const randomIndex = Math.floor( 7 | Math.random() * this.#backgroundSprites.length 8 | ); 9 | this.sprite = this.#backgroundSprites[randomIndex]; 10 | } else { 11 | this.sprite = sprite; 12 | } 13 | this.type = type; 14 | } 15 | 16 | describe() { 17 | const random = Math.random(); 18 | if (random < 0.33) { 19 | console.log("Coast is clear!"); 20 | } else if (random < 0.66) { 21 | console.log("These surroundings look familiar."); 22 | } else { 23 | console.log("There's not much here."); 24 | } 25 | } 26 | } 27 | 28 | export { GridObject }; 29 | -------------------------------------------------------------------------------- /041-Capstone-project-rpg-game/exercise-solutions/package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "code", 3 | "version": "1.0.0", 4 | "main": "Grid.js", 5 | "scripts": { 6 | "test": "echo \"Error: no test specified\" && exit 1" 7 | }, 8 | "keywords": [], 9 | "author": "", 10 | "license": "ISC", 11 | "type": "module", 12 | "description": "", 13 | "dependencies": { 14 | "inquirer": "^9.1.4" 15 | } 16 | } 17 | -------------------------------------------------------------------------------- /041-Capstone-project-rpg-game/exercise-solutions/playerPrompts.js: -------------------------------------------------------------------------------- 1 | import inquirer from "inquirer"; 2 | 3 | async function promptPlayerForDirection() { 4 | const results = await inquirer.prompt({ 5 | type: "list", 6 | name: "direction", 7 | message: "Which direction would you like to travel:", 8 | choices: ["Up", "Down", "Left", "Right"], 9 | }); 10 | return results.direction; 11 | } 12 | 13 | export { promptPlayerForDirection }; 14 | -------------------------------------------------------------------------------- /041-Capstone-project-rpg-game/exercises/GridObject.js: -------------------------------------------------------------------------------- 1 | class GridObject { 2 | #backgroundSprites = ["🌳", "🌲", "🌴", "🌵"]; 3 | 4 | constructor(sprite, type = "undiscovered") { 5 | if (!sprite) { 6 | const randomIndex = Math.floor( 7 | Math.random() * this.#backgroundSprites.length 8 | ); 9 | this.sprite = this.#backgroundSprites[randomIndex]; 10 | } else { 11 | this.sprite = sprite; 12 | } 13 | this.type = type; 14 | } 15 | 16 | describe() { 17 | const random = Math.random(); 18 | if (random < 0.33) { 19 | console.log("Coast is clear!"); 20 | } else if (random < 0.66) { 21 | console.log("These surroundings look familiar."); 22 | } else { 23 | console.log("There's not much here."); 24 | } 25 | } 26 | } 27 | 28 | export { GridObject }; 29 | -------------------------------------------------------------------------------- /041-Capstone-project-rpg-game/exercises/package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "code", 3 | "version": "1.0.0", 4 | "main": "Grid.js", 5 | "scripts": { 6 | "test": "echo \"Error: no test specified\" && exit 1" 7 | }, 8 | "keywords": [], 9 | "author": "", 10 | "license": "ISC", 11 | "type": "module", 12 | "description": "", 13 | "dependencies": { 14 | "inquirer": "^9.1.4" 15 | } 16 | } 17 | -------------------------------------------------------------------------------- /041-Capstone-project-rpg-game/exercises/playerPrompts.js: -------------------------------------------------------------------------------- 1 | import inquirer from "inquirer"; 2 | 3 | async function promptPlayerForDirection() { 4 | const results = await inquirer.prompt({ 5 | type: "list", 6 | name: "direction", 7 | message: "Which direction would you like to travel:", 8 | choices: ["Up", "Down", "Left", "Right"], 9 | }); 10 | return results.direction; 11 | } 12 | 13 | export { promptPlayerForDirection }; 14 | -------------------------------------------------------------------------------- /041-Capstone-project-rpg-game/video-examples/GridObject.js: -------------------------------------------------------------------------------- 1 | class GridObject { 2 | #backgroundSprites = ["🌳", "🌲", "🌴", "🌵"]; 3 | 4 | constructor(sprite, type = "undiscovered") { 5 | if (!sprite) { 6 | const randomIndex = Math.floor( 7 | Math.random() * this.#backgroundSprites.length 8 | ); 9 | this.sprite = this.#backgroundSprites[randomIndex]; 10 | } else { 11 | this.sprite = sprite; 12 | } 13 | this.type = type; 14 | } 15 | 16 | describe() { 17 | const random = Math.random(); 18 | if (random < 0.33) { 19 | console.log("Coast is clear!"); 20 | } else if (random < 0.66) { 21 | console.log("These surroundings look familiar."); 22 | } else { 23 | console.log("There's not much here."); 24 | } 25 | } 26 | } 27 | 28 | export { GridObject }; 29 | -------------------------------------------------------------------------------- /041-Capstone-project-rpg-game/video-examples/package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "code", 3 | "version": "1.0.0", 4 | "main": "Grid.js", 5 | "scripts": { 6 | "test": "echo \"Error: no test specified\" && exit 1" 7 | }, 8 | "keywords": [], 9 | "author": "", 10 | "license": "ISC", 11 | "type": "module", 12 | "description": "", 13 | "dependencies": { 14 | "inquirer": "^9.1.4" 15 | } 16 | } 17 | -------------------------------------------------------------------------------- /041-Capstone-project-rpg-game/video-examples/playerPrompts.js: -------------------------------------------------------------------------------- 1 | import inquirer from "inquirer"; 2 | 3 | async function promptPlayerForDirection() { 4 | const results = await inquirer.prompt({ 5 | type: "list", 6 | name: "direction", 7 | message: "Which direction would you like to travel:", 8 | choices: ["Up", "Down", "Left", "Right"], 9 | }); 10 | return results.direction; 11 | } 12 | 13 | export { promptPlayerForDirection }; 14 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # Javascript In Depth 2 | 3 | This is a companion repository for the [Javascript In Depth Youtube Series](https://www.youtube.com/playlist?list=PLovN13bqAx7D_MFjL0PHnCkYAHMSO8-kU) 4 | 5 | It contains some of the video notes, along with the exercises and exercise solutions for each section. --------------------------------------------------------------------------------