From f0468f94e37411aa5da878dec4a5a127fb4b114c Mon Sep 17 00:00:00 2001 From: Bogdan Stashchuk Date: Tue, 23 Oct 2018 13:35:07 +0300 Subject: [PATCH 01/41] Remove .DS_store --- .DS_Store | Bin 6148 -> 0 bytes 1 file changed, 0 insertions(+), 0 deletions(-) delete mode 100644 .DS_Store diff --git a/.DS_Store b/.DS_Store deleted file mode 100644 index 4fed28f7b6b7037ac8da47f498676395e4c4cb7c..0000000000000000000000000000000000000000 GIT binary patch literal 0 HcmV?d00001 literal 6148 zcmeHK%Sr=55Ukb(1G(hralSzC50((WAU_~xMTEc}qMrBUcll{nKahlF@#ICSp{Hhg zx@MR7B};py4k8jvACV_7U{4) zQKJ-)0+$M0=W^rq|AD^H|6h`{k^)lTUnyYSZok{|NmW~CkMmmF=#O;I`J%gV9uy8y lj)_r@x$ts)8%dehe9ry8a7qk1<3T6tXTWulNrAss;2WRX8MOca From d0b7e5787afb7eec2362fce6469f0f21ee96d480 Mon Sep 17 00:00:00 2001 From: Bogdan Stashchuk Date: Tue, 23 Oct 2018 13:39:42 +0300 Subject: [PATCH 02/41] Final code for the branch --- favicon.png | Bin 0 -> 8617 bytes index.html | 22 ++++++++++++++++++++++ 2 files changed, 22 insertions(+) create mode 100644 favicon.png create mode 100644 index.html diff --git a/favicon.png b/favicon.png new file mode 100644 index 0000000000000000000000000000000000000000..0a18ed3b1fd42743e8434aa0e45a9731122f15d9 GIT binary patch literal 8617 zcmc(FWmMGd*Y40DDIg)OARsU>w6uhPNQu%?0}M!acPb##Js6LuNOuoCNJ!_c7>6XO_@fkeG9u8>jkiKc!ung3QpwJb>sGK->OsE(pSauI4Iuy^jq z;j>2quaBTeD(X-wMO-RHHIO1Pi2^YP4lxHOh~s~z5m$%ie|EzE<0k(`!jyk}G0W$qROUL@TK{L!T;^uaC) zb>JH>ScY56q40?^J5FptN5!Jf_l`>fMmlg`In*HQdDOLQb4~lvjdY5aQF%!#Dkm=2 z{bi)!pgII*o2)#$*Z@QtQf`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Nc3_clp0(XI1)8>|d zK+iHqF>RJ%I{(e^fG16sIfn9|w`_LUNEL^^i!V;vs7|YEr{CiXqk(tR@pVqLX7X_l zi$?-V1c@gv79Zz93J~B$q84NTqPtnr-2}0)c3oNfw(&I#Lune|Z3r1^L#?%dUfruR z8wiQiP;m6{l|0{Acqn(_|68@=qL95GeV$9GnO(TU(dpKt_3hFB>qRtqv??);t~9Y5 zGez)=$Q#Pw-E4-z;19onYk4kD6+=&JOHUgqsJjjD00|30gasfF0f^WuVThEdq?D)x zpOBE0kWiNz7x;hc;N)U$Z|nDe?@)CwFB$0Y>~;nZ7h6vsOLrTPx|1c$M$-~z4|QM{ z2aAKB2uQI1JEf4M07Qaa7b4DX=jrJxB`E0Q;{&$8wFcgRHQ2=+mfKu^`%?mj+Yw*c zc{y20Nh!NPy_{^EJ*A{{083H|>zkfyzpji;Zh4d~x>3A#GNG03-VUm`(E)U literal 0 HcmV?d00001 diff --git a/index.html b/index.html new file mode 100644 index 0000000..6e14d5e --- /dev/null +++ b/index.html @@ -0,0 +1,22 @@ + + + + + + + + + JavaScript embedded into the HTML + + + + + + + \ No newline at end of file From f878fd716db2d3e1b67980decb62601770ea87a2 Mon Sep 17 00:00:00 2001 From: Bogdan Stashchuk Date: Tue, 23 Oct 2018 14:26:59 +0300 Subject: [PATCH 03/41] Final --- index.html | 8 +------- index.js | 1 + 2 files changed, 2 insertions(+), 7 deletions(-) create mode 100644 index.js diff --git a/index.html b/index.html index 6e14d5e..b77bd0c 100644 --- a/index.html +++ b/index.html @@ -10,13 +10,7 @@ - + \ No newline at end of file diff --git a/index.js b/index.js new file mode 100644 index 0000000..68548f9 --- /dev/null +++ b/index.js @@ -0,0 +1 @@ +console.log("Hello from external JavaScript file"); \ No newline at end of file From 4a3d4e4fe45a39800ae7c1b659ed76da7d4f9557 Mon Sep 17 00:00:00 2001 From: Bogdan Stashchuk Date: Thu, 25 Oct 2018 08:06:14 +0300 Subject: [PATCH 04/41] Final --- index.html | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/index.html b/index.html index b77bd0c..e0df346 100644 --- a/index.html +++ b/index.html @@ -6,7 +6,7 @@ - JavaScript embedded into the HTML + JavaScript Basics From 95bab3d868a5ea694f7978925a197ddbb594a764 Mon Sep 17 00:00:00 2001 From: Bogdan Stashchuk Date: Mon, 29 Oct 2018 12:19:33 +0200 Subject: [PATCH 05/41] Start --- index.js | 1 - 1 file changed, 1 deletion(-) diff --git a/index.js b/index.js index 68548f9..e69de29 100644 --- a/index.js +++ b/index.js @@ -1 +0,0 @@ -console.log("Hello from external JavaScript file"); \ No newline at end of file From 34b8edd1497b14d8ce2d18c32fabbbd2a2c34536 Mon Sep 17 00:00:00 2001 From: Bogdan Stashchuk Date: Tue, 30 Oct 2018 09:49:19 +0200 Subject: [PATCH 06/41] Final --- index.js | 117 +++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 117 insertions(+) diff --git a/index.js b/index.js index e69de29..3645fb4 100644 --- a/index.js +++ b/index.js @@ -0,0 +1,117 @@ +// /** +// * EXAMPLE 1 - Variable declaration +// */ +// var a; + +// console.log(a); + +// // console.log(b); // Uncaught ReferenceError: b is not defined + +// let c; + +// console.log(c); + +// // const d; // Uncaught SyntaxError: Missing initializer in const declaration + +// /** +// * EXAMPLE 2 - "let" +// */ +// let myNumber = 10; + +// console.log(myNumber); + +// // declaration +// let myString; + +// console.log(myString); + +// // assignment +// myString = "Hello from String"; + +// console.log(myString); + +// // re-assignment +// myString = "New value for myString variable"; + +// console.log(myString); + +// /** +// * EXAMPLE 3 - "var" +// */ +// var myNumber = 10; + +// console.log(myNumber); + +// // declaration +// var myString; + +// console.log(myString); + +// // assignment +// myString = "Hello from String"; + +// console.log(myString); + +// // re-assignment +// myString = "New value for myString variable"; + +// console.log(myString); + +// /** +// * EXAMPLE 4 - "const" +// */ +// const myBoolean = true; + +// console.log(myBoolean); + +// // myBoolean = false; // Assignment to constant variable. + +// // const myBoolean = false; // Uncaught SyntaxError: Identifier 'myBoolean' has already been declared + +// /** +// * CHALLENGE 1 +// * +// * Declare variable "myObject" and assign value {}. +// * Print this variable to the console. +// * NOTE: variable "myObject" will NOT be reassigned in the future +// */ +// const myObject = {}; + +// console.log(myObject); + +// // myObject = {}; // Uncaught TypeError: Assignment to constant variable. + +// /** +// * CHALLENGE 2 +// * Declare "x" and assign value 10 to it. +// * Declare "y" and assign value true to it +// * Declare "myObject" and assign object with two name-value pairs +// * Declare "anotherObject". +// * Later assign value to it - object with three name-value pairs +// */ +// let x = 10; +// const y = true; +// const myObject = { +// a: x, +// b: y +// }; +// console.log(myObject); +// /** +// * {a: 10, b: true, __proto__: Object} +// */ +// x = 20; +// let anotherObject; +// anotherObject = { +// newA: x, +// b: y, +// c: myObject +// }; +// console.log(anotherObject); +// /** +// * { +// * newA: 20, +// * b: true, +// * c: {a: 10, b: true, __proto__: Object}, +// * __proto__: Object +// * } +// */ \ No newline at end of file From 900c9808053255f73d45fbc730d4ee4dc0fdaded Mon Sep 17 00:00:00 2001 From: Bogdan Stashchuk Date: Tue, 30 Oct 2018 13:29:23 +0200 Subject: [PATCH 07/41] Start --- index.js | 117 ------------------------------------------------------- 1 file changed, 117 deletions(-) diff --git a/index.js b/index.js index 3645fb4..e69de29 100644 --- a/index.js +++ b/index.js @@ -1,117 +0,0 @@ -// /** -// * EXAMPLE 1 - Variable declaration -// */ -// var a; - -// console.log(a); - -// // console.log(b); // Uncaught ReferenceError: b is not defined - -// let c; - -// console.log(c); - -// // const d; // Uncaught SyntaxError: Missing initializer in const declaration - -// /** -// * EXAMPLE 2 - "let" -// */ -// let myNumber = 10; - -// console.log(myNumber); - -// // declaration -// let myString; - -// console.log(myString); - -// // assignment -// myString = "Hello from String"; - -// console.log(myString); - -// // re-assignment -// myString = "New value for myString variable"; - -// console.log(myString); - -// /** -// * EXAMPLE 3 - "var" -// */ -// var myNumber = 10; - -// console.log(myNumber); - -// // declaration -// var myString; - -// console.log(myString); - -// // assignment -// myString = "Hello from String"; - -// console.log(myString); - -// // re-assignment -// myString = "New value for myString variable"; - -// console.log(myString); - -// /** -// * EXAMPLE 4 - "const" -// */ -// const myBoolean = true; - -// console.log(myBoolean); - -// // myBoolean = false; // Assignment to constant variable. - -// // const myBoolean = false; // Uncaught SyntaxError: Identifier 'myBoolean' has already been declared - -// /** -// * CHALLENGE 1 -// * -// * Declare variable "myObject" and assign value {}. -// * Print this variable to the console. -// * NOTE: variable "myObject" will NOT be reassigned in the future -// */ -// const myObject = {}; - -// console.log(myObject); - -// // myObject = {}; // Uncaught TypeError: Assignment to constant variable. - -// /** -// * CHALLENGE 2 -// * Declare "x" and assign value 10 to it. -// * Declare "y" and assign value true to it -// * Declare "myObject" and assign object with two name-value pairs -// * Declare "anotherObject". -// * Later assign value to it - object with three name-value pairs -// */ -// let x = 10; -// const y = true; -// const myObject = { -// a: x, -// b: y -// }; -// console.log(myObject); -// /** -// * {a: 10, b: true, __proto__: Object} -// */ -// x = 20; -// let anotherObject; -// anotherObject = { -// newA: x, -// b: y, -// c: myObject -// }; -// console.log(anotherObject); -// /** -// * { -// * newA: 20, -// * b: true, -// * c: {a: 10, b: true, __proto__: Object}, -// * __proto__: Object -// * } -// */ \ No newline at end of file From 169c1c54f520c6a464ffa734a4cd5a326a7acf3e Mon Sep 17 00:00:00 2001 From: Bogdan Stashchuk Date: Tue, 30 Oct 2018 15:44:49 +0200 Subject: [PATCH 08/41] Final --- index.js | 29 +++++++++++++++++++++++++++++ 1 file changed, 29 insertions(+) diff --git a/index.js b/index.js index e69de29..26fef89 100644 --- a/index.js +++ b/index.js @@ -0,0 +1,29 @@ +let myVariable; + +console.log(myVariable); // undefined + +myVariable = 10; + +console.log(myVariable); // 10 + +myVariable = true; + +console.log(myVariable); // true + +myVariable = { + x: true, + y: 10 +}; + +console.log(myVariable); // {x: true, y: 10} + +myVariable.y = 20; + +console.log(myVariable); // {x: true, y: 20} + +// // THIS WILL BREAK THE CODE +// myVariable = null; + +myVariable.x = false; // Uncaught TypeError: Cannot set property 'x' of null + +console.log(myVariable); // {x: false, y: 20} \ No newline at end of file From 79e62765a306727aa9522a8a04cd7354f26bbab3 Mon Sep 17 00:00:00 2001 From: Bogdan Stashchuk Date: Thu, 1 Nov 2018 10:03:41 +0200 Subject: [PATCH 09/41] Start --- index.js | 29 ----------------------------- 1 file changed, 29 deletions(-) diff --git a/index.js b/index.js index 26fef89..e69de29 100644 --- a/index.js +++ b/index.js @@ -1,29 +0,0 @@ -let myVariable; - -console.log(myVariable); // undefined - -myVariable = 10; - -console.log(myVariable); // 10 - -myVariable = true; - -console.log(myVariable); // true - -myVariable = { - x: true, - y: 10 -}; - -console.log(myVariable); // {x: true, y: 10} - -myVariable.y = 20; - -console.log(myVariable); // {x: true, y: 20} - -// // THIS WILL BREAK THE CODE -// myVariable = null; - -myVariable.x = false; // Uncaught TypeError: Cannot set property 'x' of null - -console.log(myVariable); // {x: false, y: 20} \ No newline at end of file From 7532f397672303c7a64b7af47091bbdccb774a7b Mon Sep 17 00:00:00 2001 From: Bogdan Stashchuk Date: Thu, 1 Nov 2018 13:49:24 +0200 Subject: [PATCH 10/41] Final --- index.js | 158 +++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 158 insertions(+) diff --git a/index.js b/index.js index e69de29..2e73526 100644 --- a/index.js +++ b/index.js @@ -0,0 +1,158 @@ +// /** +// * EXAMPLE 1 - Create object and modify its properties +// */ +// let myObject; + +// myObject = { +// a: 10, +// b: "abc" +// }; + +// console.log(myObject); + +// myObject.a = 15; + +// console.log(myObject); + +// myObject.c = true; + +// console.log(myObject); + +// delete myObject.b; + +// console.log(myObject); + +// console.log(myObject.a); + +// /** +// * CHALLENGE 1 +// * +// * Create variable called "myPost". +// * Initial value should be {} +// * Add property called "postTitle" and value "Object is reference type" +// * Add one more property "postLikes" with value 0 +// * Add third property "shared" and set its value to "false" +// * Increase value of the "postLikes" by 1 +// * Delete property "shared" +// */ +// let myPost = {}; + +// myPost.postTitle = "Object is reference type"; + +// myPost.postLikes = 0; + +// myPost.shared = false; + +// console.log(myPost); + +// myPost.postLikes = myPost.postLikes + 1; + +// console.log(myPost); + +// delete myPost.shared; + +// console.log(myPost); + +// /** +// * EXAMPLE 2 +// * +// * Use "const" for object declaration +// */ +// const myObject = {}; + +// myObject.a = true; // NO ERROR! Variable is not reassigned + +// console.log(myObject); + +// myObject = { +// a: true +// }; // Uncaught TypeError: Assignment to constant variable. + +// /** +// * CHALLENGE 2 +// * +// * Create variable "myObject" and add property "a" - 10. +// * Create another variable "copyOfMyObject" and its value should be myObject. +// * Add new property "b" with value false to the "copyOfMyObject". +// * Print to the console "myObject" and "copyOfMyObject" and interpret results. +// */ +// let myObject = { +// a: 10 +// }; +// let copyOfMyObject = myObject; + +// copyOfMyObject.b = false; + +// console.log(myObject); +// console.log(copyOfMyObject); + +// /** +// * EXAMPLE 3 +// * +// * Bracket notation +// */ +// let myObject = { +// a: true, +// b: null, +// c: 25 +// }; + +// console.log(myObject["a"]); // true + +// // console.log(myObject[a]); // Uncaught ReferenceError: a is not defined + +// console.log(myObject["b"]); // null + +// const propertyName = "c"; + +// console.log(myObject[propertyName]); // 25 + +// console.log(myObject["propertyName"]); // undefined + +// myObject["new" + "Property" + "Name"] = "Value for dynamically computed property name"; + +// console.log(myObject); + +// /** +// * EXAMPLE 4 +// * +// * Missing properties +// */ +// const myObject = { +// a: 3, +// b: true +// }; + +// // Code exectuion is not stopped +// console.log(myObject.c); // undefined + +// console.log(myObject.absentProperty); // undefined + +// // // Code exectuion is STOPPED +// // console.log(nonDeclaredVariable); // Uncaught ReferenceError: nonDeclaredVariable is not defined + +// // IMPORTANT!!! +// // NEVER ASSIGN "undefined" to any property or variable. Use "null" instead +// myObject.newPropertyWithUndefinedValue = undefined; + +// console.log(myObject); +// console.log(myObject.newPropertyWithUndefinedValue); + +// /** +// * CHALLENGE 3 +// * +// * Create object "objectWithNestedObject" with initial value {}. +// * Add property "nestedObject" with initial value {}. +// * Add property "a" with value "null" to "nestedObject". Use dot notation +// * Add property "b" with value "true" to "nestedObject". Use bracket notation. Create new variable with property name +// */ +// let objectWithNestedObject = {}; +// objectWithNestedObject.nestedObject = {}; + +// objectWithNestedObject.nestedObject.a = null; + +// const newPropertyName = "b"; + +// objectWithNestedObject.nestedObject[newPropertyName] = true; + +// console.log(objectWithNestedObject); \ No newline at end of file From a8c7bb4cf808d4fbced49ec117792830bee61262 Mon Sep 17 00:00:00 2001 From: Bogdan Stashchuk Date: Sun, 4 Nov 2018 22:29:58 +0200 Subject: [PATCH 11/41] Fix typo --- index.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/index.js b/index.js index 2e73526..0d5c9bf 100644 --- a/index.js +++ b/index.js @@ -123,12 +123,12 @@ // b: true // }; -// // Code exectuion is not stopped +// // Code execution is not stopped // console.log(myObject.c); // undefined // console.log(myObject.absentProperty); // undefined -// // // Code exectuion is STOPPED +// // // Code execution is STOPPED // // console.log(nonDeclaredVariable); // Uncaught ReferenceError: nonDeclaredVariable is not defined // // IMPORTANT!!! From 26f38b1b753729ad23365cd9d9ce94cc8a314895 Mon Sep 17 00:00:00 2001 From: Bogdan Stashchuk Date: Mon, 5 Nov 2018 12:01:43 +0200 Subject: [PATCH 12/41] Start --- index.js | 158 ------------------------------------------------------- 1 file changed, 158 deletions(-) diff --git a/index.js b/index.js index 0d5c9bf..e69de29 100644 --- a/index.js +++ b/index.js @@ -1,158 +0,0 @@ -// /** -// * EXAMPLE 1 - Create object and modify its properties -// */ -// let myObject; - -// myObject = { -// a: 10, -// b: "abc" -// }; - -// console.log(myObject); - -// myObject.a = 15; - -// console.log(myObject); - -// myObject.c = true; - -// console.log(myObject); - -// delete myObject.b; - -// console.log(myObject); - -// console.log(myObject.a); - -// /** -// * CHALLENGE 1 -// * -// * Create variable called "myPost". -// * Initial value should be {} -// * Add property called "postTitle" and value "Object is reference type" -// * Add one more property "postLikes" with value 0 -// * Add third property "shared" and set its value to "false" -// * Increase value of the "postLikes" by 1 -// * Delete property "shared" -// */ -// let myPost = {}; - -// myPost.postTitle = "Object is reference type"; - -// myPost.postLikes = 0; - -// myPost.shared = false; - -// console.log(myPost); - -// myPost.postLikes = myPost.postLikes + 1; - -// console.log(myPost); - -// delete myPost.shared; - -// console.log(myPost); - -// /** -// * EXAMPLE 2 -// * -// * Use "const" for object declaration -// */ -// const myObject = {}; - -// myObject.a = true; // NO ERROR! Variable is not reassigned - -// console.log(myObject); - -// myObject = { -// a: true -// }; // Uncaught TypeError: Assignment to constant variable. - -// /** -// * CHALLENGE 2 -// * -// * Create variable "myObject" and add property "a" - 10. -// * Create another variable "copyOfMyObject" and its value should be myObject. -// * Add new property "b" with value false to the "copyOfMyObject". -// * Print to the console "myObject" and "copyOfMyObject" and interpret results. -// */ -// let myObject = { -// a: 10 -// }; -// let copyOfMyObject = myObject; - -// copyOfMyObject.b = false; - -// console.log(myObject); -// console.log(copyOfMyObject); - -// /** -// * EXAMPLE 3 -// * -// * Bracket notation -// */ -// let myObject = { -// a: true, -// b: null, -// c: 25 -// }; - -// console.log(myObject["a"]); // true - -// // console.log(myObject[a]); // Uncaught ReferenceError: a is not defined - -// console.log(myObject["b"]); // null - -// const propertyName = "c"; - -// console.log(myObject[propertyName]); // 25 - -// console.log(myObject["propertyName"]); // undefined - -// myObject["new" + "Property" + "Name"] = "Value for dynamically computed property name"; - -// console.log(myObject); - -// /** -// * EXAMPLE 4 -// * -// * Missing properties -// */ -// const myObject = { -// a: 3, -// b: true -// }; - -// // Code execution is not stopped -// console.log(myObject.c); // undefined - -// console.log(myObject.absentProperty); // undefined - -// // // Code execution is STOPPED -// // console.log(nonDeclaredVariable); // Uncaught ReferenceError: nonDeclaredVariable is not defined - -// // IMPORTANT!!! -// // NEVER ASSIGN "undefined" to any property or variable. Use "null" instead -// myObject.newPropertyWithUndefinedValue = undefined; - -// console.log(myObject); -// console.log(myObject.newPropertyWithUndefinedValue); - -// /** -// * CHALLENGE 3 -// * -// * Create object "objectWithNestedObject" with initial value {}. -// * Add property "nestedObject" with initial value {}. -// * Add property "a" with value "null" to "nestedObject". Use dot notation -// * Add property "b" with value "true" to "nestedObject". Use bracket notation. Create new variable with property name -// */ -// let objectWithNestedObject = {}; -// objectWithNestedObject.nestedObject = {}; - -// objectWithNestedObject.nestedObject.a = null; - -// const newPropertyName = "b"; - -// objectWithNestedObject.nestedObject[newPropertyName] = true; - -// console.log(objectWithNestedObject); \ No newline at end of file From a5e24b88647703904047dd98da6f4ff79fa95553 Mon Sep 17 00:00:00 2001 From: Bogdan Stashchuk Date: Sat, 10 Nov 2018 18:10:01 +0200 Subject: [PATCH 13/41] Examples added --- index.js | 105 +++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 105 insertions(+) diff --git a/index.js b/index.js index e69de29..231366b 100644 --- a/index.js +++ b/index.js @@ -0,0 +1,105 @@ +// /** +// * EXAMPLE 1 +// * +// * Simplest function in JavaScript +// */ +// function myFunction() {} + +// console.log(myFunction); // myFunction() {} + +// myFunction(); + +// const functionResult = myFunction(); + +// console.log(functionResult); // undefined + +// console.log(myFunction()); // undefined + +// console.log(myFunction(10, true)); // undefined + +// /** +// * EXAMPLE 2 +// * +// * Parameters of the function +// */ +// function myFunction(a, b) { +// console.log(a); +// console.log(b); +// } + +// myFunction(10, 5); // 10, 5 + +// myFunction(true, null); // true, null + +// myFunction(); // undefined, undefined + +// myFunction("abc"); // abc, undefined + +// console.log(myFunction(4, 3)); // undefined + +// /** +// * EXAMPLE 3 +// * +// * Function scope +// */ +// function myFunction(a, b) { +// console.log(a, b); +// } + +// console.log(myFunction(3, 2)); + +// console.log(a); // Uncaught ReferenceError: a is not defined +// console.log(b); + +// /** +// * EXAMPLE 4 +// * +// * Reuse parameter names +// */ +// function myFunction1(a, b) { +// console.log(a, b); +// } + +// function myFunction2(a, b) { +// console.log(a, b); +// } + +// const a = true; +// const b = null; + +// myFunction1(2, 3); // 2, 3 + +// myFunction2(5, 7); // 5, 7 + +// console.log(a, b); // true, null + +// /** +// * EXAMPLE 5 +// * +// * Add "return" +// */ +// function sum(a, b) { +// return a + b; +// } + +// sum(10, 5); // function returns 15, but we see nothing in the console + +// console.log(sum(2, 5)); // 7 +// console.log(sum(10, 3)); // 13 +// console.log(sum("abc", 2)); // "abc2" +// console.log(sum()); // NaN + +// /** +// * EXAMPLE 6 +// * +// * What happens after "return"? +// */ +// function myFunction(a) { +// console.log(a); +// return a; // function stops here +// console.log(a); +// const c = 20; +// console.log(c); +// } + +// myFunction(10); \ No newline at end of file From 484967fef583f0e7f70777a082879095f6173734 Mon Sep 17 00:00:00 2001 From: Bogdan Stashchuk Date: Sun, 11 Nov 2018 10:28:27 +0200 Subject: [PATCH 14/41] Final --- index.js | 74 +++++++++++++++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 73 insertions(+), 1 deletion(-) diff --git a/index.js b/index.js index 231366b..850c707 100644 --- a/index.js +++ b/index.js @@ -102,4 +102,76 @@ // console.log(c); // } -// myFunction(10); \ No newline at end of file +// myFunction(10); + + +// /** +// * CHALLENGE 1 +// * +// * Create function called "mult" and it will have 3 parameters. +// * Create new variable and assign to it result of multiplication of all 3 parameters. +// * Print to the console result. +// * Don't use "return". +// */ +// function mult(a, b, c) { +// const result = a * b * c; +// console.log(result); +// } + +// mult(0, 3, 5); // 0 + +// mult(2, 3, 5); // 30 + +// mult(2, 3, "abc"); // NaN + +// mult(); // NaN + +// console.log(mult(2, 3, 5)); // 30 is printed inside of the function and function returns "undefined" + +// /** +// * CHALLENGE 2 +// * +// * Create a function "concatenateStrings" and it will have 2 parameters. +// * And this function will return concatenated string. +// */ +// function concatenateStrings(str1, str2) { +// return str1 + " " + str2; +// } + +// const str3 = concatenateStrings("Hello", "World"); // "Hello World" + +// console.log(str3); + +// /** +// * CHALLENGE 3 +// * +// * Create function "outerFunction" with 2 parameters. +// * Create function inside of the "outerFunction" and name it "innerFunction" with one parameter. +// * This "innerFunction" will return square of parameter (parameter * parameter). +// * +// * In the "outerFunction" sum both parameters. +// * Call "innerFunction" with argument that is equal to sum of both parameters of the "outerFunction". +// * Log to the console result of the "innerFunction" call. +// */ +// function outerFunction(a, b) { +// function innerFunction(c) { +// return c * c; +// } +// const sum = a + b; +// const result = innerFunction(sum); + +// console.log(result); +// } + +// // // Simplified +// // function outerFunction(a, b) { +// // function innerFunction(c) { +// // return c * c; +// // } + +// // console.log(innerFunction(a + b)); +// // } + +// outerFunction(2, 3); // 25 + +// outerFunction(3, 7); // 100 \ No newline at end of file From 3bb0d7dccc1237308260172a419f291902414358 Mon Sep 17 00:00:00 2001 From: Bogdan Stashchuk Date: Sun, 27 Jan 2019 10:13:57 +0200 Subject: [PATCH 15/41] start --- index.js | 177 ------------------------------------------------------- 1 file changed, 177 deletions(-) diff --git a/index.js b/index.js index 850c707..e69de29 100644 --- a/index.js +++ b/index.js @@ -1,177 +0,0 @@ -// /** -// * EXAMPLE 1 -// * -// * Simplest function in JavaScript -// */ -// function myFunction() {} - -// console.log(myFunction); // myFunction() {} - -// myFunction(); - -// const functionResult = myFunction(); - -// console.log(functionResult); // undefined - -// console.log(myFunction()); // undefined - -// console.log(myFunction(10, true)); // undefined - -// /** -// * EXAMPLE 2 -// * -// * Parameters of the function -// */ -// function myFunction(a, b) { -// console.log(a); -// console.log(b); -// } - -// myFunction(10, 5); // 10, 5 - -// myFunction(true, null); // true, null - -// myFunction(); // undefined, undefined - -// myFunction("abc"); // abc, undefined - -// console.log(myFunction(4, 3)); // undefined - -// /** -// * EXAMPLE 3 -// * -// * Function scope -// */ -// function myFunction(a, b) { -// console.log(a, b); -// } - -// console.log(myFunction(3, 2)); - -// console.log(a); // Uncaught ReferenceError: a is not defined -// console.log(b); - -// /** -// * EXAMPLE 4 -// * -// * Reuse parameter names -// */ -// function myFunction1(a, b) { -// console.log(a, b); -// } - -// function myFunction2(a, b) { -// console.log(a, b); -// } - -// const a = true; -// const b = null; - -// myFunction1(2, 3); // 2, 3 - -// myFunction2(5, 7); // 5, 7 - -// console.log(a, b); // true, null - -// /** -// * EXAMPLE 5 -// * -// * Add "return" -// */ -// function sum(a, b) { -// return a + b; -// } - -// sum(10, 5); // function returns 15, but we see nothing in the console - -// console.log(sum(2, 5)); // 7 -// console.log(sum(10, 3)); // 13 -// console.log(sum("abc", 2)); // "abc2" -// console.log(sum()); // NaN - -// /** -// * EXAMPLE 6 -// * -// * What happens after "return"? -// */ -// function myFunction(a) { -// console.log(a); -// return a; // function stops here -// console.log(a); -// const c = 20; -// console.log(c); -// } - -// myFunction(10); - - -// /** -// * CHALLENGE 1 -// * -// * Create function called "mult" and it will have 3 parameters. -// * Create new variable and assign to it result of multiplication of all 3 parameters. -// * Print to the console result. -// * Don't use "return". -// */ -// function mult(a, b, c) { -// const result = a * b * c; -// console.log(result); -// } - -// mult(0, 3, 5); // 0 - -// mult(2, 3, 5); // 30 - -// mult(2, 3, "abc"); // NaN - -// mult(); // NaN - -// console.log(mult(2, 3, 5)); // 30 is printed inside of the function and function returns "undefined" - -// /** -// * CHALLENGE 2 -// * -// * Create a function "concatenateStrings" and it will have 2 parameters. -// * And this function will return concatenated string. -// */ -// function concatenateStrings(str1, str2) { -// return str1 + " " + str2; -// } - -// const str3 = concatenateStrings("Hello", "World"); // "Hello World" - -// console.log(str3); - -// /** -// * CHALLENGE 3 -// * -// * Create function "outerFunction" with 2 parameters. -// * Create function inside of the "outerFunction" and name it "innerFunction" with one parameter. -// * This "innerFunction" will return square of parameter (parameter * parameter). -// * -// * In the "outerFunction" sum both parameters. -// * Call "innerFunction" with argument that is equal to sum of both parameters of the "outerFunction". -// * Log to the console result of the "innerFunction" call. -// */ -// function outerFunction(a, b) { -// function innerFunction(c) { -// return c * c; -// } -// const sum = a + b; -// const result = innerFunction(sum); - -// console.log(result); -// } - -// // // Simplified -// // function outerFunction(a, b) { -// // function innerFunction(c) { -// // return c * c; -// // } - -// // console.log(innerFunction(a + b)); -// // } - -// outerFunction(2, 3); // 25 - -// outerFunction(3, 7); // 100 \ No newline at end of file From 504ac8577f2e708d6be643580073760fa2085b44 Mon Sep 17 00:00:00 2001 From: Bogdan Stashchuk Date: Sun, 2 Dec 2018 22:27:28 +0200 Subject: [PATCH 16/41] Final --- index.js | 65 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 65 insertions(+) diff --git a/index.js b/index.js index e69de29..15f3786 100644 --- a/index.js +++ b/index.js @@ -0,0 +1,65 @@ +// /** +// * EXPRESSIONS +// */ +// 10 +// "abc" +// 5 + 3 + +// ;(function(a) { +// console.log(a); +// }) // Function expression embedded into the "()" + +// // Immediately Invoked Function Expression +// ;(function() { +// console.log("Hello from IIFE"); +// })() // Function call is expression + +// let a; +// a = 10 // Assignment expression + +// // 5 = true // Uncaught ReferenceError: Invalid left-hand side in assignment + +// 4 <= 10 <= 20 || 5 // true - Logical expression + +// /** +// * STATEMENTS +// */ +// let a; // Variable declaration is statement + +// a = 3 + +// function myFunction(b) { +// // Quick check that "return" is a statement (not expression) +// // console.log(return b); // Uncaught SyntaxError: Unexpected token return +// return b; +// } + +// myFunction(a) + +// if (true) { +// console.log("Hello from 'if' statement!"); +// } // "if" statement + + +// // Quick check that "if" is statement +// // console.log(if (true) { +// // console.log("Hello from 'if' statement!"); +// // }); // Uncaught SyntaxError: Unexpected token if + +// /** +// * EXPRESSION STATEMENTS +// */ +// console.log(4 + 3); // Expression statement + +// // console.log(console.log(4 + 3);); // Uncaught SyntaxError: missing ) after argument list + +// console.log(console.log(4 + 3)); // Expression statement + +// let a; +// a = 5; // Expression statement + +// true; // Expression statement + +// // console.log(true;); // Uncaught SyntaxError: missing ) after argument list + +// console.log(true); \ No newline at end of file From 1fccd9871486952bbaea5fbb4e55f2ea6aedd4ca Mon Sep 17 00:00:00 2001 From: Bogdan Stashchuk Date: Tue, 11 Dec 2018 18:10:36 +0200 Subject: [PATCH 17/41] Initial --- index.js | 65 -------------------------------------------------------- 1 file changed, 65 deletions(-) diff --git a/index.js b/index.js index 15f3786..e69de29 100644 --- a/index.js +++ b/index.js @@ -1,65 +0,0 @@ -// /** -// * EXPRESSIONS -// */ -// 10 -// "abc" -// 5 + 3 - -// ;(function(a) { -// console.log(a); -// }) // Function expression embedded into the "()" - -// // Immediately Invoked Function Expression -// ;(function() { -// console.log("Hello from IIFE"); -// })() // Function call is expression - -// let a; -// a = 10 // Assignment expression - -// // 5 = true // Uncaught ReferenceError: Invalid left-hand side in assignment - -// 4 <= 10 <= 20 || 5 // true - Logical expression - -// /** -// * STATEMENTS -// */ -// let a; // Variable declaration is statement - -// a = 3 - -// function myFunction(b) { -// // Quick check that "return" is a statement (not expression) -// // console.log(return b); // Uncaught SyntaxError: Unexpected token return -// return b; -// } - -// myFunction(a) - -// if (true) { -// console.log("Hello from 'if' statement!"); -// } // "if" statement - - -// // Quick check that "if" is statement -// // console.log(if (true) { -// // console.log("Hello from 'if' statement!"); -// // }); // Uncaught SyntaxError: Unexpected token if - -// /** -// * EXPRESSION STATEMENTS -// */ -// console.log(4 + 3); // Expression statement - -// // console.log(console.log(4 + 3);); // Uncaught SyntaxError: missing ) after argument list - -// console.log(console.log(4 + 3)); // Expression statement - -// let a; -// a = 5; // Expression statement - -// true; // Expression statement - -// // console.log(true;); // Uncaught SyntaxError: missing ) after argument list - -// console.log(true); \ No newline at end of file From a6b09d8f7af0d5235e2d653f01fa3a6d4fd36945 Mon Sep 17 00:00:00 2001 From: Bogdan Stashchuk Date: Tue, 11 Dec 2018 18:11:28 +0200 Subject: [PATCH 18/41] Initial --- index.js | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/index.js b/index.js index e69de29..18cac61 100644 --- a/index.js +++ b/index.js @@ -0,0 +1,4 @@ +/** + * JS-BASICS/CORE/CHALLENGES/03-expressions-vs-statements + * + */ \ No newline at end of file From 049b89ab3cdb9f622f2a3783585e07df456a5bb4 Mon Sep 17 00:00:00 2001 From: Bogdan Stashchuk Date: Tue, 11 Dec 2018 19:01:32 +0200 Subject: [PATCH 19/41] Final --- index.js | 45 ++++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 44 insertions(+), 1 deletion(-) diff --git a/index.js b/index.js index 18cac61..8136449 100644 --- a/index.js +++ b/index.js @@ -1,4 +1,47 @@ /** * JS-BASICS/CORE/CHALLENGES/03-expressions-vs-statements * - */ \ No newline at end of file + */ + +// /** +// * TASK 1 +// * +// * Is it expression or statement? +// */ +// const myObject = { +// x: 10, +// y: true +// }; + +// // console.log(delete myObject.x); // "delete" operator is used in the expressions + +// delete myObject.x; // Expression statement + +// /** +// * TASK 2 +// * +// * What will be logged to the console? +// */ +// function fn() { +// console.log("Greeting from the 'fn' function"); + +// return function(a) { +// console.log(a); +// }; +// } + +// fn() // Greeting from the 'fn' function +// (true) // "true" because this line will be interpreted as function call with argument "true" + +// /** +// * TASK 3 +// * +// * Explain why semicolon is added? +// */ +// function firstFunction(a, b) { +// return a + b; +// } // Function Declaration + +// const secondFunction = function(a, b) { +// return a + b; +// }; // Statement \ No newline at end of file From d493c1d94447009c445a72b0d05063750a7cfbde Mon Sep 17 00:00:00 2001 From: Bogdan Stashchuk Date: Wed, 12 Dec 2018 17:09:05 +0200 Subject: [PATCH 20/41] Initial --- index.js | 47 ----------------------------------------------- 1 file changed, 47 deletions(-) diff --git a/index.js b/index.js index 8136449..e69de29 100644 --- a/index.js +++ b/index.js @@ -1,47 +0,0 @@ -/** - * JS-BASICS/CORE/CHALLENGES/03-expressions-vs-statements - * - */ - -// /** -// * TASK 1 -// * -// * Is it expression or statement? -// */ -// const myObject = { -// x: 10, -// y: true -// }; - -// // console.log(delete myObject.x); // "delete" operator is used in the expressions - -// delete myObject.x; // Expression statement - -// /** -// * TASK 2 -// * -// * What will be logged to the console? -// */ -// function fn() { -// console.log("Greeting from the 'fn' function"); - -// return function(a) { -// console.log(a); -// }; -// } - -// fn() // Greeting from the 'fn' function -// (true) // "true" because this line will be interpreted as function call with argument "true" - -// /** -// * TASK 3 -// * -// * Explain why semicolon is added? -// */ -// function firstFunction(a, b) { -// return a + b; -// } // Function Declaration - -// const secondFunction = function(a, b) { -// return a + b; -// }; // Statement \ No newline at end of file From 80eb0161906b99894340c8ebdea8a201dedf6ed7 Mon Sep 17 00:00:00 2001 From: Bogdan Stashchuk Date: Fri, 14 Dec 2018 12:33:34 +0200 Subject: [PATCH 21/41] Final --- index.js | 134 +++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 134 insertions(+) diff --git a/index.js b/index.js index e69de29..eeab0a8 100644 --- a/index.js +++ b/index.js @@ -0,0 +1,134 @@ +// /** +// * EXAMPLE 1 +// * +// * Global scope +// */ +// var a = 10; +// let b = true; + +// console.log(a); // 10 +// console.log(window.a); // 10 + +// console.log(b); // true +// console.log(window.b); // undefined + +// const c = "abc"; + +// console.log(c); // "abc" +// console.log(window.c); // undefined + +// function myFunction(a) { +// console.log(a); // undefined +// console.log(b); // true +// } + +// console.log(myFunction); +// /** +// * ƒ myFunction(a) { +// console.log(a); +// } +// */ +// console.log(window.myFunction); +// /** +// * ƒ myFunction(a) { +// console.log(a); +// } +// */ + +// myFunction(); + + +// /** +// * EXAMPLE 2 +// * +// * Function scope +// */ + +// let e; + +// function myFunction(a, b) { +// const c = true; +// console.log(c); // true +// // console.log(d); // Uncaught ReferenceError: d is not defined at myFunction +// console.log(e); // undefined + +// console.log(a, b); // values of the parameters "a" and "b" +// } + +// myFunction(); + +// myFunction(2, 3); + +// // console.log(c); // Uncaught ReferenceError: c is not defined + +// // console.log(a); // Uncaught ReferenceError: a is not defined + +// // console.log(b); // Uncaught ReferenceError: b is not defined + + +// /** +// * EXAMPLE 3 +// * +// * Scope chain +// */ +// const c = 2; + +// function sum(a, b) { +// // const c = 3; +// function mult(a, b) { +// return a * b * c; // 100 +// } +// console.log(mult(a, b)); +// return a + b; +// } + +// const result = sum(10, 5); +// console.log(result); // 15 + + +// /** +// * EXAMPLE 4 +// * +// * Undeclared variable +// */ + +// a = 10; // variable "a" will be automatically declared in the global scope +// console.log(a); + +// const myFunction = function() { +// b = 5; // variable "b" will be automatically declared in the global scope +// console.log(b); // 5 +// } + +// myFunction(); + +// console.log(b); // 5 + +// /** +// * EXAMPLE 5 +// * +// * Strict mode +// */ +// "use strict"; + +// // a = 10; // Uncaught ReferenceError: a is not defined + +// function myFn() { +// b = 5; // Uncaught ReferenceError: b is not defined at myFn +// } + +// myFn(); + +// /** +// * EXAMPLE 6 +// * +// * Strict mode in the function +// */ +// a = 10; + +// function myFn() { +// "use strict"; +// // b = 5; // Uncaught ReferenceError: b is not defined at myFn +// } + +// myFn(); \ No newline at end of file From 68a5d0e43af27f940519fb5cd3b8aab044026252 Mon Sep 17 00:00:00 2001 From: Bogdan Stashchuk Date: Fri, 14 Dec 2018 12:34:50 +0200 Subject: [PATCH 22/41] Init --- index.js | 134 ------------------------------------------------------- 1 file changed, 134 deletions(-) diff --git a/index.js b/index.js index eeab0a8..e69de29 100644 --- a/index.js +++ b/index.js @@ -1,134 +0,0 @@ -// /** -// * EXAMPLE 1 -// * -// * Global scope -// */ -// var a = 10; -// let b = true; - -// console.log(a); // 10 -// console.log(window.a); // 10 - -// console.log(b); // true -// console.log(window.b); // undefined - -// const c = "abc"; - -// console.log(c); // "abc" -// console.log(window.c); // undefined - -// function myFunction(a) { -// console.log(a); // undefined -// console.log(b); // true -// } - -// console.log(myFunction); -// /** -// * ƒ myFunction(a) { -// console.log(a); -// } -// */ -// console.log(window.myFunction); -// /** -// * ƒ myFunction(a) { -// console.log(a); -// } -// */ - -// myFunction(); - - -// /** -// * EXAMPLE 2 -// * -// * Function scope -// */ - -// let e; - -// function myFunction(a, b) { -// const c = true; -// console.log(c); // true -// // console.log(d); // Uncaught ReferenceError: d is not defined at myFunction -// console.log(e); // undefined - -// console.log(a, b); // values of the parameters "a" and "b" -// } - -// myFunction(); - -// myFunction(2, 3); - -// // console.log(c); // Uncaught ReferenceError: c is not defined - -// // console.log(a); // Uncaught ReferenceError: a is not defined - -// // console.log(b); // Uncaught ReferenceError: b is not defined - - -// /** -// * EXAMPLE 3 -// * -// * Scope chain -// */ -// const c = 2; - -// function sum(a, b) { -// // const c = 3; -// function mult(a, b) { -// return a * b * c; // 100 -// } -// console.log(mult(a, b)); -// return a + b; -// } - -// const result = sum(10, 5); -// console.log(result); // 15 - - -// /** -// * EXAMPLE 4 -// * -// * Undeclared variable -// */ - -// a = 10; // variable "a" will be automatically declared in the global scope -// console.log(a); - -// const myFunction = function() { -// b = 5; // variable "b" will be automatically declared in the global scope -// console.log(b); // 5 -// } - -// myFunction(); - -// console.log(b); // 5 - -// /** -// * EXAMPLE 5 -// * -// * Strict mode -// */ -// "use strict"; - -// // a = 10; // Uncaught ReferenceError: a is not defined - -// function myFn() { -// b = 5; // Uncaught ReferenceError: b is not defined at myFn -// } - -// myFn(); - -// /** -// * EXAMPLE 6 -// * -// * Strict mode in the function -// */ -// a = 10; - -// function myFn() { -// "use strict"; -// // b = 5; // Uncaught ReferenceError: b is not defined at myFn -// } - -// myFn(); \ No newline at end of file From a45094818ebb0e19fec0e163168e6854cb065b32 Mon Sep 17 00:00:00 2001 From: Bogdan Stashchuk Date: Fri, 14 Dec 2018 12:35:55 +0200 Subject: [PATCH 23/41] Title --- index.js | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/index.js b/index.js index e69de29..419bfab 100644 --- a/index.js +++ b/index.js @@ -0,0 +1,4 @@ +/** + * JS-BASICS/CORE/CHALLENGES/04-scopes + * + */ \ No newline at end of file From 30778213a65ebf321f34bc83870ab78f2b13f911 Mon Sep 17 00:00:00 2001 From: Bogdan Stashchuk Date: Fri, 14 Dec 2018 18:31:56 +0200 Subject: [PATCH 24/41] Final --- index.js | 68 +++++++++++++++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 67 insertions(+), 1 deletion(-) diff --git a/index.js b/index.js index 419bfab..4667595 100644 --- a/index.js +++ b/index.js @@ -1,4 +1,70 @@ /** * JS-BASICS/CORE/CHALLENGES/04-scopes * - */ \ No newline at end of file + */ +// /** +// * TASK 1 +// * +// * Function scopes +// * What will be logged to the console? +// */ +// const b = 2; +// let d = 15; + +// function myFn1(a) { +// let b; +// let d = 10; +// myFn2(b); +// } + +// function myFn2(a) { +// let c = 5; +// console.log(a, b, c, d); +// } + +// myFn1(); + +// // ANSWER: undefined, 2, 5, 15 + + +// /** +// * TASK 2 +// * +// * Strict mode +// * Fix problems with the code below +// */ +// // "use strict"; + +// // function myFunction() { +// // a = 2; +// // return a; +// // } + +// // myFunction(); + +// // ANSWER +// "use strict"; + +// function myFunction() { +// let a = 2; +// return a; +// } + +// myFunction(); + + +// /** +// * TASK 3 +// * +// * Callback function +// * What will be logged to the console? +// */ +// setTimeout(function myFn() { +// console.log("Hello from myFn function"); +// }, 2000); + +// myFn(); + +// // ANSWER +// // Uncaught ReferenceError: myFn is not defined +// // "Hello from myFn function" \ No newline at end of file From 1d7cf12e3b69cf46eccfe40bda42bd72656167ba Mon Sep 17 00:00:00 2001 From: Bogdan Stashchuk Date: Fri, 14 Dec 2018 18:32:47 +0200 Subject: [PATCH 25/41] Start --- index.js | 70 -------------------------------------------------------- 1 file changed, 70 deletions(-) diff --git a/index.js b/index.js index 4667595..e69de29 100644 --- a/index.js +++ b/index.js @@ -1,70 +0,0 @@ -/** - * JS-BASICS/CORE/CHALLENGES/04-scopes - * - */ -// /** -// * TASK 1 -// * -// * Function scopes -// * What will be logged to the console? -// */ -// const b = 2; -// let d = 15; - -// function myFn1(a) { -// let b; -// let d = 10; -// myFn2(b); -// } - -// function myFn2(a) { -// let c = 5; -// console.log(a, b, c, d); -// } - -// myFn1(); - -// // ANSWER: undefined, 2, 5, 15 - - -// /** -// * TASK 2 -// * -// * Strict mode -// * Fix problems with the code below -// */ -// // "use strict"; - -// // function myFunction() { -// // a = 2; -// // return a; -// // } - -// // myFunction(); - -// // ANSWER -// "use strict"; - -// function myFunction() { -// let a = 2; -// return a; -// } - -// myFunction(); - - -// /** -// * TASK 3 -// * -// * Callback function -// * What will be logged to the console? -// */ -// setTimeout(function myFn() { -// console.log("Hello from myFn function"); -// }, 2000); - -// myFn(); - -// // ANSWER -// // Uncaught ReferenceError: myFn is not defined -// // "Hello from myFn function" \ No newline at end of file From d27b91e1b8e43c2e6f89a3ba384177bbbde6c0bd Mon Sep 17 00:00:00 2001 From: Bogdan Stashchuk Date: Wed, 19 Dec 2018 08:09:33 +0200 Subject: [PATCH 26/41] Final --- index.js | 102 +++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 102 insertions(+) diff --git a/index.js b/index.js index e69de29..41d8195 100644 --- a/index.js +++ b/index.js @@ -0,0 +1,102 @@ +// /** +// * EXAMPLE 1 +// * +// * Empty Array +// */ +// const myArray = []; +// console.log(myArray); + +// /** +// * EXAMPLE 2 +// * +// * Add elements to the Array +// */ +// const myArray = []; +// myArray[0] = "First Element"; + +// console.log(myArray); + +// myArray[1] = "Second Element"; + +// console.log(myArray); + +// myArray.push("Third Element"); // Preferable + +// console.log(myArray); + +// /** +// * EXAMPLE 3 +// * +// * Modify Elements +// */ +// const myArray = [3, true, "abc", {}]; + +// console.log(myArray); + +// myArray[1] = "New Value for second element"; + +// console.log(myArray); + +// myArray[0] = null; + +// console.log(myArray); + +// myArray[3].newProp = 10; + +// console.log(myArray); +// console.log(myArray[3].newProp); // 10 +// console.log(myArray[3]["newProp"]); // 10 + +// /** +// * EXAMPLE 4 +// * +// * Square bracket notation +// */ +// const myArray = [1, 2]; + +// console.log(myArray[0]); // 1 +// // If property name in the object is numeric you can't use dot notation +// console.log(myArray.0); // Uncaught SyntaxError: missing ) after argument list + + +// /** +// * EXAMPLE 5 +// * +// * Delete elements +// */ +// const myArray = [true, null, 1, 2, "abc"]; +// console.log(myArray); + +// delete myArray[2]; + +// console.log(myArray); // element with index 2 is "empty" + +// console.log(myArray[2]); // undefined + +// myArray.pop(); + +// console.log(myArray); // [true, null, empty, 2] + +// myArray.pop(); + +// console.log(myArray); // [true, null, empty] + +// myArray.shift(); + +// console.log(myArray); // [null, empty] + +// /** +// * EXAMPLE 6 +// * +// * Compare Arrays +// */ +// const myArray1 = [1, 3, 2]; +// const myArray2 = [1, 2, 3]; + +// console.log(myArray1 === myArray2); // false + +// const copyOfMyArray1 = myArray1; + +// console.log(copyOfMyArray1 === myArray1); // true + +// console.log(myArray1.toString() === myArray2.toString()); // true \ No newline at end of file From f1a278685dc1d65a885a8ced2e0477229edc71d6 Mon Sep 17 00:00:00 2001 From: Bogdan Stashchuk Date: Wed, 19 Dec 2018 08:10:15 +0200 Subject: [PATCH 27/41] Start --- index.js | 102 ------------------------------------------------------- 1 file changed, 102 deletions(-) diff --git a/index.js b/index.js index 41d8195..e69de29 100644 --- a/index.js +++ b/index.js @@ -1,102 +0,0 @@ -// /** -// * EXAMPLE 1 -// * -// * Empty Array -// */ -// const myArray = []; -// console.log(myArray); - -// /** -// * EXAMPLE 2 -// * -// * Add elements to the Array -// */ -// const myArray = []; -// myArray[0] = "First Element"; - -// console.log(myArray); - -// myArray[1] = "Second Element"; - -// console.log(myArray); - -// myArray.push("Third Element"); // Preferable - -// console.log(myArray); - -// /** -// * EXAMPLE 3 -// * -// * Modify Elements -// */ -// const myArray = [3, true, "abc", {}]; - -// console.log(myArray); - -// myArray[1] = "New Value for second element"; - -// console.log(myArray); - -// myArray[0] = null; - -// console.log(myArray); - -// myArray[3].newProp = 10; - -// console.log(myArray); -// console.log(myArray[3].newProp); // 10 -// console.log(myArray[3]["newProp"]); // 10 - -// /** -// * EXAMPLE 4 -// * -// * Square bracket notation -// */ -// const myArray = [1, 2]; - -// console.log(myArray[0]); // 1 -// // If property name in the object is numeric you can't use dot notation -// console.log(myArray.0); // Uncaught SyntaxError: missing ) after argument list - - -// /** -// * EXAMPLE 5 -// * -// * Delete elements -// */ -// const myArray = [true, null, 1, 2, "abc"]; -// console.log(myArray); - -// delete myArray[2]; - -// console.log(myArray); // element with index 2 is "empty" - -// console.log(myArray[2]); // undefined - -// myArray.pop(); - -// console.log(myArray); // [true, null, empty, 2] - -// myArray.pop(); - -// console.log(myArray); // [true, null, empty] - -// myArray.shift(); - -// console.log(myArray); // [null, empty] - -// /** -// * EXAMPLE 6 -// * -// * Compare Arrays -// */ -// const myArray1 = [1, 3, 2]; -// const myArray2 = [1, 2, 3]; - -// console.log(myArray1 === myArray2); // false - -// const copyOfMyArray1 = myArray1; - -// console.log(copyOfMyArray1 === myArray1); // true - -// console.log(myArray1.toString() === myArray2.toString()); // true \ No newline at end of file From dd71c8c40537392c8df996cd1fb64a6ef3a35e91 Mon Sep 17 00:00:00 2001 From: Bogdan Stashchuk Date: Thu, 20 Dec 2018 23:00:57 +0200 Subject: [PATCH 28/41] Final --- index.js | 77 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 77 insertions(+) diff --git a/index.js b/index.js index e69de29..fcc2d76 100644 --- a/index.js +++ b/index.js @@ -0,0 +1,77 @@ +// /** +// * CHALLENGE 1 +// * +// * Add elements at the beginning of the Array +// * First add string "Hello" +// * Second add number 100 +// */ +// // const myArray = [true, null]; + +// // console.log(myArray); // [100, "Hello", true, null] + +// // SOLUTION +// const myArray = [true, null]; + +// myArray.unshift("Hello"); +// console.log(myArray); + +// myArray.unshift(100); + +// console.log(myArray); // [100, "Hello", true, null] + +// /** +// * CHALLENGE 2 +// * +// * Add element at the specific index. +// * Element "abc" with index 10. +// * Log to the console Array and explain results. +// * What is the length of the final Array? +// */ +// // const myArray = [1, 2]; + +// // SOLUTION +// const myArray = [1, 2]; +// console.log(myArray.length); // 2 + +// myArray[10] = "abc"; + +// console.log(myArray); +// // [1, 2, empty × 8, "abc"] +// // Length is 11 +// console.log(myArray.length); // 11 + + +// /** +// * CHALLENGE 3 +// * +// * Array of objects. +// * +// * Create Array with 3 objects. +// * Each object will have two properties - carBrand, price. +// * Add one more object to the Array +// */ +// const arrayOfCars = [ +// { +// carBrand: "Toyota", +// price: 12000 +// }, +// { +// carBrand: "Tesla", +// price: 30000 +// }, +// { +// carBrand: "BMW", +// price: 25000 +// } +// ]; + +// console.log(arrayOfCars); + +// const newCar = { +// carBrand: "Honda", +// price: 15000 +// }; + +// arrayOfCars.push(newCar); + +// console.log(arrayOfCars); // Array with 4 objects From f5371d37453133fef3d37dca48e22ebf43806971 Mon Sep 17 00:00:00 2001 From: Bogdan Stashchuk Date: Mon, 28 Jan 2019 08:30:08 +0200 Subject: [PATCH 29/41] Start --- index.js | 77 -------------------------------------------------------- 1 file changed, 77 deletions(-) diff --git a/index.js b/index.js index fcc2d76..e69de29 100644 --- a/index.js +++ b/index.js @@ -1,77 +0,0 @@ -// /** -// * CHALLENGE 1 -// * -// * Add elements at the beginning of the Array -// * First add string "Hello" -// * Second add number 100 -// */ -// // const myArray = [true, null]; - -// // console.log(myArray); // [100, "Hello", true, null] - -// // SOLUTION -// const myArray = [true, null]; - -// myArray.unshift("Hello"); -// console.log(myArray); - -// myArray.unshift(100); - -// console.log(myArray); // [100, "Hello", true, null] - -// /** -// * CHALLENGE 2 -// * -// * Add element at the specific index. -// * Element "abc" with index 10. -// * Log to the console Array and explain results. -// * What is the length of the final Array? -// */ -// // const myArray = [1, 2]; - -// // SOLUTION -// const myArray = [1, 2]; -// console.log(myArray.length); // 2 - -// myArray[10] = "abc"; - -// console.log(myArray); -// // [1, 2, empty × 8, "abc"] -// // Length is 11 -// console.log(myArray.length); // 11 - - -// /** -// * CHALLENGE 3 -// * -// * Array of objects. -// * -// * Create Array with 3 objects. -// * Each object will have two properties - carBrand, price. -// * Add one more object to the Array -// */ -// const arrayOfCars = [ -// { -// carBrand: "Toyota", -// price: 12000 -// }, -// { -// carBrand: "Tesla", -// price: 30000 -// }, -// { -// carBrand: "BMW", -// price: 25000 -// } -// ]; - -// console.log(arrayOfCars); - -// const newCar = { -// carBrand: "Honda", -// price: 15000 -// }; - -// arrayOfCars.push(newCar); - -// console.log(arrayOfCars); // Array with 4 objects From eaf1e7b380f74300794543835588a877dd4f304a Mon Sep 17 00:00:00 2001 From: Bogdan Stashchuk Date: Thu, 31 Jan 2019 19:01:39 +0200 Subject: [PATCH 30/41] start --- index.js | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/index.js b/index.js index e69de29..57a8714 100644 --- a/index.js +++ b/index.js @@ -0,0 +1,4 @@ +/** + * JS-BASICS/CORE/CHALLENGES/06-loops-and-conditions + * + */ From 43d7ccb8619eb6105647ba7fd8b2457f6e64af97 Mon Sep 17 00:00:00 2001 From: Bogdan Stashchuk Date: Sat, 2 Feb 2019 23:34:05 +0200 Subject: [PATCH 31/41] Final --- index.js | 113 +++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 113 insertions(+) diff --git a/index.js b/index.js index 57a8714..3b6639c 100644 --- a/index.js +++ b/index.js @@ -2,3 +2,116 @@ * JS-BASICS/CORE/CHALLENGES/06-loops-and-conditions * */ +// /** +// * TASK 1 +// * +// * Loop through the object and if property name(key) is either "key1" or "key3" log to the console property value +// */ +// const myObject = { +// key1: true, +// key5: 10, +// key3: "abc", +// key4: null, +// key10: NaN +// }; + +// // ANSWER +// for (let key in myObject) { +// if (key === "key1" || key === "key3") { +// console.log(myObject[key]); +// } +// } + + +// /** +// * TASK 2 +// * +// * Generate new 4-digit random number. +// * Range for the random number is 1000-9999. +// * +// * Ensure that this new random number doesn't match any of the numbers in the myNumbers array. +// * If it matches you need to generate new 4-digit number. +// * If there is no match(new number is unique) then add it to the myNumbers array. +// */ +// const MIN = 1000; +// const MAX = 9999; + +// const myNumbers = [ +// 2355, +// 7235, +// 8135, +// 1762, +// 2361, +// 8351 +// ]; + +// let newRandomNumber; + +// function getRandomInt(min, max) { +// return Math.floor(Math.random() * (max - min + 1)) + min; +// } + +// function isNotUnique(newRandomNum) { +// // compare num with numbers in the myNumbers array +// for (let number of myNumbers) { +// if (number === newRandomNum) { +// console.log("Number " + newRandomNum + " is not unique!"); +// return true; +// } +// } +// } + +// do { +// newRandomNumber = getRandomInt(MIN, MAX); +// } while (isNotUnique(newRandomNumber)); + +// myNumbers.push(newRandomNumber); + +// console.log(myNumbers); + + +// /** +// * TASK 3 +// * +// * For in loop. Make "for in" loop iterate only over own properties of the myObject +// */ +// const myObject = { +// name: "Mike", +// age: 30, +// city: "London" +// }; + +// Object.prototype.country = "England"; + +// for (let key in myObject) { +// if (myObject.hasOwnProperty(key)) { +// console.log(myObject[key]); +// } +// } + +// /** +// * TASK 4 +// * +// * Rewrite "if...else" statement with ternary operator +// */ +// // function emptyArray(inputArray) { +// // if (inputArray.length > 0) { +// // return "Array is not empty"; +// // } else { +// // return "Array is empty"; +// // } +// // } + +// // console.log(emptyArray([1, 3])); +// // console.log(emptyArray([])); + + +// //ANSWER +// function emptyArray(inputArray) { +// return inputArray.length > 0 +// ? "Array is not empty" +// : "Array is empty"; +// } + +// console.log(emptyArray([1, 3])); +// console.log(emptyArray([])); From 82ce97613d98f188baa9443fefbaff4a6f67a0e8 Mon Sep 17 00:00:00 2001 From: Bogdan Stashchuk Date: Sun, 10 Feb 2019 10:47:20 +0200 Subject: [PATCH 32/41] Start --- index.js | 117 ------------------------------------------------------- 1 file changed, 117 deletions(-) diff --git a/index.js b/index.js index 3b6639c..e69de29 100644 --- a/index.js +++ b/index.js @@ -1,117 +0,0 @@ -/** - * JS-BASICS/CORE/CHALLENGES/06-loops-and-conditions - * - */ -// /** -// * TASK 1 -// * -// * Loop through the object and if property name(key) is either "key1" or "key3" log to the console property value -// */ -// const myObject = { -// key1: true, -// key5: 10, -// key3: "abc", -// key4: null, -// key10: NaN -// }; - -// // ANSWER -// for (let key in myObject) { -// if (key === "key1" || key === "key3") { -// console.log(myObject[key]); -// } -// } - - -// /** -// * TASK 2 -// * -// * Generate new 4-digit random number. -// * Range for the random number is 1000-9999. -// * -// * Ensure that this new random number doesn't match any of the numbers in the myNumbers array. -// * If it matches you need to generate new 4-digit number. -// * If there is no match(new number is unique) then add it to the myNumbers array. -// */ -// const MIN = 1000; -// const MAX = 9999; - -// const myNumbers = [ -// 2355, -// 7235, -// 8135, -// 1762, -// 2361, -// 8351 -// ]; - -// let newRandomNumber; - -// function getRandomInt(min, max) { -// return Math.floor(Math.random() * (max - min + 1)) + min; -// } - -// function isNotUnique(newRandomNum) { -// // compare num with numbers in the myNumbers array -// for (let number of myNumbers) { -// if (number === newRandomNum) { -// console.log("Number " + newRandomNum + " is not unique!"); -// return true; -// } -// } -// } - -// do { -// newRandomNumber = getRandomInt(MIN, MAX); -// } while (isNotUnique(newRandomNumber)); - -// myNumbers.push(newRandomNumber); - -// console.log(myNumbers); - - -// /** -// * TASK 3 -// * -// * For in loop. Make "for in" loop iterate only over own properties of the myObject -// */ -// const myObject = { -// name: "Mike", -// age: 30, -// city: "London" -// }; - -// Object.prototype.country = "England"; - -// for (let key in myObject) { -// if (myObject.hasOwnProperty(key)) { -// console.log(myObject[key]); -// } -// } - -// /** -// * TASK 4 -// * -// * Rewrite "if...else" statement with ternary operator -// */ -// // function emptyArray(inputArray) { -// // if (inputArray.length > 0) { -// // return "Array is not empty"; -// // } else { -// // return "Array is empty"; -// // } -// // } - -// // console.log(emptyArray([1, 3])); -// // console.log(emptyArray([])); - - -// //ANSWER -// function emptyArray(inputArray) { -// return inputArray.length > 0 -// ? "Array is not empty" -// : "Array is empty"; -// } - -// console.log(emptyArray([1, 3])); -// console.log(emptyArray([])); From 68df65e39d9cca5285ec98faea14318dba8d2fef Mon Sep 17 00:00:00 2001 From: Bogdan Stashchuk Date: Sun, 10 Feb 2019 11:55:42 +0200 Subject: [PATCH 33/41] Final --- index.js | 40 ++++++++++++++++++++++++++++++++++++++++ 1 file changed, 40 insertions(+) diff --git a/index.js b/index.js index e69de29..5d5758f 100644 --- a/index.js +++ b/index.js @@ -0,0 +1,40 @@ +// // EXAMPLE 1 - global and function execution contexts +// // Global execution context +// console.log("This is global execution context"); + +// const a = 10; + +// console.log(a); + +// function myFunction(a, b) { +// console.log("This is function execution context"); +// return a + b; +// } + +// console.log(myFunction(5, 20)); // new function execution context is created + +// console.log(myFunction(3, 5)); // new function execution context is created + + + +// // EXAMPLE 2 - Execution contexts stack + +// console.log("Global execution context - root level in the stack"); + +// function firstLevel() { +// console.log("Function execution context - second level in the stack"); + +// function secondLevel() { +// console.log("Function execution context - third level in the stack"); + +// function thirdLevel() { +// console.log("Function execution context - fourth level in the stack"); +// } + +// thirdLevel(); +// } + +// secondLevel(); +// } + +// firstLevel(); \ No newline at end of file From 0ab2c854946c7de6f84c160c5f3355787d942034 Mon Sep 17 00:00:00 2001 From: Bogdan Stashchuk Date: Sun, 10 Feb 2019 13:05:09 +0200 Subject: [PATCH 34/41] Start --- index.js | 40 ---------------------------------------- 1 file changed, 40 deletions(-) diff --git a/index.js b/index.js index 5d5758f..e69de29 100644 --- a/index.js +++ b/index.js @@ -1,40 +0,0 @@ -// // EXAMPLE 1 - global and function execution contexts -// // Global execution context -// console.log("This is global execution context"); - -// const a = 10; - -// console.log(a); - -// function myFunction(a, b) { -// console.log("This is function execution context"); -// return a + b; -// } - -// console.log(myFunction(5, 20)); // new function execution context is created - -// console.log(myFunction(3, 5)); // new function execution context is created - - - -// // EXAMPLE 2 - Execution contexts stack - -// console.log("Global execution context - root level in the stack"); - -// function firstLevel() { -// console.log("Function execution context - second level in the stack"); - -// function secondLevel() { -// console.log("Function execution context - third level in the stack"); - -// function thirdLevel() { -// console.log("Function execution context - fourth level in the stack"); -// } - -// thirdLevel(); -// } - -// secondLevel(); -// } - -// firstLevel(); \ No newline at end of file From d102b73e3bc5036f4ffa36172a9d65f7d42db1c9 Mon Sep 17 00:00:00 2001 From: Bogdan Stashchuk Date: Sun, 10 Feb 2019 14:51:05 +0200 Subject: [PATCH 35/41] Final --- index.js | 96 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 96 insertions(+) diff --git a/index.js b/index.js index e69de29..e000ee1 100644 --- a/index.js +++ b/index.js @@ -0,0 +1,96 @@ +// // EXAMPLE 1 - CALL - custom "this" +// const myObject = { +// a: 10, +// b: null +// }; + +// function myFunction() { +// console.log(this); +// } + +// myFunction(); // "this" is window + +// myFunction.call(myObject); // "this" is {a: 10, b: null} + + + +// // EXAMPLE 2 - CALL - custom "this" and arguments +// const myObject = { +// a: 10, +// b: null +// }; + +// function myFunction(a, b) { +// console.log(a + b); +// console.log(this); +// } + +// // myFunction(); // "this" is window + +// myFunction.call(myObject, 10, 3); // "this" is {a: 10, b: null} + + +// // EXAMPLE 3 - CALL - Call method of the object with other object as "this" +// const person1 = { +// city: "New York", +// name: "Bob", +// info: function() { +// console.log(this.name + " lives in " + this.city); +// } +// }; + +// const person2 = { +// city: "Paris", +// name: "Alice" +// }; + +// person1.info(); // Bob lives in New York + +// person1.info.call(person2); // Alice lives in Paris + + +// // EXAMPLE 4 - APPLY - custom "this" and arguments +// const myObject = { +// a: 10, +// b: null +// }; + +// function myFunction(a, b, c) { +// let sum = a + b + c; +// // console.log(this); + +// for (let key in this) { +// if (typeof this[key] === "number") { +// sum += this[key]; +// } +// } + +// console.log(sum); +// } + +// // myFunction(); // "this" is window + +// myFunction.apply(myObject, [10, 3, 5]); // "this" is {a: 10, b: null} + + + +// // EXAMPLE 5 - BIND +// const myObject = { +// a: 10, +// b: null +// }; + +// function myFunction(a, b) { +// console.log(a + b); +// console.log(this); +// } + +// const customFunction1 = myFunction.bind(myObject, 10, 3); // preset "this" and both arguments +// customFunction1(); + + +// const customFunction2 = myFunction.bind(myObject); // preset only "this" +// customFunction2(20, 6); // call with custom arguments + +// const customFunction3 = myFunction.bind(myObject, 50); // preset "this" and only first argument +// customFunction3(30); // pass remaining arguments \ No newline at end of file From 4046f78b07b452423bf8def7fd4557402c07cfe4 Mon Sep 17 00:00:00 2001 From: Bogdan Stashchuk Date: Sun, 10 Feb 2019 15:17:13 +0200 Subject: [PATCH 36/41] Start --- index.js | 96 -------------------------------------------------------- 1 file changed, 96 deletions(-) diff --git a/index.js b/index.js index e000ee1..e69de29 100644 --- a/index.js +++ b/index.js @@ -1,96 +0,0 @@ -// // EXAMPLE 1 - CALL - custom "this" -// const myObject = { -// a: 10, -// b: null -// }; - -// function myFunction() { -// console.log(this); -// } - -// myFunction(); // "this" is window - -// myFunction.call(myObject); // "this" is {a: 10, b: null} - - - -// // EXAMPLE 2 - CALL - custom "this" and arguments -// const myObject = { -// a: 10, -// b: null -// }; - -// function myFunction(a, b) { -// console.log(a + b); -// console.log(this); -// } - -// // myFunction(); // "this" is window - -// myFunction.call(myObject, 10, 3); // "this" is {a: 10, b: null} - - -// // EXAMPLE 3 - CALL - Call method of the object with other object as "this" -// const person1 = { -// city: "New York", -// name: "Bob", -// info: function() { -// console.log(this.name + " lives in " + this.city); -// } -// }; - -// const person2 = { -// city: "Paris", -// name: "Alice" -// }; - -// person1.info(); // Bob lives in New York - -// person1.info.call(person2); // Alice lives in Paris - - -// // EXAMPLE 4 - APPLY - custom "this" and arguments -// const myObject = { -// a: 10, -// b: null -// }; - -// function myFunction(a, b, c) { -// let sum = a + b + c; -// // console.log(this); - -// for (let key in this) { -// if (typeof this[key] === "number") { -// sum += this[key]; -// } -// } - -// console.log(sum); -// } - -// // myFunction(); // "this" is window - -// myFunction.apply(myObject, [10, 3, 5]); // "this" is {a: 10, b: null} - - - -// // EXAMPLE 5 - BIND -// const myObject = { -// a: 10, -// b: null -// }; - -// function myFunction(a, b) { -// console.log(a + b); -// console.log(this); -// } - -// const customFunction1 = myFunction.bind(myObject, 10, 3); // preset "this" and both arguments -// customFunction1(); - - -// const customFunction2 = myFunction.bind(myObject); // preset only "this" -// customFunction2(20, 6); // call with custom arguments - -// const customFunction3 = myFunction.bind(myObject, 50); // preset "this" and only first argument -// customFunction3(30); // pass remaining arguments \ No newline at end of file From 3f49718c631fc78e8385d992c3b5295a86baeeec Mon Sep 17 00:00:00 2001 From: Bogdan Stashchuk Date: Sun, 10 Feb 2019 16:04:34 +0200 Subject: [PATCH 37/41] Final --- index.js | 48 ++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 48 insertions(+) diff --git a/index.js b/index.js index e69de29..4c93b83 100644 --- a/index.js +++ b/index.js @@ -0,0 +1,48 @@ +// // PASS BY VALUE +// // If variable that holds value of primitive value type is passed to the function as argument, it's value can't be changed inside of the function +// function myFunction(parameterA) { +// parameterA = 20; +// return parameterA; +// } + +// const a = 10; + +// console.log(myFunction(a)); // 20 + +// console.log(a); // 10 + + +// // PASS BY REFERENCE +// const myArray = [1, 2, 3]; + +// console.log(myArray); + +// function myFunction(arr) { +// console.log(arr === myArray); // true +// arr.push(4); +// console.log(arr); +// return arr; +// } + +// myFunction(myArray); + +// console.log(myArray); + + +// // CHALLENGE +// // Create a function that will add custom method to the global object "window" +// function addCustomGlobalMethod(globalObject) { +// globalObject.customMethod = function() { +// console.log("Greeting from the custom method"); +// }; +// } + +// addCustomGlobalMethod(this); +// console.log(this === window); // true +// console.log(typeof window); // "object" + +// this.customMethod(); // "Greeting from the custom method" + +// window.customMethod(); // "Greeting from the custom method" + +// customMethod(); // "Greeting from the custom method" \ No newline at end of file From a4f458ca25f1669edc6736ab553b2656deac93c1 Mon Sep 17 00:00:00 2001 From: Bogdan Stashchuk Date: Sat, 2 Mar 2019 12:28:49 +0200 Subject: [PATCH 38/41] start --- index.js | 57 +++++++++++++------------------------------------------- 1 file changed, 13 insertions(+), 44 deletions(-) diff --git a/index.js b/index.js index 4c93b83..7daf460 100644 --- a/index.js +++ b/index.js @@ -1,48 +1,17 @@ -// // PASS BY VALUE -// // If variable that holds value of primitive value type is passed to the function as argument, it's value can't be changed inside of the function -// function myFunction(parameterA) { -// parameterA = 20; -// return parameterA; -// } +// CHALLENGE +// Create a function that will add custom method to the global object "window" +function addCustomGlobalMethod(globalObject) { + globalObject.customMethod = function() { + console.log("Greeting from the custom method"); + }; +} -// const a = 10; +addCustomGlobalMethod(this); +console.log(this === window); // true +console.log(typeof window); // "object" -// console.log(myFunction(a)); // 20 +this.customMethod(); // "Greeting from the custom method" -// console.log(a); // 10 +window.customMethod(); // "Greeting from the custom method" - -// // PASS BY REFERENCE -// const myArray = [1, 2, 3]; - -// console.log(myArray); - -// function myFunction(arr) { -// console.log(arr === myArray); // true -// arr.push(4); -// console.log(arr); -// return arr; -// } - -// myFunction(myArray); - -// console.log(myArray); - - -// // CHALLENGE -// // Create a function that will add custom method to the global object "window" -// function addCustomGlobalMethod(globalObject) { -// globalObject.customMethod = function() { -// console.log("Greeting from the custom method"); -// }; -// } - -// addCustomGlobalMethod(this); -// console.log(this === window); // true -// console.log(typeof window); // "object" - -// this.customMethod(); // "Greeting from the custom method" - -// window.customMethod(); // "Greeting from the custom method" - -// customMethod(); // "Greeting from the custom method" \ No newline at end of file +customMethod(); // "Greeting from the custom method" \ No newline at end of file From 088d650b83a92830b5d4cf3f47bdb8ed4bcadf30 Mon Sep 17 00:00:00 2001 From: Bogdan Stashchuk Date: Sat, 2 Mar 2019 13:06:11 +0200 Subject: [PATCH 39/41] Final --- index.js | 25 ++++++++++++++++++++----- 1 file changed, 20 insertions(+), 5 deletions(-) diff --git a/index.js b/index.js index 7daf460..096f7df 100644 --- a/index.js +++ b/index.js @@ -1,12 +1,27 @@ -// CHALLENGE -// Create a function that will add custom method to the global object "window" -function addCustomGlobalMethod(globalObject) { +// IIFE - Immediately invoked function expression +// OPTION 1 +(function(globalObject) { globalObject.customMethod = function() { console.log("Greeting from the custom method"); }; -} +})(this); + + +// // OPTION 2 +// (function() { +// this.customMethod = function() { +// console.log("Greeting from the custom method"); +// }; +// })(); + +// // OPTION 3 +// (() => { +// this.customMethod = function() { +// console.log("Greeting from the custom method"); +// }; +// })(); + -addCustomGlobalMethod(this); console.log(this === window); // true console.log(typeof window); // "object" From 116ab5a4656f14a0d4ceed5ba35a50a1e97d8f66 Mon Sep 17 00:00:00 2001 From: Bogdan Stashchuk Date: Sat, 2 Mar 2019 13:10:02 +0200 Subject: [PATCH 40/41] start --- index.js | 32 -------------------------------- 1 file changed, 32 deletions(-) diff --git a/index.js b/index.js index 096f7df..e69de29 100644 --- a/index.js +++ b/index.js @@ -1,32 +0,0 @@ -// IIFE - Immediately invoked function expression -// OPTION 1 -(function(globalObject) { - globalObject.customMethod = function() { - console.log("Greeting from the custom method"); - }; -})(this); - - -// // OPTION 2 -// (function() { -// this.customMethod = function() { -// console.log("Greeting from the custom method"); -// }; -// })(); - -// // OPTION 3 -// (() => { -// this.customMethod = function() { -// console.log("Greeting from the custom method"); -// }; -// })(); - - -console.log(this === window); // true -console.log(typeof window); // "object" - -this.customMethod(); // "Greeting from the custom method" - -window.customMethod(); // "Greeting from the custom method" - -customMethod(); // "Greeting from the custom method" \ No newline at end of file From efd1df416f58867cc8ae9c4a03ba98b96d829558 Mon Sep 17 00:00:00 2001 From: Bogdan Stashchuk Date: Sat, 2 Mar 2019 13:42:12 +0200 Subject: [PATCH 41/41] Final --- index.js | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/index.js b/index.js index e69de29..ca32828 100644 --- a/index.js +++ b/index.js @@ -0,0 +1,13 @@ +// CHALLENGE +// Create a function "waitingFn" with single parameter "timeInMs" and inside of the function create "while" loop and this loop should be running during "timeInMs". +// HINT: Date.now() - current time in ms since 1970 +function waitingFn(timeInMs) { + const futureTime = Date.now() + timeInMs; + while (futureTime > Date.now()) { + // waiting... + } +} + +waitingFn(3000); + +console.log("Function call has just ended"); \ No newline at end of file