From 05a3d10f0723cb2e6280db9cdb26b86e6ddcbe52 Mon Sep 17 00:00:00 2001 From: abdouconde Date: Tue, 4 Jun 2024 20:28:42 +0200 Subject: [PATCH 1/8] empty statte --- index.js | 30 ------------------------------ 1 file changed, 30 deletions(-) diff --git a/index.js b/index.js index f90b9de..e69de29 100644 --- a/index.js +++ b/index.js @@ -1,30 +0,0 @@ -/* -Modify "personInfo" function to match console.log output at the end of the challenge. - -Object that is returned by "personInfo" function must contain only shorthand property names. -*/ - -const personInfo = (/* parameters */) => { - /* return ... */ -}; - -const person = { - name: "Alice", - age: 19, - location: { - country: "England", - city: "London" - } -}; - -console.log(personInfo(person)); -/* -{ - name: "Alice", - personAge: 19, - origin: "England", - homeCity: "London", - friendsQty: 0, - recordCreatedAt: *current year* -} -*/ From 0f5a8caa63fe7cc0cfa238561883f284ef12f9b6 Mon Sep 17 00:00:00 2001 From: abdouconde Date: Tue, 4 Jun 2024 20:51:26 +0200 Subject: [PATCH 2/8] chanllenge Ok: Use strict Don't unecesseraly expose variable to outer scope use var when variable is going to change use let in blcok scope --- index.js | 41 +++++++++++++++++++++++++++++++++++++++++ 1 file changed, 41 insertions(+) diff --git a/index.js b/index.js index e69de29..8da0416 100644 --- a/index.js +++ b/index.js @@ -0,0 +1,41 @@ +/** + * CHALLENGE 1-1 TASK + * + * Rewrite code below using let, const and var according to + * variables usage guidelines + */ +"use strict"; +const numbers1 = [23, 87, 110, 11, 20, 5, 34]; +const numbers2 = [11, 21, 31]; + +const onlyOddNumbers = function(arr) { + var oddNumbers = []; + var EVEN_NUMBERS_QUANTITY = 0; + const LEN = arr.length; + + for (let i = 0; i < LEN; i++) { + arr[i] % 2 + ? oddNumbers.push(arr[i]) + : EVEN_NUMBERS_QUANTITY++; + } + + if (EVEN_NUMBERS_QUANTITY === 0) { + let info = "Array contains only odd numbers"; + console.log(info); + } else { + let info = + "There are " + + EVEN_NUMBERS_QUANTITY + + " even numbers"; + console.log(info); + } + + return { + oddNumbersKey: oddNumbers, + EVEN_NUMBERS_QUANTITYValue: EVEN_NUMBERS_QUANTITY + }; + +}; + +console.log(onlyOddNumbers(numbers1)); +console.log(onlyOddNumbers(numbers2)); \ No newline at end of file From 650f2e8fa7de6b1336895f2fa7643f701ea926ce Mon Sep 17 00:00:00 2001 From: abdouconde Date: Fri, 14 Jun 2024 10:54:23 +0200 Subject: [PATCH 3/8] okay --- index.html | 17 ++++++++++++++ index.js | 66 ++++++++++++++++++++++++++---------------------------- 2 files changed, 49 insertions(+), 34 deletions(-) diff --git a/index.html b/index.html index 2d5a61b..d68d155 100644 --- a/index.html +++ b/index.html @@ -3,9 +3,26 @@ ES6 + +
+ diff --git a/index.js b/index.js index 8da0416..df483ae 100644 --- a/index.js +++ b/index.js @@ -1,41 +1,39 @@ /** - * CHALLENGE 1-1 TASK + * CHALLENGE 1-2 SOLUTION * - * Rewrite code below using let, const and var according to - * variables usage guidelines + * Find all menu elements by selector ".nav-link" + * or by className "nav-link". + * + * Use "for" loop to iterate through all menu items + * Inside of the loop add "onclick" event handler to + * each menu item. + * + * In the "onclick" event handler: + * 1. Remove first "active" class from all + * menu elements + * 2. Add "active" class to the clicked menu element + * 3. Log to the console message with the name + * of the clicked menu item */ -"use strict"; -const numbers1 = [23, 87, 110, 11, 20, 5, 34]; -const numbers2 = [11, 21, 31]; - -const onlyOddNumbers = function(arr) { - var oddNumbers = []; - var EVEN_NUMBERS_QUANTITY = 0; - const LEN = arr.length; - - for (let i = 0; i < LEN; i++) { - arr[i] % 2 - ? oddNumbers.push(arr[i]) - : EVEN_NUMBERS_QUANTITY++; - } - if (EVEN_NUMBERS_QUANTITY === 0) { - let info = "Array contains only odd numbers"; - console.log(info); - } else { - let info = - "There are " + - EVEN_NUMBERS_QUANTITY + - " even numbers"; - console.log(info); - } - return { - oddNumbersKey: oddNumbers, - EVEN_NUMBERS_QUANTITYValue: EVEN_NUMBERS_QUANTITY - }; +const navBarItems = document.querySelectorAll(".nav-link"); +const LEN = navBarItems.length; + +console.log(navBarItems); -}; +for(let i=0;i Date: Mon, 22 Jul 2024 00:11:21 +0200 Subject: [PATCH 4/8] Arrow function does not have own this, they are attached to the surrounded context --- index.js | 58 +++++++++++++++++++++----------------------------------- 1 file changed, 22 insertions(+), 36 deletions(-) diff --git a/index.js b/index.js index df483ae..496984c 100644 --- a/index.js +++ b/index.js @@ -1,39 +1,25 @@ -/** - * CHALLENGE 1-2 SOLUTION - * - * Find all menu elements by selector ".nav-link" - * or by className "nav-link". - * - * Use "for" loop to iterate through all menu items - * Inside of the loop add "onclick" event handler to - * each menu item. - * - * In the "onclick" event handler: - * 1. Remove first "active" class from all - * menu elements - * 2. Add "active" class to the clicked menu element - * 3. Log to the console message with the name - * of the clicked menu item - */ - - -const navBarItems = document.querySelectorAll(".nav-link"); -const LEN = navBarItems.length; - -console.log(navBarItems); - -for(let i=0;i{ + return "This is "+this.name + " , He is " + this.age + } //This here is always global or window +} - - } +var person2={ + name:"Conde Abdourahamane", + age: 26, + present: function(){ + return "This is "+this.name + " , He is " + this.age + } +} +var anotherPerson={ + name: "Conde Souleymane", + age: 15, } + +console.log(person1.present.call(anotherPerson)) //This is undefined , He is undefined +console.log(person2.present.call(anotherPerson)) //This is Conde Souleymane , He is 15 \ No newline at end of file From 08706da1fb7f84e8d2813f711c5af81a24936cba Mon Sep 17 00:00:00 2001 From: abdouconde Date: Mon, 22 Jul 2024 00:11:49 +0200 Subject: [PATCH 5/8] tempCodeRunner.js --- tempCodeRunnerFile.js | 2 ++ 1 file changed, 2 insertions(+) create mode 100644 tempCodeRunnerFile.js diff --git a/tempCodeRunnerFile.js b/tempCodeRunnerFile.js new file mode 100644 index 0000000..0bba4ea --- /dev/null +++ b/tempCodeRunnerFile.js @@ -0,0 +1,2 @@ +var type= typeof [] +console.log(type) \ No newline at end of file From 5bf364520ae8bba363d126d1cf11717d49c3c818 Mon Sep 17 00:00:00 2001 From: abdouconde Date: Tue, 23 Jul 2024 00:42:26 +0200 Subject: [PATCH 6/8] Arrow function's this is the lexical context in wich they have been defined --- index.js | 30 ++++++++++++++++++++++-------- 1 file changed, 22 insertions(+), 8 deletions(-) diff --git a/index.js b/index.js index 496984c..8909c09 100644 --- a/index.js +++ b/index.js @@ -3,23 +3,37 @@ var person1={ name:"Conde Abdourahamane", age: 26, - present: ()=>{ - return "This is "+this.name + " , He is " + this.age - } //This here is always global or window + present: function() + { + setTimeout(function() + { + console.log("This is "+this.name + " , He is " + this.age) + }.bind(this), //We need bind here because we don't use arrow function + 2000) + } } var person2={ name:"Conde Abdourahamane", age: 26, present: function(){ - return "This is "+this.name + " , He is " + this.age - } + setTimeout(()=>{ + console.log("This is "+this.name + " , He is " + this.age) + },2000) // Here, there is no need to bind thanks to arrow function whose this is the surronding context : person2 + } } -var anotherPerson={ +var anotherPerson1={ name: "Conde Souleymane", age: 15, } -console.log(person1.present.call(anotherPerson)) //This is undefined , He is undefined -console.log(person2.present.call(anotherPerson)) //This is Conde Souleymane , He is 15 \ No newline at end of file +var anotherPerson2={ + name: "Conde Karifa", + age: 15, +} + +console.log(person1.present.call(anotherPerson1)) //This is undefined , He is undefined +console.log(person2.present.call(anotherPerson2)) //This is Conde Souleymane , He is 15 + + From 53a3d57ebc4150c74cc9c781b9e5c95f6a257240 Mon Sep 17 00:00:00 2001 From: abdouconde Date: Wed, 24 Jul 2024 00:28:54 +0200 Subject: [PATCH 7/8] arrow function cannot be used as function constructor --- index.js | 47 +++++++++++++---------------------------------- 1 file changed, 13 insertions(+), 34 deletions(-) diff --git a/index.js b/index.js index 8909c09..377ce9d 100644 --- a/index.js +++ b/index.js @@ -1,39 +1,18 @@ -//Arrow function does not have own this, they are attached to the surrounded context +//Arrow function cannot be used as function constructor, Exception: ... Is not a constructor -var person1={ - name:"Conde Abdourahamane", - age: 26, - present: function() - { - setTimeout(function() - { - console.log("This is "+this.name + " , He is " + this.age) - }.bind(this), //We need bind here because we don't use arrow function - 2000) - } -} - -var person2={ - name:"Conde Abdourahamane", - age: 26, - present: function(){ - setTimeout(()=>{ - console.log("This is "+this.name + " , He is " + this.age) - },2000) // Here, there is no need to bind thanks to arrow function whose this is the surronding context : person2 - } -} +function Pyramidian(isu, firstname, lastname){ + this.isu=isu, + this.firstname=firstname, + this.lastname=lastname +} // This works fine -var anotherPerson1={ - name: "Conde Souleymane", - age: 15, -} +var pyramidian= new Pyramidian(1, "Souleymane", "Condé"); -var anotherPerson2={ - name: "Conde Karifa", - age: 15, +var Pyramidien= (isu, firstname, lastname)=>{ + this.isu=isu, + this.firstname=firstname, + this.lastname=lastname } -console.log(person1.present.call(anotherPerson1)) //This is undefined , He is undefined -console.log(person2.present.call(anotherPerson2)) //This is Conde Souleymane , He is 15 - - +// console.log(pyramidian) +console.log(new Pyramidien(1, "Souleymane", "Condé")) \ No newline at end of file From cc4607991ace50d6f67595237a63c8c2ebc040a1 Mon Sep 17 00:00:00 2001 From: abdouconde Date: Wed, 24 Jul 2024 00:41:06 +0200 Subject: [PATCH 8/8] typeof(function instance) = function not object --- index.js | 33 ++++++++++++++++++--------------- 1 file changed, 18 insertions(+), 15 deletions(-) diff --git a/index.js b/index.js index 377ce9d..e8e0a61 100644 --- a/index.js +++ b/index.js @@ -1,18 +1,21 @@ -//Arrow function cannot be used as function constructor, Exception: ... Is not a constructor +/*typeof return's type is "string". The value is : + 1- the underlying primitive type for primitive type operands (string, number, undefined, boolean, etc...) + 2- "object" for all reference types + 3- "object" for null + 4- "function" for functions + */ -function Pyramidian(isu, firstname, lastname){ - this.isu=isu, - this.firstname=firstname, - this.lastname=lastname -} // This works fine + // console.log(typeof(undefined)) //undefined + // console.log(typeof(null)) //object + // console.log(typeof({})) //object + // console.log(typeof([])) //object not array + // console.log(typeof( ()=>{})) //function not object + // console.log(typeof( function(){})) //function not object + // console.log(typeof( function(){})) //function not object -var pyramidian= new Pyramidian(1, "Souleymane", "Condé"); +/* Intanceof : + 1- always return false for primitive types as they don't have function constructor in the proto list + 2- true if the function constructor on the right is in the proto list of the argument -var Pyramidien= (isu, firstname, lastname)=>{ - this.isu=isu, - this.firstname=firstname, - this.lastname=lastname -} - -// console.log(pyramidian) -console.log(new Pyramidien(1, "Souleymane", "Condé")) \ No newline at end of file + + */ \ No newline at end of file