├── .gitignore ├── README.md ├── Section_01_-_Welcome,_Welcome,_Welcome! └── README.md ├── Section_02_-_The_Fondamentals ├── 00_Browser_console │ └── browser_console.js ├── 01_Linking_a_JavaScript_File │ ├── index.html │ └── script.js ├── 02_Values_and_Variables │ ├── index.html │ └── script.js ├── 03_Variable_name_conventions │ ├── index.html │ └── script.js ├── 04_Practice_Assignments │ └── values_and_variables_assignment.js ├── 05_Data_Types │ ├── index.html │ └── script.js ├── 06_let,_const_and_var │ ├── index.html │ └── script.js ├── 07_Basic_Operators │ ├── index.html │ └── script.js ├── 08_Coding_Challenge_01 │ ├── index.html │ └── script.js ├── 09_Strings_and_Template_Literals │ ├── index.html │ └── script.js ├── 10_Taking_Decisions_if_else_statements │ ├── index.html │ └── script.js ├── 11_Coding_Challenge_02 │ ├── index.html │ └── script.js ├── 12_Type_conversion_and_coercion │ ├── index.html │ └── script.js ├── 13_Truthy_and_Falsy_values │ ├── index.html │ └── script.js ├── 14_Equality_operators │ ├── index.html │ └── script.js ├── 15_Logical_Operators │ ├── index.html │ └── script.js ├── 16_Coding_Challenge_03 │ ├── index.html │ └── script.js ├── 17_The_Switch_Statement │ ├── index.html │ └── script.js ├── 18_Statements_and_Expressions │ ├── index.html │ └── script.js ├── 19_The_Conditional_Ternary_Operator │ ├── index.html │ └── script.js └── 20_Coding_Challenge_04 │ ├── index.html │ └── script.js ├── Section_03_-_The_Fondamentals ├── 01_Activating_Strict_Mode │ ├── index.html │ └── script.js ├── 02_Functions │ ├── index.html │ └── script.js ├── 03_Function_declarations_vs_expressions │ ├── index.html │ └── script.js ├── 04_Arrow_functions │ ├── index.html │ └── script.js ├── 05_Functions_calling_other_functions │ ├── index.html │ └── script.js ├── 06_Reviewing_functions │ ├── index.html │ └── script.js ├── 07_Coding_Challenge_01 │ ├── index.html │ └── script.js ├── 08_Introduction_to_Arrays │ ├── index.html │ └── script.js ├── 09_Basic_Array_Operations │ ├── index.html │ └── script.js ├── 10_Coding_Challenge_02 │ ├── index.html │ └── script.js ├── 11_Introduction_to_Objects │ ├── index.html │ └── script.js ├── 12_Object_methods │ ├── index.html │ └── script.js ├── 13_Coding_Challenge_03 │ ├── index.html │ └── script.js ├── 14_Iteration_Loops │ ├── index.html │ └── script.js └── 15_Coding_Challenge_04 │ ├── index.html │ └── script.js ├── Section_04_-_How_to_Navigate_this_Course └── README.md ├── Section_05_-_Developer_Skills_and_Editor_Setup ├── index.html └── script.js ├── Section_06_-_HTML_and_CSS_Crash_Course ├── index.html └── style.css ├── Section_07_-_JavaScript_in_the_Browser_DOM_and_Events_Fundamentals ├── 1_Guess_My_Number_Project │ └── README.md ├── 2_Modal_Window_Project │ └── README.md └── 3_Pig_Game_Project │ └── README.md ├── Section_08_-_How_JavaScript_Works_Behind_the_Scenes ├── 1_Scoping_in_Practice │ ├── index.html │ └── script.js ├── 2_Hoisting_and_TDZ_in_Practice │ ├── index.html │ └── script.js ├── 3_The_this_Keyword │ ├── index.html │ └── script.js ├── 4_Regular_Functions_vs_Arrow_Functions │ ├── index.html │ └── script.js └── 5_Objects_vs_Primitives │ ├── index.html │ └── script.js ├── Section_09_-_Data_Structures_Modern_Operators_Strings ├── 01_Destructuring_Arrays │ ├── index.html │ └── script.js ├── 02_The_Spread_Operator │ ├── index.html │ └── script.js ├── 03_Rest_patterns_and_parameters │ ├── index.html │ └── script.js └── 04_Short_circuiting_&&_and_|| │ ├── index.html │ └── script.js └── all_coding_challenges.pdf /.gitignore: -------------------------------------------------------------------------------- 1 | 2 | # Created by https://www.toptal.com/developers/gitignore/api/python,pycharm,eclipse,java,intellij+all,c++ 3 | # Edit at https://www.toptal.com/developers/gitignore?templates=python,pycharm,eclipse,java,intellij+all,c++ 4 | 5 | ### C++ ### 6 | # Prerequisites 7 | *.d 8 | 9 | # Compiled Object files 10 | *.slo 11 | *.lo 12 | *.o 13 | *.obj 14 | 15 | # Precompiled Headers 16 | *.gch 17 | *.pch 18 | 19 | # Compiled Dynamic libraries 20 | *.so 21 | *.dylib 22 | *.dll 23 | 24 | # Fortran module files 25 | *.mod 26 | *.smod 27 | 28 | # Compiled Static libraries 29 | *.lai 30 | *.la 31 | *.a 32 | *.lib 33 | 34 | # Executables 35 | *.exe 36 | *.out 37 | *.app 38 | 39 | ### Eclipse ### 40 | .metadata 41 | bin/ 42 | tmp/ 43 | *.tmp 44 | *.bak 45 | *.swp 46 | *~.nib 47 | local.properties 48 | .settings/ 49 | .loadpath 50 | .recommenders 51 | 52 | # External tool builders 53 | .externalToolBuilders/ 54 | 55 | # Locally stored "Eclipse launch configurations" 56 | *.launch 57 | 58 | # PyDev specific (Python IDE for Eclipse) 59 | *.pydevproject 60 | 61 | # CDT-specific (C/C++ Development Tooling) 62 | .cproject 63 | 64 | # CDT- autotools 65 | .autotools 66 | 67 | # Java annotation processor (APT) 68 | .factorypath 69 | 70 | # PDT-specific (PHP Development Tools) 71 | .buildpath 72 | 73 | # sbteclipse plugin 74 | .target 75 | 76 | # Tern plugin 77 | .tern-project 78 | 79 | # TeXlipse plugin 80 | .texlipse 81 | 82 | # STS (Spring Tool Suite) 83 | .springBeans 84 | 85 | # Code Recommenders 86 | .recommenders/ 87 | 88 | # Annotation Processing 89 | .apt_generated/ 90 | .apt_generated_test/ 91 | 92 | # Scala IDE specific (Scala & Java development for Eclipse) 93 | .cache-main 94 | .scala_dependencies 95 | .worksheet 96 | 97 | # Uncomment this line if you wish to ignore the project description file. 98 | # Typically, this file would be tracked if it contains build/dependency configurations: 99 | #.project 100 | 101 | ### Eclipse Patch ### 102 | # Spring Boot Tooling 103 | .sts4-cache/ 104 | 105 | ### Intellij+all ### 106 | # Covers JetBrains IDEs: IntelliJ, RubyMine, PhpStorm, AppCode, PyCharm, CLion, Android Studio, WebStorm and Rider 107 | # Reference: https://intellij-support.jetbrains.com/hc/en-us/articles/206544839 108 | 109 | # User-specific stuff 110 | .idea/**/workspace.xml 111 | .idea/**/tasks.xml 112 | .idea/**/usage.statistics.xml 113 | .idea/**/dictionaries 114 | .idea/**/shelf 115 | 116 | # AWS User-specific 117 | .idea/**/aws.xml 118 | 119 | # Generated files 120 | .idea/**/contentModel.xml 121 | 122 | # Sensitive or high-churn files 123 | .idea/**/dataSources/ 124 | .idea/**/dataSources.ids 125 | .idea/**/dataSources.local.xml 126 | .idea/**/sqlDataSources.xml 127 | .idea/**/dynamic.xml 128 | .idea/**/uiDesigner.xml 129 | .idea/**/dbnavigator.xml 130 | 131 | # Gradle 132 | .idea/**/gradle.xml 133 | .idea/**/libraries 134 | 135 | # Gradle and Maven with auto-import 136 | # When using Gradle or Maven with auto-import, you should exclude module files, 137 | # since they will be recreated, and may cause churn. Uncomment if using 138 | # auto-import. 139 | # .idea/artifacts 140 | # .idea/compiler.xml 141 | # .idea/jarRepositories.xml 142 | # .idea/modules.xml 143 | # .idea/*.iml 144 | # .idea/modules 145 | # *.iml 146 | # *.ipr 147 | 148 | # CMake 149 | cmake-build-*/ 150 | 151 | # Mongo Explorer plugin 152 | .idea/**/mongoSettings.xml 153 | 154 | # File-based project format 155 | *.iws 156 | 157 | # IntelliJ 158 | out/ 159 | 160 | # mpeltonen/sbt-idea plugin 161 | .idea_modules/ 162 | 163 | # JIRA plugin 164 | atlassian-ide-plugin.xml 165 | 166 | # Cursive Clojure plugin 167 | .idea/replstate.xml 168 | 169 | # Crashlytics plugin (for Android Studio and IntelliJ) 170 | com_crashlytics_export_strings.xml 171 | crashlytics.properties 172 | crashlytics-build.properties 173 | fabric.properties 174 | 175 | # Editor-based Rest Client 176 | .idea/httpRequests 177 | 178 | # Android studio 3.1+ serialized cache file 179 | .idea/caches/build_file_checksums.ser 180 | 181 | ### Intellij+all Patch ### 182 | # Ignores the whole .idea folder and all .iml files 183 | # See https://github.com/joeblau/gitignore.io/issues/186 and https://github.com/joeblau/gitignore.io/issues/360 184 | 185 | .idea/ 186 | 187 | # Reason: https://github.com/joeblau/gitignore.io/issues/186#issuecomment-249601023 188 | 189 | *.iml 190 | modules.xml 191 | .idea/misc.xml 192 | *.ipr 193 | 194 | # Sonarlint plugin 195 | .idea/sonarlint 196 | 197 | ### Java ### 198 | # Compiled class file 199 | *.class 200 | 201 | # Log file 202 | *.log 203 | 204 | # BlueJ files 205 | *.ctxt 206 | 207 | # Mobile Tools for Java (J2ME) 208 | .mtj.tmp/ 209 | 210 | # Package Files # 211 | *.jar 212 | *.war 213 | *.nar 214 | *.ear 215 | *.zip 216 | *.tar.gz 217 | *.rar 218 | 219 | # virtual machine crash logs, see http://www.java.com/en/download/help/error_hotspot.xml 220 | hs_err_pid* 221 | 222 | ### PyCharm ### 223 | # Covers JetBrains IDEs: IntelliJ, RubyMine, PhpStorm, AppCode, PyCharm, CLion, Android Studio, WebStorm and Rider 224 | # Reference: https://intellij-support.jetbrains.com/hc/en-us/articles/206544839 225 | 226 | # User-specific stuff 227 | 228 | # AWS User-specific 229 | 230 | # Generated files 231 | 232 | # Sensitive or high-churn files 233 | 234 | # Gradle 235 | 236 | # Gradle and Maven with auto-import 237 | # When using Gradle or Maven with auto-import, you should exclude module files, 238 | # since they will be recreated, and may cause churn. Uncomment if using 239 | # auto-import. 240 | # .idea/artifacts 241 | # .idea/compiler.xml 242 | # .idea/jarRepositories.xml 243 | # .idea/modules.xml 244 | # .idea/*.iml 245 | # .idea/modules 246 | # *.iml 247 | # *.ipr 248 | 249 | # CMake 250 | 251 | # Mongo Explorer plugin 252 | 253 | # File-based project format 254 | 255 | # IntelliJ 256 | 257 | # mpeltonen/sbt-idea plugin 258 | 259 | # JIRA plugin 260 | 261 | # Cursive Clojure plugin 262 | 263 | # Crashlytics plugin (for Android Studio and IntelliJ) 264 | 265 | # Editor-based Rest Client 266 | 267 | # Android studio 3.1+ serialized cache file 268 | 269 | ### PyCharm Patch ### 270 | # Comment Reason: https://github.com/joeblau/gitignore.io/issues/186#issuecomment-215987721 271 | 272 | # *.iml 273 | # modules.xml 274 | # .idea/misc.xml 275 | # *.ipr 276 | 277 | # Sonarlint plugin 278 | # https://plugins.jetbrains.com/plugin/7973-sonarlint 279 | .idea/**/sonarlint/ 280 | 281 | # SonarQube Plugin 282 | # https://plugins.jetbrains.com/plugin/7238-sonarqube-community-plugin 283 | .idea/**/sonarIssues.xml 284 | 285 | # Markdown Navigator plugin 286 | # https://plugins.jetbrains.com/plugin/7896-markdown-navigator-enhanced 287 | .idea/**/markdown-navigator.xml 288 | .idea/**/markdown-navigator-enh.xml 289 | .idea/**/markdown-navigator/ 290 | 291 | # Cache file creation bug 292 | # See https://youtrack.jetbrains.com/issue/JBR-2257 293 | .idea/$CACHE_FILE$ 294 | 295 | # CodeStream plugin 296 | # https://plugins.jetbrains.com/plugin/12206-codestream 297 | .idea/codestream.xml 298 | 299 | ### Python ### 300 | # Byte-compiled / optimized / DLL files 301 | __pycache__/ 302 | *.py[cod] 303 | *$py.class 304 | 305 | # C extensions 306 | 307 | # Distribution / packaging 308 | .Python 309 | build/ 310 | develop-eggs/ 311 | dist/ 312 | downloads/ 313 | eggs/ 314 | .eggs/ 315 | lib/ 316 | lib64/ 317 | parts/ 318 | sdist/ 319 | var/ 320 | wheels/ 321 | share/python-wheels/ 322 | *.egg-info/ 323 | .installed.cfg 324 | *.egg 325 | MANIFEST 326 | 327 | # PyInstaller 328 | # Usually these files are written by a python script from a template 329 | # before PyInstaller builds the exe, so as to inject date/other infos into it. 330 | *.manifest 331 | *.spec 332 | 333 | # Installer logs 334 | pip-log.txt 335 | pip-delete-this-directory.txt 336 | 337 | # Unit test / coverage reports 338 | htmlcov/ 339 | .tox/ 340 | .nox/ 341 | .coverage 342 | .coverage.* 343 | .cache 344 | nosetests.xml 345 | coverage.xml 346 | *.cover 347 | *.py,cover 348 | .hypothesis/ 349 | .pytest_cache/ 350 | cover/ 351 | 352 | # Translations 353 | *.mo 354 | *.pot 355 | 356 | # Django stuff: 357 | local_settings.py 358 | db.sqlite3 359 | db.sqlite3-journal 360 | 361 | # Flask stuff: 362 | instance/ 363 | .webassets-cache 364 | 365 | # Scrapy stuff: 366 | .scrapy 367 | 368 | # Sphinx documentation 369 | docs/_build/ 370 | 371 | # PyBuilder 372 | .pybuilder/ 373 | target/ 374 | 375 | # Jupyter Notebook 376 | .ipynb_checkpoints 377 | 378 | # IPython 379 | profile_default/ 380 | ipython_config.py 381 | 382 | # pyenv 383 | # For a library or package, you might want to ignore these files since the code is 384 | # intended to run in multiple environments; otherwise, check them in: 385 | # .python-version 386 | 387 | # pipenv 388 | # According to pypa/pipenv#598, it is recommended to include Pipfile.lock in version control. 389 | # However, in case of collaboration, if having platform-specific dependencies or dependencies 390 | # having no cross-platform support, pipenv may install dependencies that don't work, or not 391 | # install all needed dependencies. 392 | #Pipfile.lock 393 | 394 | # PEP 582; used by e.g. github.com/David-OConnor/pyflow 395 | __pypackages__/ 396 | 397 | # Celery stuff 398 | celerybeat-schedule 399 | celerybeat.pid 400 | 401 | # SageMath parsed files 402 | *.sage.py 403 | 404 | # Environments 405 | .env 406 | .venv 407 | env/ 408 | venv/ 409 | ENV/ 410 | env.bak/ 411 | venv.bak/ 412 | 413 | # Spyder project settings 414 | .spyderproject 415 | .spyproject 416 | 417 | # Rope project settings 418 | .ropeproject 419 | 420 | # mkdocs documentation 421 | /site 422 | 423 | # mypy 424 | .mypy_cache/ 425 | .dmypy.json 426 | dmypy.json 427 | 428 | # Pyre type checker 429 | .pyre/ 430 | 431 | # pytype static type analyzer 432 | .pytype/ 433 | 434 | # Cython debug symbols 435 | cython_debug/ 436 | 437 | # End of https://www.toptal.com/developers/gitignore/api/python,pycharm,eclipse,java,intellij+all,c++ 438 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # Complete JavaScript Course 2 | 3 | Modern JavaScript from the very beginning, step-by-step. 4 | 5 | - [Section 1: Welcome, Welcome, Welcome!](https://github.com/formidablae/The_Complete_JavaScript_Course/blob/master/Section_01_-_Welcome,_Welcome,_Welcome!) 6 | - [Section 2: JavaScript Fundamentals - Part 1](https://github.com/formidablae/The_Complete_JavaScript_Course/blob/master/Section_02_-_The_Fondamentals) 7 | - [Section 3: JavaScript Fundamentals - Part 2](https://github.com/formidablae/The_Complete_JavaScript_Course/blob/master/Section_03_-_The_Fondamentals) 8 | - [Section 4: How to Navigate This Course](https://github.com/formidablae/The_Complete_JavaScript_Course/blob/master/Section_04_-_How_to_Navigate_this_Course) 9 | - [Section 5: Developer Skills & Editor Setup](https://github.com/formidablae/The_Complete_JavaScript_Course/blob/master/Section_05_-_Developer_Skills_and_Editor_Setup/) 10 | - [Section 6: HTML & CSS](https://github.com/formidablae/The_Complete_JavaScript_Course/blob/master/Section_06_-_HTML_and_CSS_Crash_Course) 11 | - [Section 7: JavaScript in the Browser: DOM and Events Fundamentals](https://github.com/formidablae/The_Complete_JavaScript_Course/blob/master/Section_07_-_JavaScript_in_the_Browser_DOM_and_Events_Fundamentals) 12 | - [Section 8: How JavaScript Works Behind the Scenes](https://github.com/formidablae/The_Complete_JavaScript_Course/blob/master/Section_08_-_How_JavaScript_Works_Behind_the_Scenes) 13 | - [Section 9: Data Structures, Modern Operators and Strings](https://github.com/formidablae/The_Complete_JavaScript_Course/blob/master/Section_09_-_Data_Structures_Modern_Operators_Strings/) 14 | 15 | -------------------------------------------------------------------------------- /Section_01_-_Welcome,_Welcome,_Welcome!/README.md: -------------------------------------------------------------------------------- 1 | No code in this section 2 | -------------------------------------------------------------------------------- /Section_02_-_The_Fondamentals/00_Browser_console/browser_console.js: -------------------------------------------------------------------------------- 1 | //alert("Hello World!") 2 | console.log("Hello World!") 3 | 4 | let js = "amazing" 5 | if (js === "amazing") { 6 | //alert("JavaScript is FUN!") 7 | console.log("JavaScript is FUN!") 8 | } 9 | 10 | js = "boring" 11 | if (js === "amazing") { 12 | //alert("JavaScript is FUN!") 13 | console.log("JavaScript is FUN!") 14 | } 15 | 16 | console.log(40+8+23-10) 17 | -------------------------------------------------------------------------------- /Section_02_-_The_Fondamentals/01_Linking_a_JavaScript_File/index.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | JavaScript Fundamentals - Part 1 9 | 27 | 28 | 29 | 30 |

