From 072b4f10eb01eabb118cfdce8ea24a45f33159ce Mon Sep 17 00:00:00 2001 From: Rishabh Date: Mon, 24 Feb 2020 10:10:34 +0530 Subject: [PATCH 1/3] initial commit --- 1. objects/1.md | 80 +++++++++++++++++++++++++++------ 1. objects/2.js | 11 +++++ 2. array/1.md | 26 ++++++----- 3. copy-vs-reference/index.js | 13 +++--- 4. array-and-objects/01/main.js | 15 +++++++ 4. array-and-objects/02/main.js | 54 ++++++++++++++++++++++ 4. array-and-objects/03/main.js | 24 ++++++++++ 7 files changed, 192 insertions(+), 31 deletions(-) diff --git a/1. objects/1.md b/1. objects/1.md index 5e2179d..3bcd294 100644 --- a/1. objects/1.md +++ b/1. objects/1.md @@ -1,73 +1,93 @@ 1. Pick a penguin from Wikipedia's List of Fictional Penguins (https://en.wikipedia.org/wiki/List_of_fictional_penguins) and create an object named `myPenguin` with properties that represent the information listed in each column on that Wikipedia page (for example: the character's name, origin, and author). ```js -// your code goes here +var myPenguin ={ + name: "Whiteblack", + origin: "Whiteblack the Penguin sees the world", + author: "H.A. Rey and Margaret Rey", +} + ``` 2. Use console.log() to print the penguin's name to the console as part of a welcome message, like "Hello, I'm a penguin and my name is [NAME HERE]!" ```js -// your code goes here +console.log("Hello, I'm a Penguin and my name is " + myPenguin.name); ``` 3. Write another line of code that adds a new property to your penguin called canFly and set it to false. ```js -// your code goes here +myPenguin.canFly = false; ``` 4. Add a method to your penguin called chirp that prints to the console: "CHIRP CHIRP! Is this what penguins sound like?" ```js -// your code goes here +myPenguin.chirp = function() { + console.log("CHIP CHIRP! IS this what penguins sound like?"); +} ``` 6. Next, call your penguin's sayHello() method and make sure that it works! ```js -// your code goes here + ``` 7. Without modifying any of your previous code, change the penguin's name to "Penguin McPenguinFace" and then call your penguin's sayHello() function one more time to make sure it still works. ```js -// your code goes here +myPenguin.name = "Penguin McPenguinFace"; ``` 8. Write another method called fly, and inside that method, use an if / else statement to print "I can fly!" to the console if your penguin's canFly property is true, or "No flying for me!" if its canFly property is false. ```js -// your code goes here +myPenguin.fly = function() { + if(myPenguin.canFly == true) { + console.log("I can fly!"); + } else { + console.log("No flying for me!"); + } +} + ``` 9. Call your penguin's fly() method and make sure it works! ```js -// your code goes here +myPenguin.fly(); ``` 10. Change the canFly property to true -- again, without modifying any of your previous code! ```js -// your code goes here +myPenguin.canFly = true; ``` 11. Now call your penguin's fly() method again and make sure it works as expected! ```js -// your code goes here +myPenguin.fly(); ``` 12. Write a for ... in loop to print each key to the console. ```js -// your code goes here +for(var i=0;i Date: Tue, 25 Feb 2020 09:38:34 +0530 Subject: [PATCH 2/3] final commit --- 3. copy-vs-reference/index.js | 38 +++++++++++++++++++-------------- 4. array-and-objects/03/main.js | 4 +++- 2 files changed, 25 insertions(+), 17 deletions(-) diff --git a/3. copy-vs-reference/index.js b/3. copy-vs-reference/index.js index 793640e..63f166e 100644 --- a/3. copy-vs-reference/index.js +++ b/3. copy-vs-reference/index.js @@ -36,7 +36,7 @@ console.log(arr == arr2); //false //What's the output console.log([10] === [10]); - +// false // What's the output? function personDetails(person) { @@ -53,8 +53,8 @@ var personObj1 = { age: 30 }; var personObj2 = personDetails(personObj1); -console.log(personObj1); // -> ? -console.log(personObj2); // -> ? +console.log(personObj1); // -> name:Alex Age: 25 +console.log(personObj2); // -> ?name: John Age: 30 // Guess the output var oldArray = []; @@ -62,6 +62,7 @@ var object = {}; object.newArray = oldArray; oldArray.push(10); console.log(object.newArray === oldArray); +//true // Guess the output var a = 5; @@ -69,13 +70,16 @@ var b = a; a = 10; console.log(a); console.log(b); - +//10 +//5 // What's the output? var a = {}; var b = a; a.a = 1; console.log(a); console.log(b); +//1 +//1 // What's the output. var a = []; @@ -84,6 +88,7 @@ a.push(1); console.log(a); // [1] console.log(b); // [1] console.log(a === b); +//true // Clone the object person in clone var person = { @@ -96,6 +101,7 @@ var person = { }; var clone = {}; +clone = {...person}; // Output of the following let brothers = ["John", "Bran", "Robb"]; @@ -118,15 +124,15 @@ let user3 = { brothers: ["John", "Bran", "Robb"] }; // Output of the below code and why? -user.house === user2.house; // output: -user.house == user2.house; // output: -user.brothers === user2.brothers; // output: -user.brothers == user2.brothers; // output: -user.name == user2.name; // output: -user.name === user2.name; // output: -user.brothers == user3.brothers; // output: -user.brothers === user3.brothers; // output: -user.house === user2.house; // output -user.house === user3.house; // output -user.brothers[0] === user2.brothers[0]; // output -user.brothers[0] === user3.brothers[0]; // output +user.house === user2.house; // output: true +user.house == user2.house; // output: true +user.brothers === user2.brothers; // output: true +user.brothers == user2.brothers; // output: true +user.name == user2.name; // output: true +user.name === user2.name; // output: true +user.brothers == user3.brothers; // output: false +user.brothers === user3.brothers; // output: false +user.house === user2.house; // output: true +user.house === user3.house; // output: true +user.brothers[0] === user2.brothers[0]; // output: true +user.brothers[0] === user3.brothers[0]; // output: true diff --git a/4. array-and-objects/03/main.js b/4. array-and-objects/03/main.js index dc68c36..2c00a57 100644 --- a/4. array-and-objects/03/main.js +++ b/4. array-and-objects/03/main.js @@ -21,4 +21,6 @@ var gunter = { var i; for(i in gunter) { console.log(gunter.outfit[i]); - } \ No newline at end of file + } + + \ No newline at end of file From d96fbdef735df9c1f9927bcd418f7c1cd134cc78 Mon Sep 17 00:00:00 2001 From: Rishabh Date: Wed, 18 Mar 2020 10:14:09 +0530 Subject: [PATCH 3/3] final commit --- 1. objects/1.md | 1 + 2. array/1.md | 4 +++- 2 files changed, 4 insertions(+), 1 deletion(-) diff --git a/1. objects/1.md b/1. objects/1.md index 3bcd294..5192476 100644 --- a/1. objects/1.md +++ b/1. objects/1.md @@ -33,6 +33,7 @@ myPenguin.chirp = function() { ```js + ``` 7. Without modifying any of your previous code, change the penguin's name to "Penguin McPenguinFace" and then call your penguin's sayHello() function one more time to make sure it still works. diff --git a/2. array/1.md b/2. array/1.md index b6bab49..e6ec3a5 100644 --- a/2. array/1.md +++ b/2. array/1.md @@ -31,13 +31,14 @@ var fourthColor = array[3]; 6.Add another color to the end of the list. ```js -array.push("brown"); +array.push("purple"); ``` 7.Add another color to the beginning of the list. ```js // your code goes here +array.unshift("cyan"); ``` 8. Print the length of the array to the console with console.log() @@ -49,6 +50,7 @@ console.log(array.length); 9.Remove the last color from the end of list, and then print the length of the array to the console one more time. ```js +array.pop(); ```