From 23b5c2d21b936201306025ae6b7d670046dbd38a Mon Sep 17 00:00:00 2001 From: sunny Date: Tue, 10 Sep 2019 20:08:01 +0530 Subject: [PATCH 1/4] update assignment --- .DS_Store | Bin 0 -> 6148 bytes 1. objects/1.md | 100 ++++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 100 insertions(+) create mode 100644 .DS_Store diff --git a/.DS_Store b/.DS_Store new file mode 100644 index 0000000000000000000000000000000000000000..20a3d41803a2845b60b3a241cbf885b8df250157 GIT binary patch literal 6148 zcmeHK&2G~`5T0!VY>W^&RBDgDAaQ7`m;`!2NG7C*9*_`5Z~)ZWv7tt;H;SF6X$bO# zhkyq_;!$`49)t&gZ+}4fX*r?@?L@QRcz0&j`^BF15)tbRV~?moL>wxy=AgMiHkHXez*4AVRrsNghC;PUE4n#W?)5yLz#RGvT&a9-#2!^YNR(rS9!ZoBPG zx82F!UK4if-gH{$o433N2S+F4^U3?^hfiub#8AML+%)(bKEt?>pwnQGXCi-#aT&|$ zjv_In0e&Hk7YO_cpIHJosHOaSpuJCH+M!bv%^k!h^ad(1M=4F_^RUgOJni{;kt0N8 z4E)O<%04dS;dEE!N$3pa8!K3t_s4>Nou1M@J)|x@2JX@c#q$yBk@+(7$RL50Rbs$A z^8ETL-ITo-%YbEIB^Z$P!G%in4OSXe=|H270Kgi$mB5yt3o^zv=o_pwVg$l;C{Two zbHrde9R05G^9@!SbvQ9|_+VycW=<$f&5r!8awq0%w5?^pGBD4;y1s14{eS=R^Z$I1 zy|N5g2L3AsSgjj$J6Mw0TbC9m_gWWv1eGHFDvc@xjoFTsA-Cc!s1l61(g6AfD~;%Z P*bf0kgKaDW|CE7W4AQ5) literal 0 HcmV?d00001 diff --git a/1. objects/1.md b/1. objects/1.md index 5110277..45f2654 100644 --- a/1. objects/1.md +++ b/1. objects/1.md @@ -2,72 +2,143 @@ ```js // your code goes here + +var myPenguin = { + penguin : { + name : "Patrick", + canFly : false, + hello : function sayHello(){ + return (`Hello, I'm a penguin and my name is ${myPenguin.penguin.name}!`); + }, + chirp : function chrip(){ + return "CHIRP CHIRP! Is this what penguins sound like?"; + }, + fly : function fly(){ + if (canFly == true) { + consloe.log("I can fly!"); + } else { + console.log("No flying for me!"); + } + } + } , + 1 : { "Literature": + { + 1.1 : "comics" + } + }, + 2 : "Theatre", + 3 : {"in media": + { + 3.1 : "Animations", + 3.2 : "video games", + 3.3 : " Other media (toys, mascots, logos, etc.)" + } + }, + 4 : "See also", + 5 : "References", +}; +for(let key in myPenguin){ + console.log(Object.keys(myPenguin.penguin); +} + + + + ``` 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 + canFly : false +console.log(myPenguin["penguin"]["canFly"]) ``` 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 +chirp : chrip(){ + return "CHIRP CHIRP! Is this what penguins sound like?" + } +console.log(myPenguin.penguin.chrip) ``` 6. Next, call your penguin's sayHello() method and make sure that it works! ```js // your code goes here +hello : sayHello(){ + return `Hello, I'm a penguin and my name is ${this.name}!` + }, ``` 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["penguin"]["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 +fly : function fly(){ + if (canFly == true) { + consloe.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["penguin"]["fly"] ``` 10. Change the canFly property to true -- again, without modifying any of your previous code! ```js // your code goes here +myPenguin["penguin"]["canFly" = true ] ``` 11. Now call your penguin's fly() method again and make sure it works as expected! ```js // your code goes here +myPenguin["penguin"]["fly"] ``` 12. Write a for ... in loop to print each key to the console. (Hint: See this page for an example of this special type of loop.) ```js // your code goes here +for(let key in myPenguin){ + console.log(key); +} ``` 13. Write another for ... in loop to print the value of each key to the console. (Hint: You'll need to use bracket notation to access the values this way, instead of dot notation!) ```js // your code goes here +for(let key in myPenguin){ + console.log(myPenguin.key); + +} ``` ## Exercise 2 @@ -84,6 +155,13 @@ ```js // your code goes here +let favouriteRecepie = { + title: Mole, + serves: 2, + ingrediants: ["cinnamon","cumin","cocoa"] +} + + ``` 15. Keep track of which books you read and which books you want to read! @@ -94,4 +172,26 @@ ```js // your code goes here +let books = [ + { + title : "Eclipse", + author : "Stephenie Meyer", + alreadyRead : true, + }, + { + title : "Harry Potter", + author : "J.K Rowling", + alreadyRead : false, + } +]; + +for (let book in books) { + console.log(`${books[book]["title"]} by ${books[book]["author"]}`); + if (books[book]["alreadyRead"]) { + console.log(`You already read ${books[book]["title"]} by ${books[book]["author"]}`); + } + else { + console.log(`You still need to read ${books[book]["title"]} by ${books[book]["author"]}`); + } +} ``` From 3685763ece6a9f957e2a21273f4fad4512d91425 Mon Sep 17 00:00:00 2001 From: sunny Date: Tue, 10 Sep 2019 21:38:32 +0530 Subject: [PATCH 2/4] update arrays --- .DS_Store | Bin 6148 -> 6148 bytes 2. array/1.md | 27 +++++++++++++++++++++++++++ 2 files changed, 27 insertions(+) diff --git a/.DS_Store b/.DS_Store index 20a3d41803a2845b60b3a241cbf885b8df250157..791ed77c7ddea8aa1be5f95f5a64df9ef6264508 100644 GIT binary patch delta 50 zcmZoMXfc@J&&atkU^g=(=VS*KiOni335=6NSOs~?f{XHU^7GOe7#J8gH?pQNZD!~A G%MSo+)D9Q` delta 36 scmZoMXfc@J&&aVcU^g=($7BZ Date: Tue, 10 Sep 2019 22:43:44 +0530 Subject: [PATCH 3/4] update assignments --- 1. objects/1.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/1. objects/1.md b/1. objects/1.md index 45f2654..de7b35a 100644 --- a/1. objects/1.md +++ b/1. objects/1.md @@ -1,4 +1,4 @@ -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). + 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 From 5f9830c6d45ed525bca43a9e8de9172dc0e1c511 Mon Sep 17 00:00:00 2001 From: sunny Date: Sun, 15 Sep 2019 22:33:35 +0530 Subject: [PATCH 4/4] update assignments --- .DS_Store | Bin 6148 -> 8196 bytes 1. objects/1.md | 4 +- 1. objects/2.js | 43 +++++++++++-- 2. array/1.md | 2 +- 3. copy-vs-reference/index.js | 48 +++++++++++--- 4. array-and-objects/.DS_Store | Bin 0 -> 6148 bytes 4. array-and-objects/01/main.js | 46 +++++++++++++ 4. array-and-objects/02/main.js | 87 +++++++++++++++++++++++++ 4. array-and-objects/03/main.js | 110 ++++++++++++++++++++++++++++++++ 5. extra/.DS_Store | Bin 0 -> 6148 bytes 10 files changed, 323 insertions(+), 17 deletions(-) create mode 100644 4. array-and-objects/.DS_Store create mode 100644 5. extra/.DS_Store diff --git a/.DS_Store b/.DS_Store index 791ed77c7ddea8aa1be5f95f5a64df9ef6264508..9abcdf96c0920d88f929c5f603b93f5c13009389 100644 GIT binary patch delta 320 zcmZoMXmOBWU|?W$DortDU;r^WfEYvza8E20o2aMAD6lbLH}hr%jz7$c**Q2SHn1=X zOm<+An5@Ebgw4oMN5RBs@;jF0lOtGeOm1P#n!Jov9mt-5kaC*5gjJKLEVw8yCqFM8 zWZC4GtlpE~uxg^K0|~jZ3Qjg-)0=FQaK;NrR973rJ>Ud(5NWpCGXemh CR#1xo delta 143 zcmZp1XfcprU|?W$DortDU=RQ@Ie-{Mvv5r;6q~50$jG@dU^g=(=VS)~iOJ?7e3Oj? zwoO(Q@|bKOm^!&mC~|Uyh&oVQe)4`%!O06m ? -console.log(personObj2); // -> ? +console.log(personObj1); // -> {name: "Alex",age: 30} +console.log(personObj2); // -> {name: "John",age: 50} // Guess the output var oldArray = []; @@ -61,20 +90,21 @@ var object = {}; object.newArray = oldArray; oldArray.push(10); console.log(object.newArray === oldArray); +// true // Guess the output var a = 5; var b = a; a = 10; -console.log(a); -console.log(b); +console.log(a); //10 +console.log(b); //5 // What's the output? var a = {}; var b = a; a.a = 1; -console.log(a); -console.log(b); +console.log(a); //{a:1} +console.log(b); //{a:1} // What's the output. var a = []; @@ -82,7 +112,7 @@ var b = a; a.push(1); console.log(a); // [1] console.log(b); // [1] -console.log(a === b); +console.log(a === b); //true // Clone the object person in clone var person = { @@ -94,4 +124,6 @@ var person = { } }; -var clone = {}; +var clone = {...person}; +//OR +clone = Object.assign(person); \ No newline at end of file diff --git a/4. array-and-objects/.DS_Store b/4. array-and-objects/.DS_Store new file mode 100644 index 0000000000000000000000000000000000000000..9869cc1925c4f124fe255965cd31ecfbe11484f6 GIT binary patch literal 6148 zcmeH~&r8EF6vvZoYBmvf5cJrK;9-Zg6?YJ!Og(rLDtb_vtsAaT8`(OC&Po3b{SW+8 z{0sbZ^u6RM?1x81M;;{Km*l;)`9PY6F~;k?rp;KHF(#m(7D`Y}F&xJ-VL9q4f^wWA zjAaNuPPR>BMhpQ%;O`Q^y_;iIW*@}za%}%@yem^LuVTV}_l9C#!<#tjrq${j&*ckq z^9w?hL}{sX?zd&%PlL4Atp}Y`Y#jz^J0$-|%J|CsM&&$ zvy&)k%6?t;l4e)U0jSQ4GB6N|&M)`D^Y1r6getttg7I*yftNAVgIWiV!; W1L~1xTA>Hb{0JxvrZNP6mB0t--|030 literal 0 HcmV?d00001 diff --git a/4. array-and-objects/01/main.js b/4. array-and-objects/01/main.js index e69de29..c34c817 100644 --- a/4. array-and-objects/01/main.js +++ b/4. array-and-objects/01/main.js @@ -0,0 +1,46 @@ + +var foods =["pizza","burger","pasta","takos"]; +var myPenguin = { + name : "Patrick", + canFly : false, + sayHello : function sayHello(){ + return (`Hello, I'm a penguin and my name is ${myPenguin.penguin.name}!`); + }, + chirp : function chrip(){ + return "CHIRP CHIRP! Is this what penguins sound like?"; + }, + fly : function fly(){ + if (canFly == true) { + consloe.log("I can fly!"); + } else { + console.log("No flying for me!"); + } + } , + favouriteFoods: foods, + firstFavFood : foods[1], + lastFavFood : favouriteFoods[favouriteFoods.length - 1], + 1 : { "Literature": + { + 1.1 : "comics" + } + }, + 2 : "Theatre", + 3 : {"in media": + { + 3.1 : "Animations", + 3.2 : "video games", + 3.3 : " Other media (toys, mascots, logos, etc.)" + } + }, + 4 : "See also", + 5 : "References", +}; +console.log(myPenguin["favouriteFoods"][1]); + myPenguin["favouriteFoods"].push("takos"); +console.log(myPenguin["favouriteFoods"].length); + +for (i = 0; i<(myPenguin["favouriteFoods"].length);i++){ + console.log(myPenguin["favouriteFoods"][i]); + } + + diff --git a/4. array-and-objects/02/main.js b/4. array-and-objects/02/main.js index e69de29..b5baa6b 100644 --- a/4. array-and-objects/02/main.js +++ b/4. array-and-objects/02/main.js @@ -0,0 +1,87 @@ +var gunter = { + name: "Gunter", + origin: "Adventure Time", + canFly: false, + sayHello: function () { + console.log("QUACK!!!"); + } + }; + + var ramon = { + name: "Ramón", + origin: "Happy Feet", + canFly: true, + sayHello: function () { + console.log("Estoy encantado de conocerle."); + } + }; + + var fred = { + name: "Fred", + origin: "Sitting Ducks", + canFly: false, + sayHello: function () { + console.log("Hi there!"); + } + }; + + var penguins = [gunter , ramon , fred]; + +var foods =["pizza","burger","pasta","takos"]; +var myPenguin = { + name : "Patrick", + canFly : false, + sayHello : function (){ + return (`Hello, I'm a penguin and my name is ${myPenguin.penguin.name}!`); + }, + chirp : function chrip(){ + return "CHIRP CHIRP! Is this what penguins sound like?"; + }, + fly : function fly(){ + if (canFly == true) { + consloe.log("I can fly!"); + } else { + console.log("No flying for me!"); + } + } , + favouriteFoods: foods, + firstFavFood : favouriteFoods[1], + lastFavFood : favouriteFoods[favouriteFoods.length - 1], + 1 : { "Literature": + { + 1.1 : "comics" + } + }, + 2 : "Theatre", + 3 : {"in media": + { + 3.1 : "Animations", + 3.2 : "video games", + 3.3 : " Other media (toys, mascots, logos, etc.)" + } + }, + 4 : "See also", + 5 : "References", +}; + console.log(penguins[0]); + var secondPenguin = penguins[1]; + console.log(penguins[2]); + penguins.push(myPenguin); + console.log(penguins.length); + gunter.canFly = true; + gunter.sayHello(); + for (let penguin in penguins){ + console.log (penguins[penguin]); + } + for (var penguin in penguins){ + console.log(penguins[penguin].sayHello()); + } + for (var penguin in penguins){ + console.log(penguins[penguin].noOfFeet = 2); + } + for (var penguin in penguins){ + if (penguins[penguin].canFly === true) { + console.log(`penguin ${penguins[penguin].name} can Fly`); + } + } + \ No newline at end of file diff --git a/4. array-and-objects/03/main.js b/4. array-and-objects/03/main.js index e69de29..3a67c4c 100644 --- a/4. array-and-objects/03/main.js +++ b/4. array-and-objects/03/main.js @@ -0,0 +1,110 @@ +var gunter = { + name: "Gunter", + origin: "Adventure Time", + canFly: false, + sayHello: function () { + console.log("QUACK!!!"); + }, + favouriteFoods: foods, + firstFavFood : favouriteFoods[1], + lastFavFood : favouriteFoods[favouriteFoods.length - 1], + outFit :outfit , + }; + + var ramon = { + name: "Ramón", + origin: "Happy Feet", + canFly: true, + sayHello: function () { + console.log("Estoy encantado de conocerle."); + }, + favouriteFoods: foods, + firstFavFood : favouriteFoods[1], + lastFavFood : favouriteFoods[favouriteFoods.length - 1], + outFit :outfit , + }; + + var fred = { + name: "Fred", + origin: "Sitting Ducks", + canFly: false, + sayHello: function () { + console.log("Hi there!"); + }, + favouriteFoods: foods, + firstFavFood : foods[1], + lastFavFood : foods[foods.length - 1], + outFit :outfit , + }; + +var myPenguin = { + name : "Patrick", + canFly : false, + sayHello : function (){ + return (`Hello, I'm a penguin and my name is ${myPenguin.penguin.name}!`); + }, + chirp : function chrip(){ + return "CHIRP CHIRP! Is this what penguins sound like?"; + }, + fly : function fly(){ + if (canFly == true) { + consloe.log("I can fly!"); + } else { + console.log("No flying for me!"); + } + } , + favouriteFoods: foods, + firstFavFood : foods[1], + lastFavFood : foods[foods.length - 1], + outFit :outfit , + + 1 : { "Literature": + { + 1.1 : "comics" + } + }, + 2 : "Theatre", + 3 : {"in media": + { + 3.1 : "Animations", + 3.2 : "video games", + 3.3 : " Other media (toys, mascots, logos, etc.)" + } + }, + 4 : "See also", + 5 : "References", +}; +var outfit = { + hat : "baseball cap", + shirt : "Hawaiian shirt", + pants : "cargo shorts", + shoes : "flip-flops" +} +for (var penguin in penguins) { + penguin["outFit"] = outfit; +} +var penguins = [gunter , ramon , fred, myPenguin]; +var foods =["pizza","burger","pasta","takos"]; +for (var penguin in penguins){ + penguinHatType = penguin["outFit"].hat; +} +for (var penguin in penguins) { + penguin["outFit"].accessory = "pocket watch"; +} +for (var penguin in penguins) { + penguin["outfit"].hat = "top hat"; +} +for (var penguin in penguins) { + delete penguin["outFit"].pants; +} +for (var penguin in penguins) { + console.log(`${penguins[penguin].outFit}`); +} + + + + + + + + \ No newline at end of file diff --git a/5. extra/.DS_Store b/5. extra/.DS_Store new file mode 100644 index 0000000000000000000000000000000000000000..4018d0718f3317cba7264d4126ef61f1fb9c3eeb GIT binary patch literal 6148 zcmeHK!AiqG5Z!I7ZYyFBf*x}bJa}kS>_LQ3_0XFT(SwR6w%9<-N}F0VR`MJAM}C2y zqcgkHf>uw0NST4zH`$%pFfU#Hx{Z|&WPNx=AogWfIqyoR@N)Jto%H(4l_W@hJU&T+U9Sq@@Q9 z-A`IQvyX2Vlq#$8MRg_1HaFaLXKTY9t~*)1UITk`dpInshy5MnE~ICXM`nN-_{;$Iejrt>{|7(!|Hg?2W`G%(P6lLY-`{UQZd6+*vcy{J tfL?;4pkHor90Go5%sXfRdW5+}m;vF7fT4j0X5dd5_yC=6RmcDU literal 0 HcmV?d00001