JavaScript Fundamentals - Part 1

31 | 32 | 33 | 34 | 35 | 36 | -------------------------------------------------------------------------------- /Section_02_-_The_Fondamentals/01_Linking_a_JavaScript_File/script.js: -------------------------------------------------------------------------------- 1 | let js = "amazing"; 2 | if (js === "amazing") alert("JavaScript is FUN!"); 3 | 4 | console.log(40 + 8 + 23 - 10); 5 | -------------------------------------------------------------------------------- /Section_02_-_The_Fondamentals/02_Values_and_Variables/index.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | JavaScript Fundamentals - Part 1 9 | 27 | 28 | 29 | 30 |

JavaScript Fundamentals - Part 1

31 | 32 | 33 | 34 | 35 | 36 | -------------------------------------------------------------------------------- /Section_02_-_The_Fondamentals/02_Values_and_Variables/script.js: -------------------------------------------------------------------------------- 1 | let js = "amazing"; 2 | console.log(40 + 8 + 23 - 10); 3 | 4 | console.log("Jonas"); 5 | console.log(23); 6 | 7 | let firstName = "Jonas"; 8 | console.log(firstName); 9 | firstName = "Bob"; 10 | console.log(firstName); 11 | firstName = "Jonas"; 12 | console.log(firstName); 13 | console.log(firstName); 14 | console.log(firstName); 15 | firstName = "Matilda"; 16 | console.log(firstName); 17 | 18 | -------------------------------------------------------------------------------- /Section_02_-_The_Fondamentals/03_Variable_name_conventions/index.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | JavaScript Fundamentals - Part 1 9 | 27 | 28 | 29 | 30 |

JavaScript Fundamentals - Part 1

31 | 32 | 33 | 34 | 35 | 36 | -------------------------------------------------------------------------------- /Section_02_-_The_Fondamentals/03_Variable_name_conventions/script.js: -------------------------------------------------------------------------------- 1 | let jonas_matilda = "JM"; 2 | let $function = 27; 3 | let person = "jonas"; 4 | let PI = 3.1415; 5 | let myFirstJob = "Coder"; 6 | let myCurrentJob = "Teacher"; 7 | let job1 = "programmer"; 8 | let job2 = "teacher"; 9 | 10 | console.log(myFirstJob); 11 | 12 | -------------------------------------------------------------------------------- /Section_02_-_The_Fondamentals/04_Practice_Assignments/values_and_variables_assignment.js: -------------------------------------------------------------------------------- 1 | let country = 'France'; 2 | let continent = 'Europe'; 3 | let population = 65; 4 | 5 | console.log(country); 6 | console.log(continent); 7 | console.log(population); 8 | -------------------------------------------------------------------------------- /Section_02_-_The_Fondamentals/05_Data_Types/index.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | JavaScript Fundamentals - Part 1 9 | 27 | 28 | 29 | 30 |

JavaScript Fundamentals - Part 1

31 | 32 | 33 | 34 | 35 | 36 | -------------------------------------------------------------------------------- /Section_02_-_The_Fondamentals/05_Data_Types/script.js: -------------------------------------------------------------------------------- 1 | let javascriptIsFun = true; 2 | console.log(javascriptIsFun); 3 | 4 | console.log(typeof true); 5 | console.log(typeof javascriptIsFun); 6 | console.log(typeof 23); 7 | console.log(typeof "Jonas"); 8 | 9 | javascriptIsFun = "YES!"; 10 | console.log(typeof javascriptIsFun); 11 | console.log(javascriptIsFun); 12 | 13 | let year; 14 | console.log(typeof year); 15 | console.log(year); 16 | 17 | year = 1991; 18 | console.log(typeof year); 19 | console.log(year); 20 | 21 | let someIdentifier = null; 22 | console.log(typeof someIdentifier); // object 23 | console.log(someIdentifier); 24 | -------------------------------------------------------------------------------- /Section_02_-_The_Fondamentals/06_let,_const_and_var/index.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | JavaScript Fundamentals - Part 1 9 | 27 | 28 | 29 | 30 |

JavaScript Fundamentals - Part 1

31 | 32 | 33 | 34 | 35 | 36 | -------------------------------------------------------------------------------- /Section_02_-_The_Fondamentals/06_let,_const_and_var/script.js: -------------------------------------------------------------------------------- 1 | let age = 30; // let is block scoped 2 | age = 31; 3 | 4 | const birthYear = 1991; 5 | // birthYear = 1990; 6 | 7 | // const job; 8 | 9 | var job = "programmer"; // var is function scoped 10 | job = "teacher"; 11 | 12 | lastName = "Schmedtmann"; 13 | console.log(lastName); 14 | 15 | // debugger; 16 | 17 | { 18 | let y = "yes" 19 | 20 | // console.log(x); 21 | let x = "Cooler"; 22 | // debugger; 23 | 24 | hacky = "Great!"; // global and visible afterwards 25 | 26 | if (true) { 27 | // debugger; 28 | let x; 29 | // debugger; 30 | console.log(x); 31 | // debugger; 32 | 33 | x = "Fancy"; 34 | // let x = "Fancy"; 35 | // debugger; 36 | console.log(x); 37 | // debugger; 38 | } 39 | 40 | // debugger; 41 | console.log(x); 42 | } 43 | 44 | // console.log(y); 45 | 46 | let peter = "Hero!"; 47 | 48 | -------------------------------------------------------------------------------- /Section_02_-_The_Fondamentals/07_Basic_Operators/index.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | JavaScript Fundamentals - Part 1 9 | 27 | 28 | 29 | 30 |

JavaScript Fundamentals - Part 1

31 | 32 | 33 | 34 | 35 | 36 | -------------------------------------------------------------------------------- /Section_02_-_The_Fondamentals/07_Basic_Operators/script.js: -------------------------------------------------------------------------------- 1 | // Mathematical operators 2 | const now = 2037; 3 | const ageJonas = now - 1991; 4 | const ageSarah = now - 2020; 5 | console.log(ageJonas, ageSarah); 6 | console.log(ageJonas * 2, ageJonas / 10, 2 ** 3); 7 | // 2 ** 3 means 2 to the power of 3 = 2 * 2 * 2 8 | 9 | const firstName = "Jonas"; 10 | const lastName = "Schmedtmann"; 11 | console.log(firstName + " " + lastName); 12 | 13 | 14 | // Assignment operators 15 | let x = 10 + 5; // x = 15 16 | console.log(x); 17 | x += 10; // x = x + 10 = 25 18 | console.log(x); 19 | x *= 4; // x = x * 4 = 100 20 | console.log(x); 21 | x++; // x = x + 1 = 101 22 | console.log(x); 23 | x--; // x = x - 1 = 100 24 | console.log(x); 25 | x--; // x = x - 1 = 99 26 | console.log(x); 27 | 28 | 29 | // Comparison operators 30 | console.log(ageJonas > ageSarah); // >, <, >=, <= 31 | console.log(ageSarah >= 18); 32 | 33 | const isFullAge = ageSarah >= 18; 34 | 35 | console.log(now - 1991 > now - 2018); 36 | 37 | 38 | // Operator Precedence 39 | // in MDN (Mozilla Developer Network) https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Operators/Operator_Precedence 40 | console.log(now - 1991 > now - 2018); 41 | 42 | let x, y; 43 | x = y = 25 - 10 - 5; // x = y = 10, x = 10 44 | console.log(x, y); 45 | const averageAge = (ageJonas + ageSarah) / 2; 46 | console.log(ageJonas, ageSarah, averageAge); 47 | -------------------------------------------------------------------------------- /Section_02_-_The_Fondamentals/08_Coding_Challenge_01/index.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | JavaScript Fundamentals - Part 1 9 | 27 | 28 | 29 | 30 |

JavaScript Fundamentals - Part 1

31 | 32 | 33 | 34 | 35 | 36 | -------------------------------------------------------------------------------- /Section_02_-_The_Fondamentals/08_Coding_Challenge_01/script.js: -------------------------------------------------------------------------------- 1 | /* 2 | Mark and John are trying to compare their BMI (Body Mass Index), which is calculated using the formula: BMI = mass / height ** 2 = mass / (height * height). (mass in kg and height in meter). 3 | 1. Store Mark's and John's mass and height in variables 4 | 2. Calculate both their BMIs using the formula (you can even implement both versions) 5 | 3. Create a boolean variable 'markHigherBMI' containing information about whether Mark has a higher BMI than John. 6 | TEST DATA 1: Marks weights 78 kg and is 1.69 m tall. John weights 92 kg and is 1.95 m tall. 7 | TEST DATA 2: Marks weights 95 kg and is 1.88 m tall. John weights 85 kg and is 1.76 m tall. 8 | GOOD LUCK 😀 9 | */ 10 | 11 | const massMarkT1 = 78; 12 | const heightMarkT1 = 1.69; 13 | const massJohnT1 = 92; 14 | const heightJohnT1 = 1.95; 15 | 16 | const massMarkT2 = 95; 17 | const heightMarkT2 = 1.88; 18 | const massJohnT2 = 85; 19 | const heightJohnT2 = 1.76; 20 | 21 | const BMIMarkT1 = massMarkT1 / (heightMarkT1 ** 2); 22 | const BMIMarkT2 = massMarkT2 / (heightMarkT2 ** 2); 23 | 24 | const BMIJohnT1 = massJohnT1 / (heightJohnT1 ** 2); 25 | const BMIJohnT2 = massJohnT2 / (heightJohnT2 ** 2); 26 | 27 | const markHigherBMIT1 = BMIMarkT1 > BMIJohnT1; 28 | const markHigherBMIT2 = BMIMarkT2 > BMIJohnT2; 29 | 30 | console.log(BMIMarkT1, BMIJohnT1, markHigherBMIT1); 31 | console.log(BMIMarkT2, BMIJohnT2, markHigherBMIT2); -------------------------------------------------------------------------------- /Section_02_-_The_Fondamentals/09_Strings_and_Template_Literals/index.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | JavaScript Fundamentals - Part 1 9 | 27 | 28 | 29 | 30 |

JavaScript Fundamentals - Part 1

31 | 32 | 33 | 34 | 35 | 36 | -------------------------------------------------------------------------------- /Section_02_-_The_Fondamentals/09_Strings_and_Template_Literals/script.js: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/formidablae/The_Complete_JavaScript_Course/d0a8e4baa61a82d424f8a96d581ae0477e9457e7/Section_02_-_The_Fondamentals/09_Strings_and_Template_Literals/script.js -------------------------------------------------------------------------------- /Section_02_-_The_Fondamentals/10_Taking_Decisions_if_else_statements/index.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | JavaScript Fundamentals - Part 1 9 | 27 | 28 | 29 | 30 |

JavaScript Fundamentals - Part 1

31 | 32 | 33 | 34 | 35 | 36 | -------------------------------------------------------------------------------- /Section_02_-_The_Fondamentals/10_Taking_Decisions_if_else_statements/script.js: -------------------------------------------------------------------------------- 1 | const ageOld = 19; 2 | const age = 15; 3 | const isOldEnough = age >= 18; 4 | 5 | if (age >= 18) { 6 | console.log("Sarah can start a driving licence course 🚗"); 7 | } else { 8 | const yearsLeft = 18 - age; 9 | console.log(`Sarah is too young.` 10 | + `\n` 11 | + `Wait another ${yearsLeft} years`); 12 | } 13 | 14 | const birthYear = 2012; 15 | let century; 16 | if (birthYear <= 2000) { 17 | century = 20; 18 | } else { 19 | century = 21; 20 | } 21 | console.log(century); 22 | -------------------------------------------------------------------------------- /Section_02_-_The_Fondamentals/11_Coding_Challenge_02/index.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | JavaScript Fundamentals - Part 1 9 | 27 | 28 | 29 | 30 |

JavaScript Fundamentals - Part 1

31 | 32 | 33 | 34 | 35 | 36 | -------------------------------------------------------------------------------- /Section_02_-_The_Fondamentals/11_Coding_Challenge_02/script.js: -------------------------------------------------------------------------------- 1 | // Coding Challenge #2 2 | 3 | /* 4 | Use the BMI example from Challenge #1, and the code you already wrote, and improve it: 5 | 1. Print a nice output to the console, saying who has the higher BMI. The message can be either "Mark's BMI is higher than John's!" or "John's BMI is higher than Mark's!" 6 | 2. Use a template literal to include the BMI values in the outputs. Example: "Mark's BMI (28.3) is higher than John's (23.9)!" 7 | HINT: Use an if/else statement 😉 8 | GOOD LUCK 😀 9 | */ 10 | 11 | const massMarkT1 = 78; 12 | const heightMarkT1 = 1.69; 13 | const massJohnT1 = 92; 14 | const heightJohnT1 = 1.95; 15 | 16 | const massMarkT2 = 95; 17 | const heightMarkT2 = 1.88; 18 | const massJohnT2 = 85; 19 | const heightJohnT2 = 1.76; 20 | 21 | const BMIMarkT1 = massMarkT1 / (heightMarkT1 ** 2); 22 | const BMIMarkT2 = massMarkT2 / (heightMarkT2 ** 2); 23 | 24 | const BMIJohnT1 = massJohnT1 / (heightJohnT1 ** 2); 25 | const BMIJohnT2 = massJohnT2 / (heightJohnT2 ** 2); 26 | 27 | console.log(BMIMarkT1, BMIJohnT1); 28 | if (BMIMarkT1 > BMIJohnT1) { 29 | console.log(`Mark's BMI (${BMIMarkT1}) is higher than John's (${BMIJohnT1})!`); 30 | } else { 31 | console.log(`John's BMI (${BMIJohnT1}) is higher than Marks's (${BMIMarkT1})!`); 32 | } 33 | 34 | console.log(BMIMarkT2, BMIJohnT2); 35 | if (BMIMarkT2 > BMIJohnT2) { 36 | console.log(`Mark's BMI (${BMIMarkT2}) is higher than John's (${BMIJohnT2})!`); 37 | } else { 38 | console.log(`John's BMI (${BMIJohnT2}) is higher than Marks's (${BMIMarkT2})!`); 39 | } 40 | -------------------------------------------------------------------------------- /Section_02_-_The_Fondamentals/12_Type_conversion_and_coercion/index.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | JavaScript Fundamentals - Part 1 9 | 27 | 28 | 29 | 30 |

JavaScript Fundamentals - Part 1

31 | 32 | 33 | 34 | 35 | 36 | -------------------------------------------------------------------------------- /Section_02_-_The_Fondamentals/12_Type_conversion_and_coercion/script.js: -------------------------------------------------------------------------------- 1 | // Type corversion (explicit conversion) 2 | const inputYear = "1991"; 3 | console.log(Number(inputYear), inputYear); 4 | console.log(Number(inputYear) + 18); 5 | 6 | console.log(Number('Jonas')); 7 | console.log(typeof NaN); 8 | 9 | console.log(String(23), 23); 10 | 11 | // Type coercion 12 | console.log("I am " + 23 + " years old"); 13 | console.log("I am " + 2 + 3 + " years old"); 14 | console.log("I am " + (2 + 3) + " years old"); 15 | console.log(5 + 23 + " years old"); 16 | console.log("23" - "10" - 3); 17 | console.log("23" + "10" + 3); 18 | console.log(23 + "10" + "3"); 19 | 20 | console.log("23" * "2"); 21 | console.log("23" / "2"); 22 | console.log("23" > "18"); 23 | 24 | let n = "1" + 1; // '11' 25 | console.log(n); 26 | 27 | n = n - 1; 28 | console.log(n); 29 | 30 | console.log(23 + "10" * 2); 31 | console.log("23" * 10 + "2"); 32 | console.log(23 + "10" - 2); 33 | -------------------------------------------------------------------------------- /Section_02_-_The_Fondamentals/13_Truthy_and_Falsy_values/index.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | JavaScript Fundamentals - Part 1 9 | 27 | 28 | 29 | 30 |

JavaScript Fundamentals - Part 1

31 | 32 | 33 | 34 | 35 | 36 | -------------------------------------------------------------------------------- /Section_02_-_The_Fondamentals/13_Truthy_and_Falsy_values/script.js: -------------------------------------------------------------------------------- 1 | // 5 falsy values: 0, "", undefined, null, NaN 2 | 3 | console.log(Boolean(0)); 4 | console.log(Boolean("Jonas")); 5 | console.log(Boolean("")); 6 | console.log(Boolean(null)); 7 | console.log(Boolean(NaN)); 8 | console.log(Boolean(undefined)); 9 | console.log(Boolean({})); // true 10 | 11 | const money1 = 0; 12 | 13 | if (money1) { 14 | console.log("Don't spend it all ;)"); 15 | } else { 16 | console.log("You should get a job!"); 17 | } 18 | 19 | const money2 = 5; 20 | 21 | if (money2) { 22 | console.log("Don't spend it all ;)"); 23 | } else { 24 | console.log("You should get a job!"); 25 | } 26 | 27 | let height1; 28 | if (height1) { 29 | console.log("YAY! Height is defined"); 30 | } else { 31 | console.log("Height is undefined"); 32 | } 33 | 34 | let height2 = 179; 35 | if (height2) { 36 | console.log("YAY! Height is defined"); 37 | } else { 38 | console.log("Height is undefined"); 39 | } 40 | 41 | let height3 = 0; 42 | if (height3) { // wrongly 43 | console.log("YAY! Height is defined"); 44 | } else { 45 | console.log("Height is undefined"); 46 | } 47 | 48 | let height4 = 0; 49 | if (height4 || height4 === 0) { 50 | console.log("YAY! Height is defined"); 51 | } else { 52 | console.log("Height is undefined"); 53 | } 54 | -------------------------------------------------------------------------------- /Section_02_-_The_Fondamentals/14_Equality_operators/index.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | JavaScript Fundamentals - Part 1 9 | 27 | 28 | 29 | 30 |

JavaScript Fundamentals - Part 1

31 | 32 | 33 | 34 | 35 | 36 | -------------------------------------------------------------------------------- /Section_02_-_The_Fondamentals/14_Equality_operators/script.js: -------------------------------------------------------------------------------- 1 | // Equality Operators: == vs. === 2 | 3 | const age1 = 18; 4 | if (age1 === 18) console.log('You just became an adult :D (strict)'); 5 | if (age1 == 18) console.log('You just became an adult :D (loose)'); 6 | 7 | 8 | const age2 = '18'; 9 | if (age2 === 18) console.log('You just became an adult :D (strict)'); 10 | if (age2 == 18) console.log('You just became an adult :D (loose)'); 11 | 12 | const favourite1 = prompt("What's your favourite number?"); 13 | console.log(favourite1); 14 | console.log(typeof favourite1); 15 | 16 | if (favourite1 === 23) { 17 | console.log('Cool! 23 is an amzaing number!') 18 | } else if (favourite1 === 7) { 19 | console.log('7 is also a cool number') 20 | } else if (favourite1 === 9) { 21 | console.log('9 is also a cool number') 22 | } else { 23 | console.log('Number is not 23 or 7 or 9') 24 | } 25 | 26 | if (favourite1 !== 23) console.log('Why not 23?'); 27 | 28 | 29 | const favourite2 = Number(prompt("What's your favourite number?")); 30 | console.log(favourite2); 31 | console.log(typeof favourite2); 32 | 33 | if (favourite2 === 23) { 34 | console.log('Cool! 23 is an amzaing number!') 35 | } else if (favourite2 === 7) { 36 | console.log('7 is also a cool number') 37 | } else if (favourite2 === 9) { 38 | console.log('9 is also a cool number') 39 | } else { 40 | console.log('Number is not 23 or 7 or 9') 41 | } 42 | 43 | if (favourite2 !== 23) console.log('Why not 23?'); 44 | -------------------------------------------------------------------------------- /Section_02_-_The_Fondamentals/15_Logical_Operators/index.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | JavaScript Fundamentals - Part 1 9 | 27 | 28 | 29 | 30 |

JavaScript Fundamentals - Part 1

31 | 32 | 33 | 34 | 35 | 36 | -------------------------------------------------------------------------------- /Section_02_-_The_Fondamentals/15_Logical_Operators/script.js: -------------------------------------------------------------------------------- 1 | // Boolean logic 2 | 3 | const age = 16; 4 | 5 | const a = age >= 20; 6 | const b = age < 30; 7 | 8 | // NOT operator 9 | 10 | console.log(!a); // true 11 | 12 | // AND operator 13 | 14 | console.log(a && b); // false 15 | console.log(!a && b); // true 16 | 17 | // OR operator 18 | 19 | console.log(a || b); // true 20 | console.log(a || !b); // false 21 | 22 | const hasDriversLicence = true; // A 23 | const hasGoodVision = true; // B 24 | 25 | console.log(hasDriversLicence && hasGoodVision); 26 | console.log(hasDriversLicence || hasGoodVision); 27 | console.log(!hasDriversLicence); 28 | 29 | const shouldDrive = hasDriversLicence && hasGoodVision; 30 | 31 | if (shouldDrive) { 32 | console.log("Sarah is able to drive!"); 33 | } else { 34 | console.log("Someone else should drive..."); 35 | } 36 | 37 | if (hasDriversLicence && hasGoodVision) { 38 | console.log("Sarah is able to drive!"); 39 | } else { 40 | console.log("Someone else should drive..."); 41 | } 42 | 43 | const isTired = true; // C 44 | console.log(hasDriversLicence && hasGoodVision && isTired); 45 | 46 | if (hasDriversLicence && hasGoodVision && !isTired) { 47 | console.log("Sarah is able to drive!"); 48 | } else { 49 | console.log("Someone else should drive..."); 50 | } 51 | -------------------------------------------------------------------------------- /Section_02_-_The_Fondamentals/16_Coding_Challenge_03/index.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | JavaScript Fundamentals - Part 1 9 | 27 | 28 | 29 | 30 |

JavaScript Fundamentals - Part 1

31 | 32 | 33 | 34 | 35 | 36 | -------------------------------------------------------------------------------- /Section_02_-_The_Fondamentals/16_Coding_Challenge_03/script.js: -------------------------------------------------------------------------------- 1 | /* 2 | Coding Challenge #3 3 | 4 | There are two gymnastics teams, Dolphins and Koalas. They compete against each 5 | other 3 times. The winner with the highest average score wins a trophy! 6 | 7 | Your tasks: 8 | 1. Calculate the average score for each team, using the test data below 9 | 2. Compare the team's average scores to determine the winner of the competition, 10 | and print it to the console. Don't forget that there can be a draw, so test for that 11 | as well (draw means they have the same average score) 12 | 3. Bonus 1: Include a requirement for a minimum score of 100. With this rule, a 13 | team only wins if it has a higher score than the other team, and the same time a 14 | score of at least 100 points. Hint: Use a logical operator to test for minimum 15 | score, as well as multiple else-if blocks 😉 16 | 4. Bonus 2: Minimum score also applies to a draw! So a draw only happens when 17 | both teams have the same score and both have a score greater or equal 100 18 | points. Otherwise, no team wins the trophy 19 | 20 | Test data: 21 | § Data 1: Dolphins score 96, 108 and 89. Koalas score 88, 91 and 110 22 | § Data Bonus 1: Dolphins score 97, 112 and 101. Koalas score 109, 95 and 123 23 | § Data Bonus 2: Dolphins score 97, 112 and 101. Koalas score 109, 95 and 106 24 | GOOD LUCK 😀 25 | */ 26 | 27 | const dolphinsScores = [96, 108, 89]; 28 | const koalasScores = [88, 91, 110]; 29 | 30 | const averageScoreDolphins = (dolphinsScores.reduce((a, b) => a + b, 0) / dolphinsScores.length) || 0; 31 | const averageScoreKoalas = (koalasScores.reduce((a, b) => a + b, 0) / koalasScores.length) || 0; 32 | 33 | console.log("Average score of the Dolphins = " + averageScoreDolphins + "."); 34 | console.log("Average score of the Koalas = " + averageScoreKoalas + "."); 35 | 36 | console.log(averageScoreDolphins === averageScoreKoalas ? ("Draw! Average score = " + averageScoreDolphins + ".") : ("The winners are the " + (averageScoreDolphins > averageScoreKoalas ? "Dolphins with an average score of = " + averageScoreDolphins : "Koalas with an average score of = " + averageScoreKoalas) + ".")); 37 | 38 | // BONUS 1 39 | console.log("\nBonus 1"); 40 | 41 | const dolphinsScoresBonus1 = [97, 112, 101]; 42 | const koalasScoresBonus1 = [109, 95, 123]; 43 | 44 | const averageScoreDolphinsBonus1 = (dolphinsScoresBonus1.reduce((a, b) => a + b, 0) / dolphinsScoresBonus1.length) || 0; 45 | const averageScoreKoalasBonus1 = (koalasScoresBonus1.reduce((a, b) => a + b, 0) / koalasScoresBonus1.length) || 0; 46 | 47 | console.log("Average score of the Dolphins = " + averageScoreDolphinsBonus1 + "."); 48 | console.log("Average score of the Koalas = " + averageScoreKoalasBonus1 + "."); 49 | 50 | if (averageScoreDolphinsBonus1 === averageScoreKoalasBonus1) { 51 | console.log("Draw! Average score = " + averageScoreDolphinsBonus1 + ".") 52 | } else if (averageScoreDolphinsBonus1 >= 100 && averageScoreKoalasBonus1 >= 100) { 53 | console.log("The winners are the " + (averageScoreDolphinsBonus1 > averageScoreKoalasBonus1 ? ("Dolphins with an average score of = " + averageScoreDolphinsBonus1) : ("Koalas with an average score of = " + averageScoreKoalasBonus1)) + "."); 54 | } else if (averageScoreDolphinsBonus1 >= 100) { 55 | console.log("The winners are the Dolphins with an average score of " + averageScoreDolphinsBonus1 + "."); 56 | } else if (averageScoreKoalasBonus1 >= 100) { 57 | console.log("The winners are the Koalas with an average score of " + averageScoreKoalasBonus1 + "."); 58 | } else { 59 | console.log("No winners. Both the Dolphins and the Koalas have an average score of less than 100 and the scores aren't equal."); 60 | } 61 | 62 | // BONUS 2 63 | console.log("\nBonus 2"); 64 | 65 | const dolphinsScoresBonus2 = [97, 112, 101]; 66 | const koalasScoresBonus2 = [109, 95, 106]; 67 | 68 | const averageScoreDolphinsBonus2 = (dolphinsScoresBonus2.reduce((a, b) => a + b, 0) / dolphinsScores.length) || 0; 69 | const averageScoreKoalasBonus2 = (koalasScoresBonus2.reduce((a, b) => a + b, 0) / koalasScores.length) || 0; 70 | 71 | console.log("Average score of the Dolphins = " + averageScoreDolphinsBonus2 + "."); 72 | console.log("Average score of the Koalas = " + averageScoreKoalasBonus2 + "."); 73 | 74 | if (averageScoreDolphinsBonus2 >= 100 && averageScoreKoalasBonus2 >= 100) { 75 | if (averageScoreDolphinsBonus2 === averageScoreKoalasBonus2) { 76 | console.log("Draw! Average score = " + averageScoreDolphinsBonus2 + ".") 77 | } else { 78 | console.log("The winners are the " + (averageScoreDolphinsBonus2 > averageScoreDolphinsBonus2 ? ("Dolphins with an average score of = " + averageScoreDolphinsBonus2) : ("Koalas with an average score of = " + averageScoreDolphinsBonus2)) + "."); 79 | } 80 | } else if (averageScoreDolphinsBonus2 >= 100) { 81 | console.log("The winners are the Dolphins with an average score of " + averageScoreDolphinsBonus2 + "."); 82 | } else if (averageScoreKoalasBonus2 >= 100) { 83 | console.log("The winners are the Koalas with an average score of " + averageScoreKoalasBonus2 + "."); 84 | } else { 85 | console.log("No winners or draws. Both the Dolphins and the Koalas have an average score of less than 100."); 86 | } 87 | -------------------------------------------------------------------------------- /Section_02_-_The_Fondamentals/17_The_Switch_Statement/index.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | JavaScript Fundamentals - Part 1 9 | 27 | 28 | 29 | 30 |

JavaScript Fundamentals - Part 1

31 | 32 | 33 | 34 | 35 | 36 | -------------------------------------------------------------------------------- /Section_02_-_The_Fondamentals/17_The_Switch_Statement/script.js: -------------------------------------------------------------------------------- 1 | let day = 'monday'; 2 | 3 | switch (day) { 4 | case 'monday': // day === 'monday' 5 | console.log('Plan course structure'); 6 | console.log('Go to coding meetup'); 7 | break; 8 | case 'tuesday': // day === 'tuesday' 9 | console.log('Prepare theory videos'); 10 | break; 11 | case 'wednesday': // day === 'wednesday' 12 | case 'thursday': // day === 'thursday' 13 | console.log('Write code examples'); 14 | break; 15 | case 'friday': // day === 'friday' 16 | console.log('Record videos'); 17 | break; 18 | case 'saturday': // day === 'saturday' 19 | case 'sunday': // day === 'sunday' 20 | console.log('Enjoy the weekend :D'); 21 | default: // not a valid day 22 | console.log('Not a valid day!'); 23 | } 24 | 25 | day = 'wednesday'; 26 | 27 | switch (day) { 28 | case 'monday': // day === 'monday' 29 | console.log('Plan course structure'); 30 | console.log('Go to coding meetup'); 31 | break; 32 | case 'tuesday': // day === 'tuesday' 33 | console.log('Prepare theory videos'); 34 | break; 35 | case 'wednesday': // day === 'wednesday' 36 | case 'thursday': // day === 'thursday' 37 | console.log('Write code examples'); 38 | // break; 39 | case 'friday': // day === 'friday' 40 | console.log('Record videos'); 41 | break; 42 | case 'saturday': // day === 'saturday' 43 | case 'sunday': // day === 'sunday' 44 | console.log('Enjoy the weekend :D'); 45 | break; 46 | default: // not a valid day 47 | console.log('Not a valid day!'); 48 | } 49 | 50 | day = 'holiday'; 51 | 52 | switch (day) { 53 | case 'monday': // day === 'monday' 54 | console.log('Plan course structure'); 55 | console.log('Go to coding meetup'); 56 | break; 57 | case 'tuesday': // day === 'tuesday' 58 | console.log('Prepare theory videos'); 59 | break; 60 | case 'wednesday': // day === 'wednesday' 61 | case 'thursday': // day === 'thursday' 62 | console.log('Write code examples'); 63 | break; 64 | case 'friday': // day === 'friday' 65 | console.log('Record videos'); 66 | break; 67 | case 'saturday': // day === 'saturday' 68 | case 'sunday': // day === 'sunday' 69 | console.log('Enjoy the weekend :D'); 70 | break; 71 | default: // not a valid day 72 | console.log('Not a valid day!'); 73 | } 74 | 75 | if (day === 'monday') { 76 | console.log('Plan course structure'); 77 | console.log('Go to coding meetup'); 78 | } else if (day === 'tuesday') { 79 | console.log('Prepare theory videos'); 80 | } else if (day === 'wednesday' || day === 'thursday') { 81 | console.log('Write code examples'); 82 | } else if (day === 'friday') { 83 | console.log('Record videos'); 84 | } else if (day === 'saturday' || day === 'sunday') { 85 | console.log('Enjoy the weekend :D'); 86 | } else { 87 | console.log('Not a valid day!'); 88 | } -------------------------------------------------------------------------------- /Section_02_-_The_Fondamentals/18_Statements_and_Expressions/index.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | JavaScript Fundamentals - Part 1 9 | 27 | 28 | 29 | 30 |

JavaScript Fundamentals - Part 1

31 | 32 | 33 | 34 | 35 | 36 | -------------------------------------------------------------------------------- /Section_02_-_The_Fondamentals/18_Statements_and_Expressions/script.js: -------------------------------------------------------------------------------- 1 | 3 + 4 2 | 3 | 1991 4 | 5 | true && false && !false 6 | 7 | if (23 > 19) { 8 | const str = '23 is bigger'; 9 | } 10 | 11 | const me = 'Jonas'; 12 | 13 | console.log(`I'm ${2037 - 1991} years old ${me}`); 14 | 15 | -------------------------------------------------------------------------------- /Section_02_-_The_Fondamentals/19_The_Conditional_Ternary_Operator/index.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | JavaScript Fundamentals - Part 1 9 | 27 | 28 | 29 | 30 |

JavaScript Fundamentals - Part 1

31 | 32 | 33 | 34 | 35 | 36 | -------------------------------------------------------------------------------- /Section_02_-_The_Fondamentals/19_The_Conditional_Ternary_Operator/script.js: -------------------------------------------------------------------------------- 1 | const age = 23; 2 | 3 | age >= 18 ? console.log('I like to drive') : console.log('I like to ride'); 4 | 5 | const driveOrRide = age >= 18 ? 'car' : 'bike'; 6 | console.log(driveOrRide); 7 | 8 | let driveOrRide2; 9 | if (age >= 18) { 10 | driveOrRide2 = 'car'; 11 | } else { 12 | driveOrRide2 = 'bike'; 13 | } 14 | console.log(driveOrRide2); 15 | 16 | console.log(`I like to ${age >= 18 ? 'drive cars' : 'ride bikes'}`); 17 | -------------------------------------------------------------------------------- /Section_02_-_The_Fondamentals/20_Coding_Challenge_04/index.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | JavaScript Fundamentals - Part 1 9 | 27 | 28 | 29 | 30 |

JavaScript Fundamentals - Part 1

31 | 32 | 33 | 34 | 35 | 36 | -------------------------------------------------------------------------------- /Section_02_-_The_Fondamentals/20_Coding_Challenge_04/script.js: -------------------------------------------------------------------------------- 1 | /* 2 | Steven wants to build a very simple tip calculator for whenever he goes eating in a restaurant. 3 | In his country, it's usual to tip 15% if the bill value is between 50 and 300. 4 | If the value is different, the tip is 20%. 5 | 6 | Your tasks: 7 | 1. Calculate the tip, depending on the bill value. 8 | Create a variable called 'tip' for this. 9 | It's not allowed to use an if/else statement 😅 10 | (If it's easier for you, you can start with an if/else statement, and then try to convert it to a ternary 11 | operator!) 12 | 13 | 2. Print a string to the console containing the bill value, the tip, and the final value (bill + tip). 14 | Example: “The bill was 275, the tip was 41.25, and the total value 316.25” 15 | 16 | Test data: 17 | Data 1: Test for bill values 275, 40 and 430 18 | 19 | Hints: 20 | To calculate 20% of a value, simply multiply it by 20/100 = 0.2 21 | 22 | Value X is between 50 and 300, if it's >= 50 && <= 300 😉 23 | GOOD LUCK 😀 24 | */ 25 | 26 | let bill = 40; 27 | let tip = bill >= 50 && bill <= 300 ? bill * 0.15 : bill * 0.2; 28 | console.log(`The bill was ${bill}, the tip was ${tip} (which is ${tip / bill * 100}%), and the total value is ${bill + tip}.`); 29 | 30 | bill = 49; 31 | tip = bill >= 50 && bill <= 300 ? bill * 0.15 : bill * 0.2; 32 | console.log(`The bill was ${bill}, the tip was ${tip} (which is ${tip / bill * 100}%), and the total value is ${bill + tip}.`); 33 | 34 | bill = 50; 35 | tip = bill >= 50 && bill <= 300 ? bill * 0.15 : bill * 0.2; 36 | console.log(`The bill was ${bill}, the tip was ${tip} (which is ${tip / bill * 100}%), and the total value is ${bill + tip}.`); 37 | 38 | bill = 51; 39 | tip = bill >= 50 && bill <= 300 ? bill * 0.15 : bill * 0.2; 40 | console.log(`The bill was ${bill}, the tip was ${tip} (which is ${tip / bill * 100}%), and the total value is ${bill + tip}.`); 41 | 42 | bill = 275; 43 | tip = bill >= 50 && bill <= 300 ? bill * 0.15 : bill * 0.2; 44 | console.log(`The bill was ${bill}, the tip was ${tip} (which is ${tip / bill * 100}%), and the total value is ${bill + tip}.`); 45 | 46 | bill = 299; 47 | tip = bill >= 50 && bill <= 300 ? bill * 0.15 : bill * 0.2; 48 | console.log(`The bill was ${bill}, the tip was ${tip} (which is ${tip / bill * 100}%), and the total value is ${bill + tip}.`); 49 | 50 | bill = 300; 51 | tip = bill >= 50 && bill <= 300 ? bill * 0.15 : bill * 0.2; 52 | console.log(`The bill was ${bill}, the tip was ${tip} (which is ${tip / bill * 100}%), and the total value is ${bill + tip}.`); 53 | 54 | bill = 301; 55 | tip = bill >= 50 && bill <= 300 ? bill * 0.15 : bill * 0.2; 56 | console.log(`The bill was ${bill}, the tip was ${tip} (which is ${tip / bill * 100}%), and the total value is ${bill + tip}.`); 57 | 58 | bill = 430; 59 | tip = bill >= 50 && bill <= 300 ? bill * 0.15 : bill * 0.2; 60 | console.log(`The bill was ${bill}, the tip was ${tip} (which is ${tip / bill * 100}%), and the total value is ${bill + tip}.`); 61 | -------------------------------------------------------------------------------- /Section_03_-_The_Fondamentals/01_Activating_Strict_Mode/index.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | JavaScript Fundamentals - Part 2 9 | 27 | 28 | 29 | 30 |

JavaScript Fundamentals - Part 2

31 | 32 | 33 | 34 | 35 | 36 | -------------------------------------------------------------------------------- /Section_03_-_The_Fondamentals/01_Activating_Strict_Mode/script.js: -------------------------------------------------------------------------------- 1 | 'use strict'; 2 | 3 | let hasDriversLicence = false; 4 | const passTest = true; 5 | 6 | if (passTest) { 7 | // hasDriverLicence = true; 8 | hasDriversLicence = true; 9 | } 10 | 11 | if (hasDriversLicence) { 12 | console.log("I can drive :D"); 13 | } 14 | 15 | // const interface = "Audio"; 16 | // const private = 534; -------------------------------------------------------------------------------- /Section_03_-_The_Fondamentals/02_Functions/index.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | JavaScript Fundamentals - Part 2 9 | 27 | 28 | 29 | 30 |

JavaScript Fundamentals - Part 2

31 | 32 | 33 | 34 | 35 | 36 | -------------------------------------------------------------------------------- /Section_03_-_The_Fondamentals/02_Functions/script.js: -------------------------------------------------------------------------------- 1 | 'use strict'; 2 | 3 | function logger() { 4 | console.log("My name is Jonas"); 5 | } 6 | 7 | // calling, running or invoking the function 8 | logger(); 9 | logger(); 10 | logger(); 11 | 12 | function fruitProcessor(apples, oranges) { 13 | // console.log(apples, oranges); 14 | const juice = `Juice with ${apples} apples and ${oranges} oranges.`; 15 | return juice; 16 | } 17 | 18 | fruitProcessor(5, 0); 19 | const appleJuice = fruitProcessor(5, 0); 20 | console.log(appleJuice); 21 | 22 | const appleOrangeJuice = fruitProcessor(2, 4); 23 | console.log(appleOrangeJuice); 24 | const num = Number('23'); 25 | -------------------------------------------------------------------------------- /Section_03_-_The_Fondamentals/03_Function_declarations_vs_expressions/index.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | JavaScript Fundamentals - Part 2 9 | 27 | 28 | 29 | 30 |

JavaScript Fundamentals - Part 2

31 | 32 | 33 | 34 | 35 | 36 | -------------------------------------------------------------------------------- /Section_03_-_The_Fondamentals/03_Function_declarations_vs_expressions/script.js: -------------------------------------------------------------------------------- 1 | 'use strict'; 2 | 3 | // Function Declarations vs. Expressions 4 | 5 | // Function declaration 6 | function calcAge1(birthYear) { 7 | return 2037 - birthYear; 8 | } 9 | 10 | const age1 = calcAge1(1991); 11 | 12 | // Function expression 13 | const calcAge2 = function(birthYear) { 14 | return 2037 - birthYear; 15 | } 16 | 17 | const age2 = calcAge2(1991); 18 | console.log(age1, age2); 19 | -------------------------------------------------------------------------------- /Section_03_-_The_Fondamentals/04_Arrow_functions/index.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | JavaScript Fundamentals - Part 2 9 | 27 | 28 | 29 | 30 |

JavaScript Fundamentals - Part 2

31 | 32 | 33 | 34 | 35 | 36 | -------------------------------------------------------------------------------- /Section_03_-_The_Fondamentals/04_Arrow_functions/script.js: -------------------------------------------------------------------------------- 1 | 'use strict'; 2 | 3 | const calcAge3 = birthYeah => 2037 - birthYeah; 4 | const age3 = calcAge3(1991); 5 | console.log(age3); 6 | 7 | const yearsUntilRetirement1 = birthYeah => { 8 | const age = 2037 - birthYeah; 9 | const retirement = 65 - age; 10 | return retirement; 11 | } 12 | 13 | const yearsUntilRetirement2 = (birthYeah, firstName) => { 14 | const age = 2037 - birthYeah; 15 | const retirement = 65 - age; 16 | 17 | // return retirement; 18 | return `${firstName} retires in ${retirement} years`; 19 | } 20 | 21 | console.log(yearsUntilRetirement1(1994)); 22 | console.log(yearsUntilRetirement2(1991, 'Jonas')); 23 | console.log(yearsUntilRetirement2(1980,'Bob')); 24 | -------------------------------------------------------------------------------- /Section_03_-_The_Fondamentals/05_Functions_calling_other_functions/index.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | JavaScript Fundamentals - Part 2 9 | 27 | 28 | 29 | 30 |

JavaScript Fundamentals - Part 2

31 | 32 | 33 | 34 | 35 | 36 | -------------------------------------------------------------------------------- /Section_03_-_The_Fondamentals/05_Functions_calling_other_functions/script.js: -------------------------------------------------------------------------------- 1 | 'use strict'; 2 | 3 | function cutFruitPieces(fruit) { 4 | return fruit * 4; 5 | } 6 | 7 | function fruitProcessor(apples, oranges) { 8 | const applePieces = cutFruitPieces(apples); 9 | const orangePieces = cutFruitPieces(oranges); 10 | const juice = `Juice with ${applePieces} pieces of apples and ${orangePieces} pieces of oranges.`; 11 | return juice; 12 | } 13 | 14 | console.log(fruitProcessor(2, 3)); 15 | -------------------------------------------------------------------------------- /Section_03_-_The_Fondamentals/06_Reviewing_functions/index.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | JavaScript Fundamentals - Part 2 9 | 27 | 28 | 29 | 30 |

JavaScript Fundamentals - Part 2

31 | 32 | 33 | 34 | 35 | 36 | -------------------------------------------------------------------------------- /Section_03_-_The_Fondamentals/06_Reviewing_functions/script.js: -------------------------------------------------------------------------------- 1 | 'use strict'; 2 | 3 | const calcAge = function (birthYear) { 4 | return 2037 - birthYear; 5 | } 6 | 7 | const yearsUntilRetirement = function (birthYear, firstName) { 8 | const age = calcAge(birthYear); 9 | const retirement = 65 - age; 10 | 11 | if (retirement > 0) { 12 | console.log(`${firstName} retires in ${retirement} years`); 13 | return retirement; 14 | } else { 15 | console.log(`${firstName} has already retired!`); 16 | return -1; 17 | } 18 | } 19 | 20 | console.log(yearsUntilRetirement(1991, 'Jonas')); 21 | console.log(yearsUntilRetirement(1950, 'Mike')); 22 | -------------------------------------------------------------------------------- /Section_03_-_The_Fondamentals/07_Coding_Challenge_01/index.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | JavaScript Fundamentals - Part 2 9 | 27 | 28 | 29 | 30 |

JavaScript Fundamentals - Part 2

31 | 32 | 33 | 34 | 35 | 36 | -------------------------------------------------------------------------------- /Section_03_-_The_Fondamentals/07_Coding_Challenge_01/script.js: -------------------------------------------------------------------------------- 1 | 'use strict'; 2 | 3 | /* 4 | Back to the two gymnastics teams, the Dolphins and the Koalas! There is a new gymnastics discipline, which works differently. 5 | Each team competes 3 times, and then the average of the 3 scores is calculated (so one average score per team). 6 | A team ONLY wins if it has at least DOUBLE the average score of the other team. Otherwise, no team wins! 7 | 8 | Your tasks: 9 | 1. Create an arrow function 'calcAverage' to calculate the average of 3 scores 10 | 2. Use the function to calculate the average for both teams 11 | 3. Create a function 'checkWinner' that takes the average score of each team as parameters ('avgDolphins' and 'avgKoalas'), and then logs the winner to the console, together with the victory points, according to the rule above. Example: "Koalas win (30 vs. 13)". 12 | 4. Use the 'checkWinner' function to determine the winner for both DATA 1 and DATA 2. 13 | 5. Ignore draws this time. 14 | 15 | TEST DATA 1: Dolphins score 44, 23 and 71. Koalas score 65, 54 and 49 16 | TEST DATA 2: Dolphins score 85, 54 and 41. Koalas score 23, 34 and 27 17 | HINT: To calculate average of 3 values, add them all together and divide by 3 18 | HINT: To check if number A is at least double number B, check for A >= 2 * B. Apply this to the team's average scores 😉 19 | GOOD LUCK 😀 20 | */ 21 | 22 | const dolphinsScores1 = [44, 23, 71]; 23 | const koalasScores1 = [65, 54, 49]; 24 | 25 | const calcAverage = (arr) => (arr.reduce((a, b) => a + b, 0) / arr.length) || 0; 26 | 27 | const checkWinner = function (avgDolphins, avgKoalas) { 28 | if (avgDolphins >= 2 * avgKoalas) { 29 | console.log(`Dolphins win (${avgDolphins} vs. ${avgKoalas})`); 30 | } else if (avgKoalas >= 2 * avgDolphins) { 31 | console.log(`Koalas win (${avgKoalas} vs. ${avgDolphins})`); 32 | } else { 33 | console.log('No team wins...'); 34 | } 35 | } 36 | 37 | let scoreDolphins1 = calcAverage(dolphinsScores1); 38 | let scoreKoalas1 = calcAverage(koalasScores1); 39 | console.log("Score of Dolphins 1: ", scoreDolphins1, "\nScore of Koalas 1: ", scoreKoalas1); 40 | 41 | checkWinner(scoreDolphins1, scoreKoalas1); 42 | 43 | const dolphinsScores2 = [85, 54, 41]; 44 | const koalasScores2 = [23, 34, 27]; 45 | 46 | let scoreDolphins2 = calcAverage(dolphinsScores2); 47 | let scoreKoalas2 = calcAverage(koalasScores2); 48 | console.log("Score of Dolphins 1: ", scoreDolphins2, "\nScore of Koalas 1: ", scoreKoalas2); 49 | 50 | checkWinner(scoreDolphins2, scoreKoalas2); 51 | -------------------------------------------------------------------------------- /Section_03_-_The_Fondamentals/08_Introduction_to_Arrays/index.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | JavaScript Fundamentals - Part 2 9 | 27 | 28 | 29 | 30 |

JavaScript Fundamentals - Part 2

31 | 32 | 33 | 34 | 35 | 36 | -------------------------------------------------------------------------------- /Section_03_-_The_Fondamentals/08_Introduction_to_Arrays/script.js: -------------------------------------------------------------------------------- 1 | 'use strict'; 2 | 3 | const friend1 = 'Michael'; 4 | const friend2 = 'Steven'; 5 | const friend3 = 'Peter'; 6 | 7 | const friends = ['Michael', 'Steven', 'Peter']; 8 | console.log(friends); 9 | 10 | const y = new Array(1991, 1984, 2008, 2020); 11 | 12 | console.log(friends[0]); 13 | console.log(friends[2]); 14 | console.log(friends.length); 15 | console.log(friends[friends.length - 1]); 16 | 17 | friends[2] = 'Jay'; 18 | console.log(friends); 19 | 20 | // friends = ['Bob', 'Alice'] 21 | const firstName = 'Jonas'; 22 | const jonas = [firstName, 'Schmedtmann', 2037 - 1991, 'teacher', friends]; 23 | console.log(jonas); 24 | console.log(jonas.length); 25 | 26 | // Exercise 27 | const calcAge = function (birthYeah) { 28 | return 2037 - birthYeah; 29 | } 30 | 31 | const years = [1990, 1967, 2002, 2010, 2018]; 32 | 33 | const age1 = calcAge(years[0]); 34 | const age2 = calcAge(years[1]); 35 | const age3 = calcAge(years[years.length - 1]); 36 | console.log(age1, age2, age3); 37 | 38 | const ages = [calcAge(years[0]), calcAge(years[1]), calcAge(years[years.length - 1])]; 39 | console.log(ages); 40 | -------------------------------------------------------------------------------- /Section_03_-_The_Fondamentals/09_Basic_Array_Operations/index.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | JavaScript Fundamentals - Part 2 9 | 27 | 28 | 29 | 30 |

JavaScript Fundamentals - Part 2

31 | 32 | 33 | 34 | 35 | 36 | -------------------------------------------------------------------------------- /Section_03_-_The_Fondamentals/09_Basic_Array_Operations/script.js: -------------------------------------------------------------------------------- 1 | 'use strict'; 2 | 3 | // Basic Array Operations (Methods) 4 | const friends = ['Michael', 'Steven', 'Peter']; 5 | 6 | // Add elements 7 | const newLength = friends.push('Jay'); 8 | console.log(friends); 9 | console.log(newLength); 10 | 11 | friends.unshift('John'); 12 | console.log(friends); 13 | 14 | // Remove elements 15 | friends.pop(); 16 | const popped = friends.pop(); 17 | console.log(popped); 18 | console.log(friends); 19 | 20 | friends.shift(); 21 | console.log(friends); 22 | console.log(friends.indexOf('Steven')); 23 | console.log(friends.indexOf('Bob')); 24 | 25 | friends.push(23); 26 | console.log(friends.includes('Steven')); 27 | console.log(friends.includes('Bob')); 28 | console.log(friends.includes(23)); 29 | 30 | if (friends.includes('Steven')) { 31 | console.log('You have a friend called Steven'); 32 | } -------------------------------------------------------------------------------- /Section_03_-_The_Fondamentals/10_Coding_Challenge_02/index.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | JavaScript Fundamentals - Part 2 9 | 27 | 28 | 29 | 30 |

JavaScript Fundamentals - Part 2

31 | 32 | 33 | 34 | 35 | 36 | -------------------------------------------------------------------------------- /Section_03_-_The_Fondamentals/10_Coding_Challenge_02/script.js: -------------------------------------------------------------------------------- 1 | 'use strict'; 2 | 3 | /* 4 | Back to the two gymnastics teams, the Dolphins and the Koalas! There is a new gymnastics discipline, which works differently. 5 | /* 6 | Steven is still building his tip calculator, using the same rules as before: Tip 15% of the bill if the bill value is between 50 and 300, and if the value is different, the tip is 20%. 7 | 1. Write a function 'calcTip' that takes any bill value as an input and returns the corresponding tip, calculated based on the rules above (you can check out the code from first tip calculator challenge if you need to). Use the function type you like the most. Test the function using a bill value of 100. 8 | 2. And now let's use arrays! So create an array 'bills' containing the test data below. 9 | 3. Create an array 'tips' containing the tip value for each bill, calculated from the function you created before. 10 | 4. BONUS: Create an array 'total' containing the total values, so the bill + tip. 11 | TEST DATA: 125, 555 and 44 12 | HINT: Remember that an array needs a value in each position, and that value can actually be the returned value of a function! So you can just call a function as array values (so don't store the tip values in separate variables first, but right in the new array) 😉 13 | GOOD LUCK 😀 14 | */ 15 | 16 | const calcTip = function (bill) { 17 | return bill >= 50 && bill <= 300 ? bill * 0.15 : bill * 0.2; 18 | } 19 | const bills = [125, 555, 44]; 20 | const tips = [calcTip(bills[0]), calcTip(bills[1]), calcTip(bills[2])]; 21 | const totals = [bills[0] + tips[0], bills[1] + tips[1], bills[2] + tips[2]]; 22 | console.log(bills, tips, totals); 23 | -------------------------------------------------------------------------------- /Section_03_-_The_Fondamentals/11_Introduction_to_Objects/index.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | JavaScript Fundamentals - Part 2 9 | 27 | 28 | 29 | 30 |

JavaScript Fundamentals - Part 2

31 | 32 | 33 | 34 | 35 | 36 | -------------------------------------------------------------------------------- /Section_03_-_The_Fondamentals/11_Introduction_to_Objects/script.js: -------------------------------------------------------------------------------- 1 | 'use strict'; 2 | 3 | const jonasArray = [ 4 | 'Jonas', 5 | 'Schmedtmann', 6 | 2037 - 1991, 7 | 'teacher', 8 | ['Michael', 'Peter', 'Steven'] 9 | ]; 10 | 11 | const jonasObject = { 12 | firstName: 'Jonas', 13 | lastName: 'Schmedtmann', 14 | age: 2037 - 1991, 15 | job: 'teacher', 16 | friends: ['Michael', 'Peter', 'Steven'] 17 | }; 18 | 19 | console.log("jonasArray:", jonasArray); 20 | console.log("jonasObject:", jonasObject); 21 | 22 | /** 23 | * Dot vs. Bracket Notation 24 | */ 25 | 26 | console.log("Last Name (dot notation):", jonasObject.lastName); 27 | console.log("Last Name (bracket notation):", jonasObject['lastName']); 28 | 29 | const nameKey = 'Name'; 30 | console.log("First Name:", jonasObject['first' + nameKey]); 31 | console.log("Last Name:", jonasObject['last' + nameKey]); 32 | 33 | const interestedIn = prompt("What do you want to know about Jonas? Choose between firstName, lastName, age, job and friends"); 34 | // console.log(jonas.interestedIn); 35 | console.log(jonasObject[interestedIn]); 36 | 37 | if (jonasObject[interestedIn]) { 38 | console.log(jonasObject[interestedIn]); 39 | } else { 40 | console.log('Wrong request! Choose between firstName, lastName, age, job and friends'); 41 | } 42 | jonasObject.location = 'Portugal'; 43 | jonasObject['twitter'] = '@jonasschmedtman'; 44 | console.log(jonasObject); 45 | 46 | /** 47 | * Challenge 48 | * 49 | * Jonas has 3 friends. 50 | * His best friend is called Michael 51 | */ 52 | console.log(`${jonasObject.firstName} has ${jonasObject.friends.length} friends. His best friend is called ${jonasObject.friends[0]}`); 53 | -------------------------------------------------------------------------------- /Section_03_-_The_Fondamentals/12_Object_methods/index.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | JavaScript Fundamentals - Part 2 9 | 27 | 28 | 29 | 30 |

JavaScript Fundamentals - Part 2

31 | 32 | 33 | 34 | 35 | 36 | -------------------------------------------------------------------------------- /Section_03_-_The_Fondamentals/12_Object_methods/script.js: -------------------------------------------------------------------------------- 1 | 'use strict'; 2 | 3 | const jonasObject = { 4 | firstName: 'Jonas', 5 | lastName: 'Schmedtmann', 6 | birthYeah: 1991, 7 | job: 'teacher', 8 | friends: ['Michael', 'Peter', 'Steven'], 9 | hasDriversLicense: true, 10 | 11 | calcAge: function (birthYeah) { 12 | return 2037 - birthYeah; 13 | } 14 | }; 15 | 16 | console.log(jonasObject); 17 | console.log(jonasObject.calcAge(1991)); 18 | console.log(jonasObject['calcAge'](1991)); 19 | console.log(jonasObject.calcAge(jonasObject.birthYeah)); 20 | console.log(jonasObject['calcAge'](jonasObject.birthYeah)); 21 | 22 | const jonasObject2 = { 23 | firstName: 'Jonas', 24 | lastName: 'Schmedtmann', 25 | birthYeah: 1991, 26 | job: 'teacher', 27 | friends: ['Michael', 'Peter', 'Steven'], 28 | hasDriversLicense: true, 29 | 30 | calcAge: function () { 31 | console.log(this); 32 | return 2037 - this.birthYeah; 33 | } 34 | }; 35 | 36 | console.log(jonasObject2); 37 | console.log(jonasObject2.calcAge()); 38 | console.log(jonasObject2['calcAge']()); 39 | 40 | const jonasObject3 = { 41 | firstName: 'Jonas', 42 | lastName: 'Schmedtmann', 43 | birthYeah: 1991, 44 | job: 'teacher', 45 | friends: ['Michael', 'Peter', 'Steven'], 46 | hasDriversLicense: true, 47 | 48 | calcAge: function () { 49 | this.age = 2037 - this.birthYeah; 50 | return this.age; 51 | }, 52 | }; 53 | 54 | console.log(jonasObject3); 55 | console.log(jonasObject3.calcAge()); 56 | console.log(jonasObject3.age); 57 | 58 | // Challenge 59 | // "Jonas is a 45-year old teacher, and he has a driver's license" 60 | const jonasObject4 = { 61 | firstName: 'Jonas', 62 | lastName: 'Schmedtmann', 63 | birthYeah: 1991, 64 | job: 'teacher', 65 | friends: ['Michael', 'Peter', 'Steven'], 66 | hasDriversLicense: true, 67 | 68 | calcAge: function () { 69 | this.age = 2037 - this.birthYeah; 70 | return this.age; 71 | }, 72 | 73 | getSummary: function () { 74 | return `Summary info: ${this.firstName} is a ${this.calcAge()} year old ${this.job} and he has ${this.hasDriversLicense ? 'a' : 'no'} driver's license.` 75 | }, 76 | }; 77 | console.log(jonasObject4.getSummary()); 78 | -------------------------------------------------------------------------------- /Section_03_-_The_Fondamentals/13_Coding_Challenge_03/index.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | JavaScript Fundamentals - Part 2 9 | 27 | 28 | 29 | 30 |

JavaScript Fundamentals - Part 2

31 | 32 | 33 | 34 | 35 | 36 | -------------------------------------------------------------------------------- /Section_03_-_The_Fondamentals/13_Coding_Challenge_03/script.js: -------------------------------------------------------------------------------- 1 | 'use strict'; 2 | 3 | /* 4 | Let's go back to Mark and John comparing their BMIs! This time, let's use objects to implement the calculations! Remember: BMI = mass / height ** 2 = mass / (height * height). (mass in kg and height in meter) 5 | 1. For each of them, create an object with properties for their full name, mass, and height (Mark Miller and John Smith) 6 | 2. Create a 'calcBMI' method on each object to calculate the BMI (the same method on both objects). Store the BMI value to a property, and also return it from the method. 7 | 3. Log to the console who has the higher BMI, together with the full name and the respective BMI. Example: "John Smith's BMI (28.3) is higher than Mark Miller's (23.9)!" 8 | TEST DATA: Marks weights 78 kg and is 1.69 m tall. John weights 92 kg and is 1.95 m tall. 9 | GOOD LUCK 😀 10 | */ 11 | 12 | const mark = { 13 | fullName: 'Mark Miller', 14 | mass: 78, 15 | height: 1.69, 16 | 17 | calcBMI: function () { 18 | this.bmi = this.mass / this.height ** 2; 19 | return this.bmi; 20 | }, 21 | }; 22 | 23 | const john = { 24 | fullName: 'John Smith', 25 | mass: 92, 26 | height: 1.95, 27 | 28 | calcBMI: function () { 29 | this.bmi = this.mass / this.height ** 2; 30 | return this.bmi; 31 | }, 32 | }; 33 | 34 | mark.calcBMI(); 35 | john.calcBMI(); 36 | 37 | console.log( 38 | `${mark.fullName}'s BMI: ${mark.bmi}\n` + 39 | `${mark.fullName}'s MBI: ${john.bmi}` 40 | ); 41 | 42 | // "John Smith's BMI (28.3) is higher than Mark Miller's (23.9)!" 43 | if (mark.bmi > john.bmi) { 44 | console.log( 45 | `${mark.fullName}'s BMI (${mark.bmi}) is higher than ${john.fullName}'s BMI (${john.bmi})` 46 | ); 47 | } else if (john.bmi > mark.bmi) { 48 | console.log( 49 | `${john.fullName}'s BMI (${john.bmi}) is higher than ${mark.fullName}'s BMI (${mark.bmi})` 50 | ); 51 | } 52 | -------------------------------------------------------------------------------- /Section_03_-_The_Fondamentals/14_Iteration_Loops/index.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | JavaScript Fundamentals - Part 2 9 | 27 | 28 | 29 | 30 |

JavaScript Fundamentals - Part 2

31 | 32 | 33 | 34 | 35 | 36 | -------------------------------------------------------------------------------- /Section_03_-_The_Fondamentals/14_Iteration_Loops/script.js: -------------------------------------------------------------------------------- 1 | 'use strict'; 2 | 3 | // Iteration: The for Loop 4 | console.log('Lifting weights repetition 1'); 5 | console.log('Lifting weights repetition 2'); 6 | console.log('Lifting weights repetition 2'); 7 | console.log('Lifting weights repetition 4'); 8 | console.log('Lifting weights repetition 5'); 9 | console.log('Lifting weights repetition 6'); 10 | console.log('Lifting weights repetition 7'); 11 | console.log('Lifting weights repetition 8'); 12 | console.log('Lifting weights repetition 9'); 13 | console.log('Lifting weights repetition 10'); 14 | 15 | // for loop keeps running while condition is TRUE 16 | for (let rep = 1; rep <= 10; rep++) { 17 | console.log(`Lifting weights (with for loop) repetition ${rep}`); 18 | } 19 | 20 | for (let rep = 1; rep <= 30; rep++) { 21 | console.log(`Lifting weights (with for loop v.2) repetition ${rep}`); 22 | } 23 | 24 | // Looping Arrays, Breaking and Continuing 25 | const jonasArray = [ 26 | 'Jonas', 27 | 'Schmedtmann', 28 | 2037 - 1991, 29 | 'teacher', 30 | ['Michael', 'Peter', 'Steven'], 31 | true 32 | ]; 33 | 34 | const types = []; 35 | console.log(jonasArray[0]) 36 | console.log(jonasArray[1]) 37 | // ... 38 | console.log(jonasArray[4]) 39 | // jonas[5] does NOT exist 40 | 41 | for (let i = 0; i < jonasArray.length; i++) { 42 | // Reading from jonas array 43 | console.log(jonasArray[i], typeof jonasArray[i]); 44 | // Filling types array 45 | // types[i] = typeof jonas[i]; 46 | types.push(typeof jonasArray[i]); 47 | } 48 | 49 | console.log(types); 50 | const years = [1991, 2007, 1969, 2020]; 51 | const ages = []; 52 | 53 | for (let i = 0; i < years.length; i++) { 54 | ages.push(2037 - years[i]); 55 | } 56 | 57 | console.log(ages); 58 | 59 | // continue and break 60 | console.log('--- ONLY STRINGS ---'); 61 | for (let i = 0; i < jonasArray.length; i++) { 62 | if (typeof jonasArray[i] !== 'string') { 63 | continue; 64 | } 65 | console.log(jonasArray[i], typeof jonasArray[i]); 66 | } 67 | 68 | console.log('--- BREAK WITH NUMBER ---'); 69 | for (let i = 0; i < jonasArray.length; i++) { 70 | if (typeof jonasArray[i] === 'number') { 71 | break; 72 | } 73 | console.log(jonasArray[i], typeof jonasArray[i]); 74 | } 75 | 76 | // Looping Backwards and Loops in Loops 77 | // 0, 1, ..., 4 78 | // 4, 3, ..., 0 79 | for (let i = jonasArray.length - 1; i >= 0; i--) { 80 | console.log(i, jonasArray[i]); 81 | } 82 | 83 | for (let exercise = 1; exercise < 4; exercise++) { 84 | console.log(`-------- Starting exercise ${exercise}`); 85 | for (let rep = 1; rep < 6; rep++) { 86 | console.log(`Exercise ${exercise}: Lifting weight repetition ${rep}`); 87 | } 88 | } 89 | 90 | // The while Loop 91 | for (let rep = 1; rep <= 10; rep++) { 92 | console.log(`Lifting weights repetition ${rep}`); 93 | } 94 | 95 | let rep = 1; 96 | while (rep <= 10) { 97 | console.log(`WHILE: Lifting weights repetition ${rep}`); 98 | rep++; 99 | } 100 | 101 | let dice = Math.trunc(Math.random() * 6) + 1; 102 | 103 | while (dice !== 6) { 104 | console.log(`You rolled a ${dice}`); 105 | dice = Math.trunc(Math.random() * 6) + 1; 106 | if (dice === 6) { 107 | console.log('Loop is about to end...'); 108 | } 109 | } 110 | -------------------------------------------------------------------------------- /Section_03_-_The_Fondamentals/15_Coding_Challenge_04/index.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | JavaScript Fundamentals - Part 2 9 | 27 | 28 | 29 | 30 |

JavaScript Fundamentals - Part 2

31 | 32 | 33 | 34 | 35 | 36 | -------------------------------------------------------------------------------- /Section_03_-_The_Fondamentals/15_Coding_Challenge_04/script.js: -------------------------------------------------------------------------------- 1 | 'use strict'; 2 | 3 | // Coding Challenge #4 4 | 5 | /* 6 | Let's improve Steven's tip calculator even more, this time using loops! 7 | 1. Create an array 'bills' containing all 10 test bill values 8 | 2. Create empty arrays for the tips and the totals ('tips' and 'totals') 9 | 3. Use the 'calcTip' function we wrote before (no need to repeat) to calculate tips and total values (bill + tip) for every bill value in the bills array. Use a for loop to perform the 10 calculations! 10 | TEST DATA: 22, 295, 176, 440, 37, 105, 10, 1100, 86 and 52 11 | HINT: Call calcTip in the loop and use the push method to add values to the tips and totals arrays 😉 12 | 4. BONUS: Write a function 'calcAverage' which takes an array called 'arr' as an argument. This function calculates the average of all numbers in the given array. This is a DIFFICULT challenge (we haven't done this before)! Here is how to solve it: 13 | 4.1. First, you will need to add up all values in the array. To do the addition, start by creating a variable 'sum' that starts at 0. Then loop over the array using a for loop. In each iteration, add the current value to the 'sum' variable. This way, by the end of the loop, you have all values added together 14 | 4.2. To calculate the average, divide the sum you calculated before by the length of the array (because that's the number of elements) 15 | 4.3. Call the function with the 'totals' array 16 | GOOD LUCK 😀 17 | */ 18 | 19 | 20 | // Solution 21 | const calcTip = function (bill) { 22 | return bill >= 50 && bill <= 300 ? bill * 0.15 : bill * 0.2; 23 | } 24 | 25 | const bills = [22, 295, 176, 440, 37, 105, 10, 1100, 86, 52]; 26 | const tips = []; 27 | const totals = []; 28 | 29 | for (let i = 0; i < bills.length; i++) { 30 | const tip = calcTip(bills[i]); 31 | tips.push(tip); 32 | totals.push(tip + bills[i]); 33 | } 34 | 35 | console.log(bills, tips, totals); 36 | 37 | const calcAverage = function (arr) { 38 | let sum = 0; 39 | 40 | for (let i = 0; i < arr.length; i++) { 41 | // sum = sum + arr[i]; 42 | sum += arr[i]; 43 | } 44 | 45 | return sum / arr.length; 46 | } 47 | 48 | console.log(calcAverage([2, 3, 7])); 49 | console.log(calcAverage(totals)); 50 | console.log(calcAverage(tips)); 51 | -------------------------------------------------------------------------------- /Section_04_-_How_to_Navigate_this_Course/README.md: -------------------------------------------------------------------------------- 1 | No code in this section 2 | -------------------------------------------------------------------------------- /Section_05_-_Developer_Skills_and_Editor_Setup/index.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | Developer Skills & Editor Setup 8 | 25 | 26 | 27 |

Developer Skills & Editor Setup

28 | 29 | 30 | 31 | -------------------------------------------------------------------------------- /Section_05_-_Developer_Skills_and_Editor_Setup/script.js: -------------------------------------------------------------------------------- 1 | 'use strict'; 2 | 3 | const x = 23; 4 | if (x === 23) console.log('x is 23'); 5 | 6 | const calcAge = (birthYear) => 2037 - birthYear; 7 | 8 | // Using Google, StackOverflow and MDN 9 | 10 | // PROBLEM 1: 11 | // We work for a company building a smart home thermometer. Our most recent task is this: "Given an array of temperatures of one day, calculate the temperature amplitude. Keep in mind that sometimes there might be a sensor error." 12 | const temperatures = [3, -2, -6, -1, 'error', 9, 13, 17, 15, 14, 9, 5]; 13 | // 1) Understanding the problem 14 | // - What is temp amplitude? Answer: difference between highest and lowest temp 15 | // - How to compute max and min temperatures? 16 | // - What's a sensor error? And what do do? 17 | // 2) Breaking up into sub-problems 18 | // - How to ignore errors? 19 | // - Find max value in temp array 20 | // - Find min value in temp array 21 | // - Subtract min from max (amplitude) and return it 22 | const calcTempAmplitude = function (temps) { 23 | let max = temps[0]; 24 | let min = temps[0]; 25 | for (let i = 0; i < temps.length; i++) { 26 | if (typeof temps[i] !== 'number') continue; 27 | if (temps[i] > max) max = temps[i]; 28 | if (temps[i] < min) min = temps[i]; 29 | } 30 | console.log(max, min); 31 | return max - min; 32 | }; 33 | 34 | const amplitude = calcTempAmplitude(temperatures); 35 | console.log(amplitude); 36 | 37 | // PROBLEM 2: 38 | // Function should now receive 2 arrays of temps 39 | // 1) Understanding the problem 40 | // - With 2 arrays, should we implement functionality twice? NO! Just merge two arrays 41 | // 2) Breaking up into sub-problems 42 | // - Merge 2 arrays 43 | const calcTempAmplitudeNew = function (t1, t2) { 44 | const temps = t1.concat(t2); 45 | console.log(temps); 46 | let max = temps[0]; 47 | let min = temps[0]; 48 | for (let i = 0; i < temps.length; i++) { 49 | if (typeof temps[i] !== 'number') continue; 50 | if (temps[i] > max) max = temps[i]; 51 | if (temps[i] < min) min = temps[i]; 52 | } 53 | console.log(max, min); 54 | return max - min; 55 | }; 56 | const amplitudeNew = calcTempAmplitudeNew([3, 5, 1], [9, 0, 5]); 57 | console.log(amplitudeNew); 58 | 59 | // Debugging with the Console and Breakpoints 60 | const measureKelvin = function () { 61 | const measurement = { 62 | type: 'temp', 63 | unit: 'celsius', 64 | // C) FIX 65 | // value: Number(prompt('Degrees celsius:')), 66 | value: 10, 67 | }; 68 | // B) FIND 69 | console.table(measurement); 70 | // console.log(measurement.value); 71 | // console.warn(measurement.value); 72 | // console.error(measurement.value); 73 | const kelvin = measurement.value + 273; 74 | return kelvin; 75 | }; 76 | // A) IDENTIFY 77 | console.log(measureKelvin()); 78 | // Using a debugger 79 | const calcTempAmplitudeBug = function (t1, t2) { 80 | const temps = t1.concat(t2); 81 | console.log(temps); 82 | let max = 0; 83 | let min = 0; 84 | for (let i = 0; i < temps.length; i++) { 85 | if (typeof temps[i] !== 'number') continue; 86 | if (temps[i] > max) max = temps[i]; 87 | debugger; 88 | if (temps[i] < min) min = temps[i]; 89 | } 90 | console.log(max, min); 91 | return max - min; 92 | }; 93 | const amplitudeBug = calcTempAmplitudeBug([3, 5, 1], [9, 4, 5]); 94 | // A) IDENTIFY 95 | console.log(amplitudeBug); 96 | 97 | /////////////////////////////////////// 98 | // Coding Challenge #1 99 | 100 | /* 101 | Given an array of forecasted maximum temperatures, the thermometer displays a string with these temperatures. 102 | Example: [17, 21, 23] will print "... 17ºC in 1 days ... 21ºC in 2 days ... 23ºC in 3 days ..." 103 | Create a function 'printForecast' which takes in an array 'arr' and logs a string like the above to the console. 104 | Use the problem-solving framework: Understand the problem and break it up into sub-problems! 105 | TEST DATA 1: [17, 21, 23] 106 | TEST DATA 2: [12, 5, -5, 0, 4] 107 | */ 108 | 109 | // 1) Understanding the problem 110 | // - Array transformed to string, separated by ... 111 | // - What is the X days? Answer: index + 1 112 | // 2) Breaking up into sub-problems 113 | // - Transform array into string 114 | // - Transform each element to string with ºC 115 | // - Strings needs to contain day (index + 1) 116 | // - Add ... between elements and start and end of string 117 | // - Log string to console 118 | const data1 = [17, 21, 23]; 119 | const data2 = [12, 5, -5, 0, 4]; 120 | console.log(`... ${data1[0]}ºC ... ${data1[1]}ºC ... ${data1[2]}ºC ...`); 121 | const printForecast = function (arr) { 122 | let str = ''; 123 | for (let i = 0; i < arr.length; i++) { 124 | str += `${arr[i]}ºC in ${i + 1} days ... `; 125 | } 126 | console.log('...' + str); 127 | }; 128 | printForecast(data1); 129 | -------------------------------------------------------------------------------- /Section_06_-_HTML_and_CSS_Crash_Course/index.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 13 | 14 | Learning HTML & CSS 15 | 16 | 17 |

JavaScript is fun, but so is HTML & CSS

18 |

19 | You can learn JavaScript without HTML and CSS, but for DOM manipulation 20 | it's useful to have some basic ideas of HTML & CSS. You can learn more 21 | about it 22 | here. 23 |

24 | 25 |

Another heading

26 |

27 | Just another paragraph. 28 |

29 | 30 | 31 | 41 |
42 |

You name here

43 |

Please fill in this form :)

44 | 45 | 46 | 47 | 48 | 49 | -------------------------------------------------------------------------------- /Section_06_-_HTML_and_CSS_Crash_Course/style.css: -------------------------------------------------------------------------------- 1 | * { 2 | margin: 0; 3 | padding: 0; 4 | box-sizing: border-box; 5 | } 6 | 7 | body { 8 | background-color: yellow; 9 | font-family: Arial, Helvetica, sans-serif; 10 | font-size: 20px; 11 | padding: 50px; 12 | } 13 | 14 | h1 { 15 | color: purple; 16 | font-size: 40px; 17 | margin-bottom: 25px; 18 | } 19 | 20 | h2 { 21 | color: blue; 22 | margin-bottom: 20px; 23 | text-align: center; 24 | } 25 | 26 | p { 27 | margin-bottom: 20px; 28 | } 29 | 30 | .first { 31 | color: red; 32 | } 33 | 34 | #your-name { 35 | background-color: #f0f8ff; 36 | border: 2px solid purple; 37 | border-radius: 5px; 38 | width: 400px; 39 | padding: 25px; 40 | margin-top: 30px; 41 | } 42 | 43 | input, button { 44 | padding: 10px; 45 | font-size: 16px; 46 | } 47 | 48 | a { 49 | background-color: yellowgreen; 50 | } 51 | 52 | #course-image { 53 | width: 300px; 54 | } 55 | 56 | #your-name h2 { 57 | color: olivedrab; 58 | } 59 | -------------------------------------------------------------------------------- /Section_07_-_JavaScript_in_the_Browser_DOM_and_Events_Fundamentals/1_Guess_My_Number_Project/README.md: -------------------------------------------------------------------------------- 1 | This projects files are in https://github.com/formidablae/guess_my_number 2 | -------------------------------------------------------------------------------- /Section_07_-_JavaScript_in_the_Browser_DOM_and_Events_Fundamentals/2_Modal_Window_Project/README.md: -------------------------------------------------------------------------------- 1 | This project's files are in https://github.com/formidablae/modal_window 2 | -------------------------------------------------------------------------------- /Section_07_-_JavaScript_in_the_Browser_DOM_and_Events_Fundamentals/3_Pig_Game_Project/README.md: -------------------------------------------------------------------------------- 1 | This project's files are in https://github.com/formidablae/pig_game 2 | -------------------------------------------------------------------------------- /Section_08_-_How_JavaScript_Works_Behind_the_Scenes/1_Scoping_in_Practice/index.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | How JavaScript Works Behind the Scenes 9 | 27 | 28 | 29 | 30 |

How JavaScript Works Behind the Scenes

31 | 32 | 33 | 34 | 35 | -------------------------------------------------------------------------------- /Section_08_-_How_JavaScript_Works_Behind_the_Scenes/1_Scoping_in_Practice/script.js: -------------------------------------------------------------------------------- 1 | 'use sctict'; 2 | 3 | // Practicing scoping 4 | 5 | function calcAge(birthYear) { 6 | const age = 2037 - birthYear; 7 | console.log(firstName); 8 | return age; 9 | } 10 | 11 | const firstName = 'Jonas'; 12 | calcAge(1991); 13 | 14 | //////////////////////////////////////////////////////////////////////////////// 15 | 16 | function calcAge2(birthYear2) { 17 | const age2 = 2037 - birthYear2; 18 | 19 | function printAge() { 20 | const output = `${firstName2}, you are ${age2}, born in ${birthYear2}`; 21 | console.log(output); 22 | } 23 | printAge(); 24 | 25 | return age2; 26 | } 27 | 28 | const firstName2 = 'Jonas2'; 29 | calcAge2(1991); 30 | // console.log(age2); 31 | // printAge(); 32 | 33 | //////////////////////////////////////////////////////////////////////////////// 34 | 35 | function calcAge3(birthYear3) { 36 | const age3 = 2037 - birthYear3; 37 | 38 | function printAge3() { 39 | if (birthYear3 >= 1981 && birthYear3 <= 1996) { 40 | var millenial = true; 41 | const str = `Oh, and you're a millenial, ${firstName3}`; 42 | console.log(str); 43 | } 44 | // console.log(str); 45 | console.log(millenial); 46 | } 47 | printAge3(); 48 | 49 | return age3; 50 | } 51 | 52 | const firstName3 = 'Jonas3'; 53 | calcAge3(1991); 54 | 55 | //////////////////////////////////////////////////////////////////////////////// 56 | 57 | function calcAge4(birthYear4) { 58 | const age4 = 2037 - birthYear4; 59 | 60 | function printAge4() { 61 | 62 | if (birthYear4 >= 1981 && birthYear4 <= 1996) { 63 | const firstName4 = 'Steven'; 64 | const str4 = `Oh, and you're a millenial, ${firstName4}`; 65 | console.log(str4); 66 | } 67 | } 68 | printAge4(); 69 | 70 | return age4; 71 | } 72 | 73 | const firstName4 = 'Jonas4'; 74 | calcAge4(1991); 75 | 76 | //////////////////////////////////////////////////////////////////////////////// 77 | 78 | function calcAge5(birthYear5) { 79 | const age5 = 2037 - birthYear5; 80 | 81 | function printAge5() { 82 | let output5 = `${firstName5}, you are ${age5}, born in ${birthYear5}`; 83 | console.log(output5); 84 | 85 | if (birthYear5 >= 1981 && birthYear5 <= 1996) { 86 | output5 = 'New output!d'; 87 | } 88 | 89 | console.log(output5); 90 | } 91 | printAge5(); 92 | 93 | return age5; 94 | } 95 | 96 | const firstName5 = 'Jonas5'; 97 | calcAge5(1991); 98 | -------------------------------------------------------------------------------- /Section_08_-_How_JavaScript_Works_Behind_the_Scenes/2_Hoisting_and_TDZ_in_Practice/index.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | How JavaScript Works Behind the Scenes 9 | 27 | 28 | 29 | 30 |

How JavaScript Works Behind the Scenes

31 | 32 | 33 | 34 | 35 | -------------------------------------------------------------------------------- /Section_08_-_How_JavaScript_Works_Behind_the_Scenes/2_Hoisting_and_TDZ_in_Practice/script.js: -------------------------------------------------------------------------------- 1 | 'use strict'; 2 | 3 | // Hoisting and TDZ in Practice 4 | 5 | // Variables 6 | 7 | console.log(me); 8 | // console.log(job); 9 | // console.log(year); 10 | 11 | var me = 'Jonas'; 12 | let job = 'teacher'; 13 | const year = 1991; 14 | 15 | // Functions 16 | 17 | console.log(addDecl(2, 3)); 18 | // console.log(addExpr(2, 3)); 19 | console.log(addArrow); 20 | // console.log(addArrow(2, 3)); 21 | 22 | function addDecl(a, b) { 23 | return a + b; 24 | } 25 | 26 | const addExpr = function (a, b) { 27 | return a + b; 28 | }; 29 | 30 | var addArrow = (a, b) => a + b; 31 | 32 | // Example 33 | 34 | console.log(numProducts); 35 | if (!numProducts) deleteShoppingCart(); 36 | var numProducts = 10; 37 | 38 | function deleteShoppingCart() { 39 | console.log('All products deleted!'); 40 | } 41 | 42 | var x = 1; 43 | let y = 2; 44 | const z = 3; 45 | console.log(x === window.x); 46 | console.log(y === window.y); 47 | console.log(z === window.z); 48 | -------------------------------------------------------------------------------- /Section_08_-_How_JavaScript_Works_Behind_the_Scenes/3_The_this_Keyword/index.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | How JavaScript Works Behind the Scenes 9 | 27 | 28 | 29 | 30 |

How JavaScript Works Behind the Scenes

31 | 32 | 33 | 34 | 35 | -------------------------------------------------------------------------------- /Section_08_-_How_JavaScript_Works_Behind_the_Scenes/3_The_this_Keyword/script.js: -------------------------------------------------------------------------------- 1 | 'use strict'; 2 | 3 | // The this Keyword in Practice 4 | 5 | console.log(this); 6 | 7 | const calcAge = function (birthYear) { 8 | console.log(2037 - birthYear); 9 | console.log(this); 10 | }; 11 | 12 | calcAge(1991); 13 | 14 | const calcAgeArrow = birthYear => { 15 | console.log(2037 - birthYear); 16 | console.log(this); 17 | }; 18 | 19 | calcAgeArrow(1980); 20 | 21 | const jonas = { 22 | year: 1991, 23 | calcAge: function () { 24 | console.log(this); 25 | console.log(2037 - this.year); 26 | }, 27 | }; 28 | 29 | jonas.calcAge(); 30 | 31 | const matilda = { 32 | year: 2017, 33 | }; 34 | 35 | matilda.calcAge = jonas.calcAge; 36 | 37 | matilda.calcAge(); 38 | 39 | const f = jonas.calcAge; 40 | 41 | f(); 42 | -------------------------------------------------------------------------------- /Section_08_-_How_JavaScript_Works_Behind_the_Scenes/4_Regular_Functions_vs_Arrow_Functions/index.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | How JavaScript Works Behind the Scenes 9 | 27 | 28 | 29 | 30 |

How JavaScript Works Behind the Scenes

31 | 32 | 33 | 34 | 35 | -------------------------------------------------------------------------------- /Section_08_-_How_JavaScript_Works_Behind_the_Scenes/4_Regular_Functions_vs_Arrow_Functions/script.js: -------------------------------------------------------------------------------- 1 | 'use strict'; 2 | 3 | // Regular Functions vs. Arrow Functions 4 | const jonas1 = { 5 | firstName1: 'Jonas', 6 | year1: 1991, 7 | calcAge1: function () { 8 | console.log(this); 9 | console.log(2037 - this.year1); 10 | }, 11 | greet1: () => console.log(`Hey ${this.firstName1}`), 12 | }; 13 | jonas1.greet1(); 14 | 15 | //////////////////////////////////////////////////////////////////////////////// 16 | 17 | var firstName2 = 'Matilda'; 18 | const jonas2 = { 19 | firstName2: 'Jonas', 20 | year2: 1991, 21 | calcAge2: function () { 22 | console.log(this); 23 | console.log(2037 - this.year2); 24 | }, 25 | greet2: () => { 26 | console.log(this); 27 | console.log(`Hey ${this.firstName2}`); 28 | } 29 | }; 30 | jonas2.greet2(); 31 | 32 | //////////////////////////////////////////////////////////////////////////////// 33 | 34 | const jonas3 = { 35 | firstName3: 'Jonas', 36 | year3: 1991, 37 | calcAge3: function () { 38 | console.log(2037 - this.year3); 39 | 40 | function isMillenial3() { 41 | console.log(this); 42 | // console.log(this.year3 >= 1981 && this.year3 <= 1996); 43 | }; 44 | isMillenial3(); 45 | }, 46 | }; 47 | jonas3.calcAge3(); 48 | 49 | //////////////////////////////////////////////////////////////////////////////// 50 | 51 | const jonas4 = { 52 | firstName4: 'Jonas', 53 | year4: 1991, 54 | calcAge4: function () { 55 | console.log(2037 - this.year4); 56 | 57 | const self = this; // self or that 58 | const isMillenial4 = function () { 59 | console.log(self); 60 | console.log(self.year4 >= 1981 && self.year4 <= 1996); 61 | }; 62 | isMillenial4(); 63 | }, 64 | }; 65 | jonas4.calcAge4(); 66 | 67 | //////////////////////////////////////////////////////////////////////////////// 68 | 69 | const jonas5 = { 70 | firstName5: 'Jonas', 71 | year5: 1991, 72 | calcAge5: function () { 73 | console.log(2037 - this.year5); 74 | 75 | const isMillenial5 = () => { 76 | console.log(this); 77 | console.log(this.year5 >= 1981 && this.year5 <= 1996); 78 | }; 79 | isMillenial5(); 80 | }, 81 | }; 82 | jonas5.calcAge5(); 83 | 84 | //////////////////////////////////////////////////////////////////////////////// 85 | 86 | // arguments keyword 87 | 88 | const addExpr = function (a, b) { 89 | console.log(arguments); 90 | return a + b; 91 | }; 92 | 93 | addExpr(2, 5); 94 | addExpr(2, 5, 8, 12); 95 | 96 | var addArrow = (a, b) => { 97 | console.log(arguments); 98 | return a + b; 99 | }; 100 | 101 | // addArrow(2, 5, 8); 102 | -------------------------------------------------------------------------------- /Section_08_-_How_JavaScript_Works_Behind_the_Scenes/5_Objects_vs_Primitives/index.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | How JavaScript Works Behind the Scenes 9 | 27 | 28 | 29 | 30 |

How JavaScript Works Behind the Scenes

31 | 32 | 33 | 34 | 35 | -------------------------------------------------------------------------------- /Section_08_-_How_JavaScript_Works_Behind_the_Scenes/5_Objects_vs_Primitives/script.js: -------------------------------------------------------------------------------- 1 | 'use strict'; 2 | 3 | // Objects vs. primitives 4 | 5 | let age = 30; 6 | let oldAge = age; 7 | 8 | age = 31; 9 | console.log(age); 10 | console.log(oldAge); 11 | 12 | const me = { 13 | name: 'Jonas', 14 | age: 30, 15 | }; 16 | 17 | const friend = me; 18 | friend.age = 27; 19 | 20 | console.log('Friend:', friend); 21 | console.log('Me', me); 22 | 23 | //////////////////////////////////////////////////////////////////////////////// 24 | 25 | // Primitives vs. Objects in Practice 26 | 27 | // Primitive types 28 | let lastName = 'Williams'; 29 | let oldLastName = lastName; 30 | lastName = 'Davis'; 31 | console.log(lastName, oldLastName); 32 | 33 | // Reference types 34 | const jessica = { 35 | firstName: 'Jessica', 36 | lastName: 'Williams', 37 | age: 27, 38 | }; 39 | const marriedJessica = jessica; 40 | marriedJessica.lastName = 'Davis'; 41 | console.log('Before marriage:', jessica); 42 | console.log('After marriage: ', marriedJessica); 43 | // marriedJessica = {}; 44 | 45 | // Copying objects 46 | const jessica2 = { 47 | firstName: 'Jessica2', 48 | lastName: 'Williams2', 49 | age: 27, 50 | }; 51 | const jessicaCopy = Object.assign({}, jessica2); 52 | jessicaCopy.lastName = 'Davis2'; 53 | console.log('Before marriage:', jessica2); 54 | console.log('After marriage: ', jessicaCopy); 55 | 56 | 57 | // Copying objects 58 | const jessica3 = { 59 | firstName3: 'Jessica3', 60 | lastName3: 'Williams3', 61 | age3: 27, 62 | family3: ['Alice3', 'Bob3'], 63 | }; 64 | const jessicaCopy3 = Object.assign({}, jessica3); // shallow copy, copies correctly only first level properties 65 | jessicaCopy3.lastName3 = 'Davis3'; 66 | jessicaCopy3.family3.push('Mary3'); 67 | jessicaCopy3.family3.push('John3'); 68 | console.log('Before marriage3:', jessica3); 69 | console.log('After marriage3: ', jessicaCopy3); 70 | -------------------------------------------------------------------------------- /Section_09_-_Data_Structures_Modern_Operators_Strings/01_Destructuring_Arrays/index.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | Data Structures and Modern Operators 9 | 38 | 39 | 40 | 41 |

Data Structures and Modern Operators

42 | 43 | 44 | 45 | 46 | -------------------------------------------------------------------------------- /Section_09_-_Data_Structures_Modern_Operators_Strings/01_Destructuring_Arrays/script.js: -------------------------------------------------------------------------------- 1 | 'use strict'; 2 | 3 | const restaurant1 = { 4 | name: 'Classico Italiano', 5 | location: 'Via Angelo Tavanti 23, Firenze, Italy', 6 | categories: [ 7 | 'Italian', 8 | 'Pizzeria', 9 | 'Vegetarian', 10 | 'Organic', 11 | ], 12 | starterMenu: [ 13 | 'Focaccia', 14 | 'Bruschetta', 15 | 'Garlic Bread', 16 | 'Caprese Salad', 17 | ], 18 | mainMenu: ['Pizza', 'Pasta', 'Risotto'], 19 | }; 20 | 21 | const arr = [2, 3, 4]; 22 | const a = arr[0]; 23 | const b = arr[1]; 24 | const c = arr[2]; 25 | const [x, y, z] = arr; // destructuring 26 | console.log(x, y, z); 27 | console.log(arr); 28 | 29 | const[first, second] = restaurant1.categories; 30 | console.log(first, second); 31 | 32 | const [frst, , thrd] = restaurant1.categories; 33 | console.log(frst, thrd); 34 | 35 | let [main, , secondary] = restaurant1.categories; 36 | console.log(main, secondary); 37 | 38 | // old way switching values 39 | const temp = main; 40 | main = secondary; 41 | secondary = temp; 42 | 43 | // new way with destructuring 44 | [secondary, main] = [main, secondary]; 45 | console.log(main, secondary); 46 | 47 | //////////////////////////////////////////////////////////////////////////////// 48 | 49 | const restaurant2 = { 50 | name: 'Classico Italiano', 51 | location: 'Via Angelo Tavanti 23, Firenze, Italy', 52 | categories: [ 53 | 'Italian', 54 | 'Pizzeria', 55 | 'Vegetarian', 56 | 'Organic', 57 | ], 58 | starterMenu: [ 59 | 'Focaccia', 60 | 'Bruschetta', 61 | 'Garlic Bread', 62 | 'Caprese Salad', 63 | ], 64 | mainMenu: ['Pizza', 'Pasta', 'Risotto'], 65 | 66 | order: function(starterIndex, mainIndex) { 67 | return [this.starterMenu[starterIndex], this.mainMenu[mainIndex]]; 68 | }, 69 | }; 70 | 71 | console.log('restaurant2.order(2, 0)', restaurant2.order(2, 0)); 72 | const [starter2, mainCourse2] = restaurant2.order(2, 0); 73 | 74 | // nested destructuring 75 | const nested = [2, 4, [5, 6]]; 76 | const [x1, x2] = nested; 77 | console.log(x1, x2); 78 | const [x3, , [x4, x5]] = nested; 79 | console.log(x3, x4, x5); 80 | 81 | // destructuring with default values 82 | const [x6, x7, x8] = [1, 2]; 83 | console.log(x6, x7, x8); 84 | const [x9 = 0, x10 = 0, x11 = 0] = [1, 2]; 85 | console.log(x9, x10, x11); 86 | 87 | // desctructuring objects 88 | const restaurant3 = { 89 | name: 'Classico Italiano', 90 | location: 'Via Angelo Tavanti 23, Firenze, Italy', 91 | categories: ['Italian', 'Pizzeria', 'Vegetarian', 'Organic'], 92 | starterMenu: ['Focaccia', 'Bruschetta', 'Garlic Bread', 'Caprese Salad'], 93 | mainMenu: ['Pizza', 'Pasta', 'Risotto'], 94 | 95 | order: function(starterIndex, mainIndex) { 96 | return [this.starterMenu[starterIndex], this.mainMenu[mainIndex]]; 97 | }, 98 | 99 | openingHours: { 100 | thu: { 101 | open: 12, 102 | close: 22, 103 | }, 104 | fri: { 105 | open: 11, 106 | close: 23, 107 | }, 108 | sat: { 109 | open: 0, // Open 24 hours 110 | close: 24, 111 | }, 112 | }, 113 | }; 114 | 115 | const {name, openingHours, categories} = restaurant3; 116 | console.log(name, openingHours, categories); 117 | 118 | const {name: restaurantName, openingHours: hours, categories: tags} = restaurant3; 119 | console.log(restaurantName, hours, tags); 120 | 121 | // with default values 122 | const { menu = [], starterMenu: starters = [] } = restaurant3; 123 | console.log(menu, starters); 124 | 125 | // mutating variables 126 | let a2 = 111; 127 | let b2 = 999; 128 | const obj = { 129 | a2: 23, 130 | b2: 7, 131 | c2: 14, 132 | }; 133 | // const {a2, b2} = obj; 134 | // let {a2, b2} = obj; 135 | // {a2, b2} = obj; 136 | ({a2, b2} = obj); 137 | console.log(a2, b2); 138 | 139 | // nested objects 140 | const { fri } = openingHours; 141 | console.log(fri); 142 | 143 | const { fri: { open, close } } = openingHours; 144 | console.log(fri, open, close); 145 | 146 | const { fri: { open: op, close: cl } } = openingHours; 147 | console.log(fri, op, cl); 148 | 149 | //////////////////////////////////////////////////////////////////////////////// 150 | 151 | const weekdays4 = ['mon', 'tue', 'wed', 'thu', 'fri', 'sat', 'sun']; 152 | const openingHours4 = { 153 | [weekdays4[3]]: { 154 | open: 12, 155 | close: 22, 156 | }, 157 | [weekdays4[4]]: { 158 | open: 11, 159 | close: 23, 160 | }, 161 | [weekdays4[5]]: { 162 | open: 0, // Open 24 hours 163 | close: 24, 164 | }, 165 | }; 166 | 167 | const restaurant4 = { 168 | name: 'Classico Italiano', 169 | location: 'Via Angelo Tavanti 23, Firenze, Italy', 170 | categories: ['Italian', 'Pizzeria', 'Vegetarian', 'Organic'], 171 | starterMenu: ['Focaccia', 'Bruschetta', 'Garlic Bread', 'Caprese Salad'], 172 | mainMenu: ['Pizza', 'Pasta', 'Risotto'], 173 | 174 | // ES6 enhanced object literals 175 | openingHours4, 176 | 177 | order(starterIndex, mainIndex) { 178 | return [this.starterMenu[starterIndex], this.mainMenu[mainIndex]]; 179 | }, 180 | 181 | orderDelivery({ starterIndex = 1, mainIndex = 0, time = '20:00', address }) { 182 | console.log( 183 | `Order received! ${this.starterMenu[starterIndex]} and ${this.mainMenu[mainIndex]} will be delivered to ${address} at ${time}` 184 | ); 185 | }, 186 | }; 187 | 188 | restaurant4.orderDelivery({ 189 | time: '22:30', 190 | address: 'Via del Sole, 21', 191 | mainIndex: 2, 192 | starterIndex: 2, 193 | }); // allows to pass arguments in any order and with default values 194 | 195 | restaurant4.orderDelivery({ 196 | address: 'Via del Sole, 21', 197 | starterIndex: 1, 198 | }); 199 | -------------------------------------------------------------------------------- /Section_09_-_Data_Structures_Modern_Operators_Strings/02_The_Spread_Operator/index.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | Data Structures and Modern Operators 9 | 38 | 39 | 40 | 41 |

Data Structures and Modern Operators

42 | 43 | 44 | 45 | 46 | -------------------------------------------------------------------------------- /Section_09_-_Data_Structures_Modern_Operators_Strings/02_The_Spread_Operator/script.js: -------------------------------------------------------------------------------- 1 | 'use strict'; 2 | 3 | const arr1 = [7, 8, 9]; 4 | const badNewArr1 = [1, 2, arr1[0], arr1[1], arr1[2]]; 5 | console.log(badNewArr1); 6 | 7 | const newArr1 = [1, 2, ...arr1]; 8 | console.log(newArr1); 9 | 10 | console.log( ...newArr1); 11 | 12 | const restaurant1 = { 13 | name: 'Classico Italiano', 14 | location: 'Via Angelo Tavanti 23, Firenze, Italy', 15 | categories: [ 16 | 'Italian', 17 | 'Pizzeria', 18 | 'Vegetarian', 19 | 'Organic', 20 | ], 21 | starterMenu: [ 22 | 'Focaccia', 23 | 'Bruschetta', 24 | 'Garlic Bread', 25 | 'Caprese Salad', 26 | ], 27 | mainMenu: ['Pizza', 'Pasta', 'Risotto'], 28 | }; 29 | 30 | const newMenu1 = [...restaurant1.mainMenu, 'Gnocchi']; 31 | console.log(newMenu1); 32 | 33 | // copy an array 34 | const mainMenuCopy1 = [...restaurant1.mainMenu]; 35 | 36 | // join two arrays 37 | const mainMenuCopy2 = [...restaurant1.mainMenu, ...restaurant1.starterMenu]; 38 | console.log(mainMenuCopy2); 39 | 40 | const str1 = 'Jonas'; 41 | console.log(...str1); 42 | const letters1 = [...str1, ' ', 'S.']; 43 | console.log(letters1); 44 | // console.log(`${...str1} Schmedtmann`); 45 | 46 | const restaurant2 = { 47 | name: 'Classico Italiano', 48 | location: 'Via Angelo Tavanti 23, Firenze, Italy', 49 | categories: ['Italian', 'Pizzeria', 'Vegetarian', 'Organic'], 50 | starterMenu: ['Focaccia', 'Bruschetta', 'Garlic Bread', 'Caprese Salad'], 51 | mainMenu: ['Pizza', 'Pasta', 'Risotto'], 52 | 53 | order(starterIndex, mainIndex) { 54 | return [this.starterMenu[starterIndex], this.mainMenu[mainIndex]]; 55 | }, 56 | 57 | orderDelivery({ starterIndex = 1, mainIndex = 0, time = '20:00', address }) { 58 | console.log( 59 | `Order received! ${this.starterMenu[starterIndex]} and ${this.mainMenu[mainIndex]} will be delivered to ${address} at ${time}` 60 | ); 61 | }, 62 | 63 | orderPasta(ing1, ing2, ing3) { 64 | console.log( 65 | `Here is your declicious pasta with ${ing1}, ${ing2} and ${ing3}` 66 | ); 67 | }, 68 | 69 | orderPizza(mainIngredient, ...otherIngredients) { 70 | console.log(mainIngredient); 71 | console.log(otherIngredients); 72 | }, 73 | }; 74 | 75 | const ingredients2 = [ 76 | prompt("Let's make pasta! Ingredient 1?"), 77 | prompt("Ingredient 2?"), 78 | prompt("Ingredient 3?"), 79 | ]; 80 | console.log(ingredients2); 81 | 82 | restaurant2.orderPasta(ingredients2[0], ingredients2[1], ingredients2[2]); 83 | restaurant2.orderPasta(...ingredients2); 84 | 85 | // objects 86 | const restaurant3 = { 87 | foundedIn: 1989, 88 | ...restaurant2, 89 | founder: 'Giuseppe', 90 | }; 91 | console.log(restaurant3); 92 | 93 | const restaurant3Copy = {...restaurant3}; 94 | restaurant3Copy.name = 'Ristorante Roma'; 95 | console.log(restaurant3Copy.name); 96 | console.log(restaurant3.name); 97 | -------------------------------------------------------------------------------- /Section_09_-_Data_Structures_Modern_Operators_Strings/03_Rest_patterns_and_parameters/index.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | Data Structures and Modern Operators 9 | 38 | 39 | 40 | 41 |

Data Structures and Modern Operators

42 | 43 | 44 | 45 | 46 | -------------------------------------------------------------------------------- /Section_09_-_Data_Structures_Modern_Operators_Strings/03_Rest_patterns_and_parameters/script.js: -------------------------------------------------------------------------------- 1 | 'use strict'; 2 | 3 | 4 | // spread operator 5 | const arr1 = [1, 2, ...[3, 4]]; 6 | 7 | // rest pattern 8 | const [a1, b1, ...others1] = [1, 2, 3, 4, 5]; 9 | 10 | console.log(a1, b1, others1); 11 | 12 | const restaurant1 = { 13 | name: 'Classico Italiano', 14 | location: 'Via Angelo Tavanti 23, Firenze, Italy', 15 | categories: ['Italian', 'Pizzeria', 'Vegetarian', 'Organic'], 16 | starterMenu: ['Focaccia', 'Bruschetta', 'Garlic Bread', 'Caprese Salad'], 17 | mainMenu: ['Pizza', 'Pasta', 'Risotto'], 18 | 19 | openingHours: { 20 | thu: { 21 | open: 12, 22 | close: 22, 23 | }, 24 | fri: { 25 | open: 11, 26 | close: 23, 27 | }, 28 | sat: { 29 | open: 0, // Open 24 hours 30 | close: 24, 31 | }, 32 | }, 33 | 34 | order: function (starterIndex, mainIndex) { 35 | return [this.starterMenu[starterIndex], this.mainMenu[mainIndex]]; 36 | }, 37 | 38 | orderDelivery: function ({ starterIndex = 1, mainIndex = 0, time = '20:00', address }) { 39 | console.log( 40 | `Order received! ${this.starterMenu[starterIndex]} and ${this.mainMenu[mainIndex]} will be delivered to ${address} at ${time}` 41 | ); 42 | }, 43 | 44 | orderPasta: function (ing1, ing2, ing3) { 45 | console.log( 46 | `Here is your declicious pasta with ${ing1}, ${ing2} and ${ing3}` 47 | ); 48 | }, 49 | 50 | orderPizza: function (mainIngredient, ...otherIngredients) { 51 | console.log(mainIngredient); 52 | console.log(otherIngredients); 53 | }, 54 | }; 55 | 56 | const [pizza, , risotto, ...otherFood] = [...restaurant1.mainMenu, ...restaurant1.starterMenu]; 57 | console.log(pizza, risotto, otherFood); 58 | 59 | // Objects 60 | const { sat, ...weekdays } = restaurant1.openingHours; 61 | console.log(weekdays); 62 | 63 | // 2) Functions 64 | const add = function (...numbers) { 65 | let sum = 0; 66 | for (let i = 0; i < numbers.length; i++) sum += numbers[i]; 67 | console.log(sum); 68 | }; 69 | 70 | add(2, 3); 71 | add(5, 3, 7, 2); 72 | add(8, 2, 5, 3, 2, 1, 4); 73 | 74 | const x2 = [23, 5, 7]; 75 | add(...x2); 76 | restaurant1.orderPizza('mushrooms', 'onion', 'olives', 'spinach'); 77 | restaurant1.orderPizza('mushrooms'); 78 | -------------------------------------------------------------------------------- /Section_09_-_Data_Structures_Modern_Operators_Strings/04_Short_circuiting_&&_and_||/index.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | Data Structures and Modern Operators 9 | 38 | 39 | 40 | 41 |

Data Structures and Modern Operators

42 | 43 | 44 | 45 | 46 | -------------------------------------------------------------------------------- /Section_09_-_Data_Structures_Modern_Operators_Strings/04_Short_circuiting_&&_and_||/script.js: -------------------------------------------------------------------------------- 1 | 'use strict'; 2 | 3 | const restaurant1 = { 4 | name: 'Classico Italiano', 5 | location: 'Via Angelo Tavanti 23, Firenze, Italy', 6 | categories: ['Italian', 'Pizzeria', 'Vegetarian', 'Organic'], 7 | starterMenu: ['Focaccia', 'Bruschetta', 'Garlic Bread', 'Caprese Salad'], 8 | mainMenu: ['Pizza', 'Pasta', 'Risotto'], 9 | 10 | openingHours: { 11 | thu: { 12 | open: 12, 13 | close: 22, 14 | }, 15 | fri: { 16 | open: 11, 17 | close: 23, 18 | }, 19 | sat: { 20 | open: 0, // Open 24 hours 21 | close: 24, 22 | }, 23 | }, 24 | 25 | order: function (starterIndex, mainIndex) { 26 | return [this.starterMenu[starterIndex], this.mainMenu[mainIndex]]; 27 | }, 28 | 29 | orderDelivery: function ({ starterIndex = 1, mainIndex = 0, time = '20:00', address }) { 30 | console.log( 31 | `Order received! ${this.starterMenu[starterIndex]} and ${this.mainMenu[mainIndex]} will be delivered to ${address} at ${time}` 32 | ); 33 | }, 34 | 35 | orderPasta: function (ing1, ing2, ing3) { 36 | console.log( 37 | `Here is your declicious pasta with ${ing1}, ${ing2} and ${ing3}` 38 | ); 39 | }, 40 | 41 | orderPizza: function (mainIngredient, ...otherIngredients) { 42 | console.log(mainIngredient); 43 | console.log(otherIngredients); 44 | }, 45 | }; 46 | 47 | // Short Circuiting (&& and ||) 48 | console.log('---- OR ----'); 49 | 50 | // Use ANY data type, return ANY data type, short-circuiting 51 | console.log(3 || 'Jonas'); 52 | console.log('' || 'Jonas'); 53 | console.log(true || 0); 54 | console.log(undefined || null); 55 | console.log(undefined || 0 || '' || 'Hello' || 23 || null); 56 | restaurant1.numGuests = 0; 57 | const guests1 = restaurant1.numGuests ? restaurant1.numGuests : 10; 58 | console.log(guests1); 59 | const guests2 = restaurant1.numGuests || 10; 60 | console.log(guests2); 61 | 62 | console.log('---- AND ----'); 63 | console.log(0 && 'Jonas'); 64 | console.log(7 && 'Jonas'); 65 | console.log('Hello' && 23 && null && 'jonas'); 66 | 67 | // Practical example 68 | if (restaurant1.orderPizza) { 69 | restaurant1.orderPizza('mushrooms', 'spinach'); 70 | } 71 | restaurant1.orderPizza && restaurant1.orderPizza('mushrooms', 'spinach'); 72 | -------------------------------------------------------------------------------- /all_coding_challenges.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/formidablae/The_Complete_JavaScript_Course/d0a8e4baa61a82d424f8a96d581ae0477e9457e7/all_coding_challenges.pdf --------------------------------------------------------------------------------