From 894baac62d03b3698eb8cf7fd12d254528a7e33d Mon Sep 17 00:00:00 2001 From: azadaafo Date: Mon, 18 May 2020 06:27:31 +0100 Subject: [PATCH 01/19] completed InClass/A-objects-intro/exercise-part-0.js --- week-4/InClass/A-objects-intro/exercise-part-0.js | 15 ++++++++++++++- 1 file changed, 14 insertions(+), 1 deletion(-) diff --git a/week-4/InClass/A-objects-intro/exercise-part-0.js b/week-4/InClass/A-objects-intro/exercise-part-0.js index 58d6d28e7..2512a3c97 100644 --- a/week-4/InClass/A-objects-intro/exercise-part-0.js +++ b/week-4/InClass/A-objects-intro/exercise-part-0.js @@ -4,4 +4,17 @@ Describe your own laptop as a JavaScript object Try to think of as many properties as you can! -*/ \ No newline at end of file +*/ + +let myLaptop = { + brand: "Dell", + screenSize: 15, + ram: 16, + diskType: "SSD", + screenTouch: false, + batteryLife: "6 hr", + multiLanguage: true, + bulitInCamera: true, + externalSpeakers: false, + antiVirusInstalled: "Yes" +} \ No newline at end of file From 2c03bac7a46ac8fb602dea323be9acc3fce81ad3 Mon Sep 17 00:00:00 2001 From: azadaafo Date: Mon, 18 May 2020 06:42:25 +0100 Subject: [PATCH 02/19] completed InClass/A-objects-intro/exercise-part-1.js --- .../A-objects-intro/exercise-part-1.js | 43 +++++++++++++++++++ 1 file changed, 43 insertions(+) diff --git a/week-4/InClass/A-objects-intro/exercise-part-1.js b/week-4/InClass/A-objects-intro/exercise-part-1.js index 44cdf0ee0..d8c5285df 100644 --- a/week-4/InClass/A-objects-intro/exercise-part-1.js +++ b/week-4/InClass/A-objects-intro/exercise-part-1.js @@ -6,4 +6,47 @@ can describe with a JavaScript object Assign each of them to a separate variable */ +let person = { + hight: 185, + weight: 80, + hairColor: "black", + smoker: false +} +let location = { + cityName: "Manchester", + population: 600000, + highBuildings: "yes", + diverseCity: true +} + +let CYF = { + purpose: "educational", + helpfull: true, + supportLevel: "very high", + encouraging: true, + numOfMentors: 10, + numOfStudents: 25 +} + +let homework = { + hardPart: "functions and loops", + useful: "not for me until now", + harm: "I lost my confidence", + whyThat: "online style and missed some impo parts", + longValues: true, + reason: "wanted to deliver my feedback", + percentOfHelpNeeded: 100, + didYouUnderstandObjects: "except functions and loops part" +} + +let feelings = { + LikeTheCourse: true, + hoursDevotedPerDay: 5, + goodResources: "not enough", + oldStyleOrNew: "old", + interestedInTheCourse: "of course", + didIrunMyObjects: true +} + +console.log(feelings, homework, CYF); From f62f28b77270e2d9c9404a7097aecfc9b99f97ec Mon Sep 17 00:00:00 2001 From: azadaafo Date: Mon, 18 May 2020 06:44:43 +0100 Subject: [PATCH 03/19] completed InClass/A-objects-intro/exercise-part-2.js --- .../InClass/A-objects-intro/exercise-part-2.js | 17 +++++++++-------- 1 file changed, 9 insertions(+), 8 deletions(-) diff --git a/week-4/InClass/A-objects-intro/exercise-part-2.js b/week-4/InClass/A-objects-intro/exercise-part-2.js index 356828587..5fa65dda7 100644 --- a/week-4/InClass/A-objects-intro/exercise-part-2.js +++ b/week-4/InClass/A-objects-intro/exercise-part-2.js @@ -5,17 +5,18 @@ The objects below have some syntax issues - try and fix them all! */ let kitten = { - fur colour: "orange", - age "23" + furColour: "orange", + age: 23 }; -let laptop = - brand: "Lenovo" - ram "5GB" +let laptop = { + brand: "Lenovo", + ram: "5GB" } let phone = { - operating system "iOS", + operatingSystem: "iOS", hasStylus: true, - megapixels 12 - "batteryLife": "24 hours" \ No newline at end of file + megapixels: 12, + batteryLife: "24 hours" +} \ No newline at end of file From ca832e131a35b6f47a60b8604f506ae2c329f70e Mon Sep 17 00:00:00 2001 From: azadaafo Date: Mon, 18 May 2020 06:49:24 +0100 Subject: [PATCH 04/19] completed InClass/A-objects-intro/exercise-part-3.js --- week-4/InClass/A-objects-intro/exercise-part-3.js | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/week-4/InClass/A-objects-intro/exercise-part-3.js b/week-4/InClass/A-objects-intro/exercise-part-3.js index 491c6a064..d9a7b4898 100644 --- a/week-4/InClass/A-objects-intro/exercise-part-3.js +++ b/week-4/InClass/A-objects-intro/exercise-part-3.js @@ -6,11 +6,14 @@ declared above in Part 1 and 2, reading everything that happens out loud. Make sure each member of your group has read at least one variable! Make sure you use words like: -- object literal +- object literal: - property - value -- string / number / boolean -- declaring a variable +- string what we put between ("") / number: true number or float number or called integer / boolean is true or false +- declaring a variable we declare a variable using three keywords: let, const, and var. - etc. -*/ \ No newline at end of file +*/ +- object literal: is every thing between the curle braces { } +- property: within an objectusually on the left side and we assign values to it + - value: values we assigned to a property to describe an object. From 3427e1e467d9ab4c917f88b5cdcd52192befebc9 Mon Sep 17 00:00:00 2001 From: azadaafo Date: Mon, 18 May 2020 06:52:34 +0100 Subject: [PATCH 05/19] completed InClass/B-objects-get-set/exercise-1.js --- week-4/InClass/B-objects-get-set/exercise-1.js | 3 +++ 1 file changed, 3 insertions(+) diff --git a/week-4/InClass/B-objects-get-set/exercise-1.js b/week-4/InClass/B-objects-get-set/exercise-1.js index 4fd71e60b..9b05d30e2 100644 --- a/week-4/InClass/B-objects-get-set/exercise-1.js +++ b/week-4/InClass/B-objects-get-set/exercise-1.js @@ -10,6 +10,9 @@ let kitten = { // YOUR CODE GOES BELOW HERE +console.log(kitten.ageMonths); +console.log(kitten.isFemale); +console.log(kitten.furColour); From 64e09c2a77e024e8dda0146c8c04d7f13f518bd2 Mon Sep 17 00:00:00 2001 From: azadaafo Date: Mon, 18 May 2020 06:54:42 +0100 Subject: [PATCH 06/19] completed InClass/B-objects-get-set/exercise-2.js --- week-4/InClass/B-objects-get-set/exercise-2.js | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/week-4/InClass/B-objects-get-set/exercise-2.js b/week-4/InClass/B-objects-get-set/exercise-2.js index efdb092b1..fed82e3a6 100644 --- a/week-4/InClass/B-objects-get-set/exercise-2.js +++ b/week-4/InClass/B-objects-get-set/exercise-2.js @@ -5,14 +5,14 @@ */ let phone = { - brand: 'iPhone, - model 'iPhone X' + brand: 'iPhone', + model: 'iPhone X', launchYear: 2017, - is Unlocked: true -; + isUnlocked: true +}; -let phoneBrand = phone.bbrand; -let phoneLaunchYear = phone[launchYear]; +let phoneBrand = phone.brand; +let phoneLaunchYear = phone["launchYear"]; // DO NOT MODIFY BELOW THIS LINE From 2b69f9b8123350672af09a3ed0ef19ce21faccf4 Mon Sep 17 00:00:00 2001 From: azadaafo Date: Mon, 18 May 2020 06:57:08 +0100 Subject: [PATCH 07/19] completed InClass/B-objects-get-set/exercise-3.js --- week-4/InClass/B-objects-get-set/exercise-3.js | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/week-4/InClass/B-objects-get-set/exercise-3.js b/week-4/InClass/B-objects-get-set/exercise-3.js index 1f057083b..cc0441e65 100644 --- a/week-4/InClass/B-objects-get-set/exercise-3.js +++ b/week-4/InClass/B-objects-get-set/exercise-3.js @@ -3,7 +3,9 @@ */ // WRITE CODE BELOW THIS - +let kitten = { + name: "Gilbert" +} // WRITE CODE ABOVE THIS console.log(kitten.name); From 1df8c4fe3b72e97391b9a566238cc9e2278a13f2 Mon Sep 17 00:00:00 2001 From: azadaafo Date: Mon, 18 May 2020 06:59:10 +0100 Subject: [PATCH 08/19] completed InClass/B-objects-get-set/exercise-4.js --- week-4/InClass/B-objects-get-set/exercise-4.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/week-4/InClass/B-objects-get-set/exercise-4.js b/week-4/InClass/B-objects-get-set/exercise-4.js index 4947cb50f..5e1a98438 100644 --- a/week-4/InClass/B-objects-get-set/exercise-4.js +++ b/week-4/InClass/B-objects-get-set/exercise-4.js @@ -8,8 +8,8 @@ let dog = { }; // WRITE CODE BELOW THIS LINE - - +dog.name = "Rex", + dog.wantsToPlay = true // WRITE CODE ABOVE THIS LINE From 12eaa09d18211974aa52dd59237ae791dee8f69b Mon Sep 17 00:00:00 2001 From: azadaafo Date: Mon, 18 May 2020 07:06:03 +0100 Subject: [PATCH 09/19] completed InClass/C-more-complex-objects/exercise-1.js --- .../C-more-complex-objects/exercise-1.js | 26 ++++++++++--------- 1 file changed, 14 insertions(+), 12 deletions(-) diff --git a/week-4/InClass/C-more-complex-objects/exercise-1.js b/week-4/InClass/C-more-complex-objects/exercise-1.js index ae8fea487..db9402600 100644 --- a/week-4/InClass/C-more-complex-objects/exercise-1.js +++ b/week-4/InClass/C-more-complex-objects/exercise-1.js @@ -5,12 +5,12 @@ */ let house = { - address: "1 Kinning Park", - previousOwners: ["Claire M.", "John A."], - currentOwner: { - firstName: "Margaret", - lastName: "Conway" - } + address: "1 Kinning Park", + previousOwners: ["Claire M.", "John A."], + currentOwner: { + firstName: "Margaret", + lastName: "Conway" + } }; /* @@ -20,14 +20,16 @@ let house = { */ // - change the address of "house" to '51 Berkley Road' +house.address = "51 Berkley Road" // - change the previous owners of "house" to ["Brian M.", "Fiona S."] -// - change the last name of the current owner of "house" to "Montgomery" +house.previousOwners = ["Brian M.", "Fiona S."], + // - change the last name of the current owner of "house" to "Montgomery" + house.currentOwner.lastName = "Montgomery", + /* + DO NOT EDIT ANYTHING BELOW THIS LINE + */ -/* - DO NOT EDIT ANYTHING BELOW THIS LINE -*/ - -console.log("Expected result: 51 Berkley Road. Actual result: " + house.address); + console.log("Expected result: 51 Berkley Road. Actual result: " + house.address); console.log("Expected result: Brian M., Fiona S. Actual result: " + house.previousOwners.toString()); console.log("Expected result: Montgomery. Actual result: " + house.currentOwner.lastName); \ No newline at end of file From b8f6c387040e5012c4cc034a5321bbbd1f634929 Mon Sep 17 00:00:00 2001 From: azadaafo Date: Mon, 18 May 2020 07:11:33 +0100 Subject: [PATCH 10/19] completed InClass/C-more-complex-objects/exercise-2.js --- .../C-more-complex-objects/exercise-2.js | 28 ++++++++++--------- 1 file changed, 15 insertions(+), 13 deletions(-) diff --git a/week-4/InClass/C-more-complex-objects/exercise-2.js b/week-4/InClass/C-more-complex-objects/exercise-2.js index 69b3768aa..5f18b2c79 100644 --- a/week-4/InClass/C-more-complex-objects/exercise-2.js +++ b/week-4/InClass/C-more-complex-objects/exercise-2.js @@ -6,17 +6,17 @@ */ let house = { - address: "1 Kinning Park", - previousOwners: ["Claire M.", "John A."], - currentOwner: { - firstName: "Margaret", - lastName: "Conway" - } + address: "1 Kinning Park", + previousOwners: ["Claire M.", "John A."], + currentOwner: { + firstName: "Margaret", + lastName: "Conway" + } }; let newCurrentOwner = { - firstName: "Georgina", - lastName: "Hernandez" + firstName: "Georgina", + lastName: "Hernandez" }; /* @@ -26,9 +26,11 @@ let newCurrentOwner = { */ // - assign the value of the variable 'newCurrentOwner' as the value to the house's "currentOwner" -// - from the list of previous owners, replace only "John A." with "Stephen B." -// - give the house a new property called 'isForSale' with the value 'false' - +house.currentOwner = newCurrentOwner, + // - from the list of previous owners, replace only "John A." with "Stephen B." + house.previousOwners[1] = "Stephen B.", + // - give the house a new property called 'isForSale' with the value 'false' + house.isForSale = false @@ -36,7 +38,7 @@ let newCurrentOwner = { DO NOT EDIT ANYTHING BELOW THIS LINE */ console.log( - "Did you correctly assign the new owner using the given variable?", - `Expected result: true. Actual result: ${(house.currentOwner === newCurrentOwner)}`); + "Did you correctly assign the new owner using the given variable?", + `Expected result: true. Actual result: ${(house.currentOwner === newCurrentOwner)}`); console.log(`Expected result: Claire M., Stephen B.Actual result: ${house.previousOwners.toString()}`); console.log(`Expected result: false.Actual result: ${house.isForSale}`); \ No newline at end of file From ee620e221bfc49ae28bf0efc10610aa067940f22 Mon Sep 17 00:00:00 2001 From: azadaafo Date: Tue, 19 May 2020 04:28:24 +0100 Subject: [PATCH 11/19] completed InClass/C-more-complex-objects/exercise-3.js --- .../C-more-complex-objects/exercise-3.js | 34 +++++++++---------- 1 file changed, 17 insertions(+), 17 deletions(-) diff --git a/week-4/InClass/C-more-complex-objects/exercise-3.js b/week-4/InClass/C-more-complex-objects/exercise-3.js index f461e7d64..efb2e77ec 100644 --- a/week-4/InClass/C-more-complex-objects/exercise-3.js +++ b/week-4/InClass/C-more-complex-objects/exercise-3.js @@ -5,23 +5,23 @@ */ let kinningParkHouse = { - address: "1 Kinning Park", - price: 180000, - currentOwner: { - firstName: "Margaret", - lastName: "Conway", - email: "margaret@fake-emails.com" - } + address: "1 Kinning Park", + price: 180000, + currentOwner: { + firstName: "Margaret", + lastName: "Conway", + email: "margaret@fake-emails.com" + } }; let parkAvenueHouse = { - address: "50 Park Avenue", - price: 195000, - currentOwner: { - firstName: "Marie", - lastName: "McDonald", - email: "marie.m@real-emails.com" - } + address: "50 Park Avenue", + price: 195000, + currentOwner: { + firstName: "Marie", + lastName: "McDonald", + email: "marie.m@real-emails.com" + } }; /* @@ -32,17 +32,17 @@ let parkAvenueHouse = { // returns the full name (first name + last name) of the owner of the house function getOwnerFullName(house) { - + return `${kinningParkHouse.currentOwner.firstName} ${kinningParkHouse.currentOwner.lastName}` } // returns an array of the owners' email addresses of the two houses function getEmailAddresses(house1, house2) { - + return [house1.currentOwner.email, house2.currentOwner.email] } // returns the address for the cheapest house out of the two function getCheapestAddress(house1, house2) { - + return house1.price < house2.price ? house1.address : house2.address } From fc34b36e89ab9539937c79e1036aa8a5874a99cd Mon Sep 17 00:00:00 2001 From: azadaafo Date: Tue, 19 May 2020 04:35:10 +0100 Subject: [PATCH 12/19] completed InClass/D-methods/exercise-1.js --- week-4/InClass/D-methods/exercise-1.js | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/week-4/InClass/D-methods/exercise-1.js b/week-4/InClass/D-methods/exercise-1.js index 8de0f8c30..183cb1f51 100644 --- a/week-4/InClass/D-methods/exercise-1.js +++ b/week-4/InClass/D-methods/exercise-1.js @@ -6,9 +6,12 @@ Add a method "greet" so this person can say hello. let person = { name: "Alice", - age: 25 + age: 25, + greet: function () { + return "hello everybody"; + }, }; - +person.greet(); /* DO NOT EDIT ANYTHING BELOW THIS LINE From d34bf9e408d4e8587d7ddb4123c0675fb3dd648b Mon Sep 17 00:00:00 2001 From: azadaafo Date: Tue, 19 May 2020 04:37:42 +0100 Subject: [PATCH 13/19] completed InClass/D-methods/exercise-2.js --- week-4/InClass/D-methods/exercise-2.js | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/week-4/InClass/D-methods/exercise-2.js b/week-4/InClass/D-methods/exercise-2.js index 8e993fc69..f0359aa96 100644 --- a/week-4/InClass/D-methods/exercise-2.js +++ b/week-4/InClass/D-methods/exercise-2.js @@ -7,9 +7,12 @@ Hint: use 'this' keyword to access the name property. let person = { name: "Alice", - age: 25 + age: 25, + sayName: function () { + return "My name is " + this.name; + }, }; - +person.sayName(); /* DO NOT EDIT ANYTHING BELOW THIS LINE From c6cb511ca2cd172aeb95607b14bdf8673c0a1177 Mon Sep 17 00:00:00 2001 From: azadaafo Date: Tue, 19 May 2020 04:42:03 +0100 Subject: [PATCH 14/19] completed InClass/D-methods/exercise-3.js --- week-4/InClass/D-methods/exercise-3.js | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/week-4/InClass/D-methods/exercise-3.js b/week-4/InClass/D-methods/exercise-3.js index be237483b..bbeed78b8 100644 --- a/week-4/InClass/D-methods/exercise-3.js +++ b/week-4/InClass/D-methods/exercise-3.js @@ -7,12 +7,12 @@ Once you fix them, run this file, it should output the correct values! let person = { name: "Alice", age: 25, - currentAddress: "Glasgow", - changeAddress: (newAddress) { + currentAddress: "Edinburgh", + changeAddress: function (newAddress) { currentAddress = newAddress; }, - celebrateBirthday: function { - that.age = that.age + 1; + celebrateBirthday: function () { + this.age = this.age + 1; } }; From c52962d971763b3b995fe8958dcd27454b0343fd Mon Sep 17 00:00:00 2001 From: azadaafo Date: Tue, 19 May 2020 23:36:33 +0100 Subject: [PATCH 15/19] completed InClass/D-methods/exercise-4.js --- week-4/InClass/D-methods/exercise-4.js | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/week-4/InClass/D-methods/exercise-4.js b/week-4/InClass/D-methods/exercise-4.js index d89214a72..d22a0c9a2 100644 --- a/week-4/InClass/D-methods/exercise-4.js +++ b/week-4/InClass/D-methods/exercise-4.js @@ -6,7 +6,10 @@ Define a method "makeFriend" to add a new friend to her list. let person = { name: "Alice", - friends: ["John", "Nina"] + friends: ["John", "Nina"], + makeFriend: function () { + return person.friends.push("Bob"); + }, }; From 43f6449c32afb9e8d8a436c69969b7131de207f1 Mon Sep 17 00:00:00 2001 From: azadaafo Date: Thu, 21 May 2020 00:41:07 +0100 Subject: [PATCH 16/19] corrected InClass/D-methods/exercise-3.js --- week-4/InClass/D-methods/exercise-3.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/week-4/InClass/D-methods/exercise-3.js b/week-4/InClass/D-methods/exercise-3.js index bbeed78b8..df8cb2974 100644 --- a/week-4/InClass/D-methods/exercise-3.js +++ b/week-4/InClass/D-methods/exercise-3.js @@ -7,9 +7,9 @@ Once you fix them, run this file, it should output the correct values! let person = { name: "Alice", age: 25, - currentAddress: "Edinburgh", + currentAddress: "Glasgow", changeAddress: function (newAddress) { - currentAddress = newAddress; + return this.currentAddress = newAddress; }, celebrateBirthday: function () { this.age = this.age + 1; From 086a40f7b5099fdc0eabb71cce1f6ddbbf07db37 Mon Sep 17 00:00:00 2001 From: azadaafo Date: Thu, 21 May 2020 00:55:18 +0100 Subject: [PATCH 17/19] corrected InClass/D-methods/exercise-4.js --- week-4/InClass/D-methods/exercise-4.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/week-4/InClass/D-methods/exercise-4.js b/week-4/InClass/D-methods/exercise-4.js index d22a0c9a2..5abe80db2 100644 --- a/week-4/InClass/D-methods/exercise-4.js +++ b/week-4/InClass/D-methods/exercise-4.js @@ -7,8 +7,8 @@ Define a method "makeFriend" to add a new friend to her list. let person = { name: "Alice", friends: ["John", "Nina"], - makeFriend: function () { - return person.friends.push("Bob"); + makeFriend: function (friend) { + return this.friends.push(friend) }, }; From cff3ce96c1129f3fe41e6f06f91c804265e1f97f Mon Sep 17 00:00:00 2001 From: azadaafo Date: Wed, 8 Jul 2020 03:34:03 +0100 Subject: [PATCH 18/19] half of in class exercises done for week 4 Objects --- week-4/InClass/A-objects-intro/README (1).md | 15 + .../A-objects-intro/exercise-part-0.js | 18 +- .../A-objects-intro/exercise-part-1.js | 57 +- .../A-objects-intro/exercise-part-2.js | 1459 ++++++++++++++- .../A-objects-intro/exercise-part-3.js | 1433 +++++++++++++- week-4/InClass/B-objects-get-set/README.md | 1358 +++++++++++++- .../InClass/B-objects-get-set/exercise-1.js | 1451 ++++++++++++++- .../InClass/B-objects-get-set/exercise-2.js | 1475 ++++++++++++++- .../InClass/B-objects-get-set/exercise-3.js | 1411 +++++++++++++- .../InClass/B-objects-get-set/exercise-4.js | 1473 ++++++++++++++- .../InClass/C-more-complex-objects/README.md | 1308 ++++++++++++- .../C-more-complex-objects/exercise-1.js | 1523 ++++++++++++++- .../C-more-complex-objects/exercise-2.js | 1570 +++++++++++++++- .../C-more-complex-objects/exercise-3.js | 1643 ++++++++++++++++- 14 files changed, 15800 insertions(+), 394 deletions(-) create mode 100644 week-4/InClass/A-objects-intro/README (1).md diff --git a/week-4/InClass/A-objects-intro/README (1).md b/week-4/InClass/A-objects-intro/README (1).md new file mode 100644 index 000000000..982792956 --- /dev/null +++ b/week-4/InClass/A-objects-intro/README (1).md @@ -0,0 +1,15 @@ +Objects +Objects in the real world have properties that describe how they are unique. Your laptop, for example, has a brand (Lenovo/Apple etc.), a screen size (13/15 inch), RAM (8/16GB) etc. + +How would we describe the above laptop as a JavaScript object? + +let laptop = { + brand: "Lenovo", + screenSize: 13, + isTouchscreen: true +}; +Useful words to remember when talking about objects: + +object literal: anything that has a set of {...} around a set of properties is an object literal +property or key: brand, screenSize and isTouchScreen are properties/keys of the object +values: "Lenovo", 13 and true are values of the object's properties \ No newline at end of file diff --git a/week-4/InClass/A-objects-intro/exercise-part-0.js b/week-4/InClass/A-objects-intro/exercise-part-0.js index 2512a3c97..f98fe8e9d 100644 --- a/week-4/InClass/A-objects-intro/exercise-part-0.js +++ b/week-4/InClass/A-objects-intro/exercise-part-0.js @@ -1,20 +1,4 @@ /* - Describe your own laptop as a JavaScript object - Try to think of as many properties as you can! - -*/ - -let myLaptop = { - brand: "Dell", - screenSize: 15, - ram: 16, - diskType: "SSD", - screenTouch: false, - batteryLife: "6 hr", - multiLanguage: true, - bulitInCamera: true, - externalSpeakers: false, - antiVirusInstalled: "Yes" -} \ No newline at end of file +*/ \ No newline at end of file diff --git a/week-4/InClass/A-objects-intro/exercise-part-1.js b/week-4/InClass/A-objects-intro/exercise-part-1.js index d8c5285df..f54405707 100644 --- a/week-4/InClass/A-objects-intro/exercise-part-1.js +++ b/week-4/InClass/A-objects-intro/exercise-part-1.js @@ -1,52 +1,5 @@ -/* - -Think of 5 different real world "things" that you -can describe with a JavaScript object - -Assign each of them to a separate variable - -*/ -let person = { - hight: 185, - weight: 80, - hairColor: "black", - smoker: false -} - -let location = { - cityName: "Manchester", - population: 600000, - highBuildings: "yes", - diverseCity: true -} - -let CYF = { - purpose: "educational", - helpfull: true, - supportLevel: "very high", - encouraging: true, - numOfMentors: 10, - numOfStudents: 25 -} - -let homework = { - hardPart: "functions and loops", - useful: "not for me until now", - harm: "I lost my confidence", - whyThat: "online style and missed some impo parts", - longValues: true, - reason: "wanted to deliver my feedback", - percentOfHelpNeeded: 100, - didYouUnderstandObjects: "except functions and loops part" -} - -let feelings = { - LikeTheCourse: true, - hoursDevotedPerDay: 5, - goodResources: "not enough", - oldStyleOrNew: "old", - interestedInTheCourse: "of course", - didIrunMyObjects: true -} - -console.log(feelings, homework, CYF); +/* +Think of 5 different real world "things" that you +can describe with a JavaScript object +Assign each of them to a separate variable +*/ \ No newline at end of file diff --git a/week-4/InClass/A-objects-intro/exercise-part-2.js b/week-4/InClass/A-objects-intro/exercise-part-2.js index 5fa65dda7..5cdd98bc8 100644 --- a/week-4/InClass/A-objects-intro/exercise-part-2.js +++ b/week-4/InClass/A-objects-intro/exercise-part-2.js @@ -1,22 +1,1437 @@ -/* - -The objects below have some syntax issues - try and fix them all! - -*/ - -let kitten = { - furColour: "orange", - age: 23 -}; - -let laptop = { - brand: "Lenovo", - ram: "5GB" -} - -let phone = { - operatingSystem: "iOS", - hasStylus: true, - megapixels: 12, - batteryLife: "24 hours" -} \ No newline at end of file + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + js-exercises/exercise-part-2.js at master · CodeYourFuture/js-exercises + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
+ Skip to content + + + + + + + + + + + + + +
+ +
+ + + + +
+ + + +
+ + + + + + + + +
+
+
+ + + + + + + + + + + + + + + + +
+ +
+ +
+

+ + + / + + js-exercises + + +

+ + +
+ +
    + +
  • +
    + +
    + + + + Watch + + + +
    + Notifications +
    +
    + + + + + + + +
    +
    +
    + +
    +
  • + +
  • +
    +
    + + +
    +
    + + +
    + +
  • + +
  • +
    +
    + + + Fork + + + +
    + +

    Fork js-exercises

    +
    + +
    + +
    +

    If this dialog fails to load, you can visit the fork page directly.

    +
    +
    + +
    +
    +
    + + +
  • +
+ +
+ + + +
+ +
+
+ + + + + + + + Permalink + + + + +
+ +
+ + + + Branch: + master + + + + +
+ + + +
+
+
+ + + + Go to file + + +
+ + + + + + + + + +
+
+ + + +
+ +
+
+
 
+
+ +
+
 
+ Cannot retrieve contributors at this time +
+
+ + + + + + +
+ +
+
+ + 21 lines (16 sloc) + + 313 Bytes +
+ +
+ +
+ Raw + Blame +
+ +
+ + + + +
+ +
+
+ +
+
+
+ + + + + +
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
/*
The objects below have some syntax issues - try and fix them all!
*/
+
let kitten = {
fur colour: "orange",
age "23"
};
+
let laptop =
brand: "Lenovo"
ram "5GB"
}
+
let phone = {
operating system "iOS",
hasStylus: true,
megapixels 12
"batteryLife": "24 hours"
+ + + +
+ +
+ + + + +
+ + +
+ + +
+
+ + + + + + +
+
+ +
+
+ + +
+ + + + + + +
+ + + You can’t perform that action at this time. +
+ + + + + + + + + + + + + + + + + + + + + + + diff --git a/week-4/InClass/A-objects-intro/exercise-part-3.js b/week-4/InClass/A-objects-intro/exercise-part-3.js index d9a7b4898..728a48bb1 100644 --- a/week-4/InClass/A-objects-intro/exercise-part-3.js +++ b/week-4/InClass/A-objects-intro/exercise-part-3.js @@ -1,19 +1,1414 @@ -/* - -Choose a few nearby colleagues and one mentor, and go through each variable you -declared above in Part 1 and 2, reading everything that happens out loud. - -Make sure each member of your group has read at least one variable! - -Make sure you use words like: -- object literal: -- property -- value -- string what we put between ("") / number: true number or float number or called integer / boolean is true or false -- declaring a variable we declare a variable using three keywords: let, const, and var. -- etc. - -*/ -- object literal: is every thing between the curle braces { } -- property: within an objectusually on the left side and we assign values to it - - value: values we assigned to a property to describe an object. + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + js-exercises/exercise-part-3.js at master · CodeYourFuture/js-exercises + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
+ Skip to content + + + + + + + + + + + + + +
+ +
+ + + + +
+ + + +
+ + + + + + + + +
+
+
+ + + + + + + + + + + + + + + + +
+ +
+ +
+

+ + + / + + js-exercises + + +

+ + +
+ +
    + +
  • +
    + +
    + + + + Watch + + + +
    + Notifications +
    +
    + + + + + + + +
    +
    +
    + +
    +
  • + +
  • +
    +
    + + +
    +
    + + +
    + +
  • + +
  • +
    +
    + + + Fork + + + +
    + +

    Fork js-exercises

    +
    + +
    + +
    +

    If this dialog fails to load, you can visit the fork page directly.

    +
    +
    + +
    +
    +
    + + +
  • +
+ +
+ + + +
+ +
+
+ + + + + + + + Permalink + + + + +
+ +
+ + + + Branch: + master + + + + +
+ + + +
+
+
+ + + + Go to file + + +
+ + + + + + + + + +
+
+ + + +
+ +
+
+
 
+
+ +
+
 
+ Cannot retrieve contributors at this time +
+
+ + + + + + +
+ +
+
+ + 16 lines (12 sloc) + + 371 Bytes +
+ +
+ +
+ Raw + Blame +
+ +
+ + + + +
+ +
+
+ +
+
+
+ + + + + +
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
/*
Choose a few nearby colleagues and one mentor, and go through each variable you
declared above in Part 1 and 2, reading everything that happens out loud.
Make sure each member of your group has read at least one variable!
Make sure you use words like:
- object literal
- property
- value
- string / number / boolean
- declaring a variable
- etc.
*/
+ + + +
+ +
+ + + + +
+ + +
+ + +
+
+ + + + + + +
+
+ +
+
+ + +
+ + + + + + +
+ + + You can’t perform that action at this time. +
+ + + + + + + + + + + + + + + + + + + + + + + diff --git a/week-4/InClass/B-objects-get-set/README.md b/week-4/InClass/B-objects-get-set/README.md index 30f5414ec..e00010627 100644 --- a/week-4/InClass/B-objects-get-set/README.md +++ b/week-4/InClass/B-objects-get-set/README.md @@ -1,52 +1,1306 @@ -### Getting the value of an object's property - -Let's take one of the objects we looked at earlier.. - -```js -let laptop = { - brand: "Lenovo", - screenSize: 13, - isTouchscreen: true -}; -``` - -> Try to `console.log(laptop)`. The output might depend on your environment! - -To find out the value of an object's property, you can use the dot notation.. - -```js -console.log(laptop.brand); -``` - -You can also use the bracket notation (although this is rarely used, it's good to know): - -```js -console.log(laptop['brand']); -``` - -### Setting the value of a property - -Similar to reading, if we want to set a property: - -```js -laptop.brand = "Apple"; -``` - -It's strongly recommended you always use the same **type** when re-assigning an object's property (if it was a string before, keep it a string - and so on). - -```js -let laptop = { - brand: "Lenovo", - screenSize: 13, - isTouchscreen: true -}; - -// DON'T DO THIS -laptop.screenSize = "15 inch"; - -// OK TO DO -laptop.screenSize = 15; -``` - - - + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + js-exercises/README.md at master · CodeYourFuture/js-exercises + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
+ Skip to content + + + + + + + + + + + + + +
+ +
+ + + + +
+ + + +
+ + + + + + + + +
+
+
+ + + + + + + + + + + + + + + + +
+ +
+ +
+

+ + + / + + js-exercises + + +

+ + +
+ +
    + +
  • +
    + +
    + + + + Watch + + + +
    + Notifications +
    +
    + + + + + + + +
    +
    +
    + +
    +
  • + +
  • +
    +
    + + +
    +
    + + +
    + +
  • + +
  • +
    +
    + + + Fork + + + +
    + +

    Fork js-exercises

    +
    + +
    + +
    +

    If this dialog fails to load, you can visit the fork page directly.

    +
    +
    + +
    +
    +
    + + +
  • +
+ +
+ + + +
+ +
+
+ + + + + + + + Permalink + + + + +
+ +
+ + + + Branch: + master + + + + +
+ + + +
+
+
+ + + + Go to file + + +
+ + + + + + + + + +
+
+ + + +
+ +
+
+
 
+
+ +
+
 
+ Cannot retrieve contributors at this time +
+
+ + + + + + +
+ +
+
+ + 52 lines (35 sloc) + + 1.01 KB +
+ +
+ +
+ Raw + Blame +
+ +
+ + + + +
+ +
+
+ +
+
+
+ + + + +
+

Getting the value of an object's property

+

Let's take one of the objects we looked at earlier..

+
let laptop = {
+    brand: "Lenovo",
+    screenSize: 13,
+    isTouchscreen: true
+};
+
+

Try to console.log(laptop). The output might depend on your environment!

+
+

To find out the value of an object's property, you can use the dot notation..

+
console.log(laptop.brand);
+

You can also use the bracket notation (although this is rarely used, it's good to know):

+
console.log(laptop['brand']);
+

Setting the value of a property

+

Similar to reading, if we want to set a property:

+
laptop.brand = "Apple";
+

It's strongly recommended you always use the same type when re-assigning an object's property (if it was a string before, keep it a string - and so on).

+
let laptop = {
+    brand: "Lenovo",
+    screenSize: 13,
+    isTouchscreen: true
+};
+
+// DON'T DO THIS
+laptop.screenSize = "15 inch";
+
+// OK TO DO
+laptop.screenSize = 15;
+
+
+ +
+ + + + +
+ + +
+ + +
+
+ + + + + + +
+
+ +
+
+ + +
+ + + + + + +
+ + + You can’t perform that action at this time. +
+ + + + + + + + + + + + + + + + + + + + + + + diff --git a/week-4/InClass/B-objects-get-set/exercise-1.js b/week-4/InClass/B-objects-get-set/exercise-1.js index 9b05d30e2..26370fe02 100644 --- a/week-4/InClass/B-objects-get-set/exercise-1.js +++ b/week-4/InClass/B-objects-get-set/exercise-1.js @@ -1,21 +1,1430 @@ -/* - Console.log the values of each property of "kitten" -*/ - -let kitten = { - ageMonths: 3, - isFemale: true, - furColour: "brown" -}; - -// YOUR CODE GOES BELOW HERE - -console.log(kitten.ageMonths); -console.log(kitten.isFemale); -console.log(kitten.furColour); - - - - - -// YOUR CODE GOES ABOVE HERE \ No newline at end of file + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + js-exercises/exercise-1.js at master · CodeYourFuture/js-exercises + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
+ Skip to content + + + + + + + + + + + + + +
+ +
+ + + + +
+ + + +
+ + + + + + + + +
+
+
+ + + + + + + + + + + + + + + + +
+ +
+ +
+

+ + + / + + js-exercises + + +

+ + +
+ +
    + +
  • +
    + +
    + + + + Watch + + + +
    + Notifications +
    +
    + + + + + + + +
    +
    +
    + +
    +
  • + +
  • +
    +
    + + +
    +
    + + +
    + +
  • + +
  • +
    +
    + + + Fork + + + +
    + +

    Fork js-exercises

    +
    + +
    + +
    +

    If this dialog fails to load, you can visit the fork page directly.

    +
    +
    + +
    +
    +
    + + +
  • +
+ +
+ + + +
+ +
+
+ + + + + + + + Permalink + + + + +
+ +
+ + + + Branch: + master + + + + +
+ + + +
+
+
+ + + + Go to file + + +
+ + + + + + + + + +
+
+ + + +
+ +
+
+
 
+
+ +
+
 
+ Cannot retrieve contributors at this time +
+
+ + + + + + +
+ +
+
+ + 18 lines (10 sloc) + + 223 Bytes +
+ +
+ +
+ Raw + Blame +
+ +
+ + + + +
+ +
+
+ +
+
+
+ + + + + +
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
/*
Console.log the values of each property of "kitten"
*/
+
let kitten = {
ageMonths: 3,
isFemale: true,
furColour: "brown"
};
+
// YOUR CODE GOES BELOW HERE
+
+
+
+
+
+
// YOUR CODE GOES ABOVE HERE
+ + + +
+ +
+ + + + +
+ + +
+ + +
+
+ + + + + + +
+
+ +
+
+ + +
+ + + + + + +
+ + + You can’t perform that action at this time. +
+ + + + + + + + + + + + + + + + + + + + + + + diff --git a/week-4/InClass/B-objects-get-set/exercise-2.js b/week-4/InClass/B-objects-get-set/exercise-2.js index fed82e3a6..4c66fbedc 100644 --- a/week-4/InClass/B-objects-get-set/exercise-2.js +++ b/week-4/InClass/B-objects-get-set/exercise-2.js @@ -1,24 +1,1451 @@ -/* - The following code contains syntax errors - try and fix them! - - Once you fix them, run this file, it should output the correct values! -*/ - -let phone = { - brand: 'iPhone', - model: 'iPhone X', - launchYear: 2017, - isUnlocked: true -}; - -let phoneBrand = phone.brand; -let phoneLaunchYear = phone["launchYear"]; - -// DO NOT MODIFY BELOW THIS LINE - -console.log(phoneBrand); -console.log(phoneLaunchYear); - -// it should output: -// iPhone -// 2017 \ No newline at end of file + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + js-exercises/exercise-2.js at master · CodeYourFuture/js-exercises + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
+ Skip to content + + + + + + + + + + + + + +
+ +
+ + + + +
+ + + +
+ + + + + + + + +
+
+
+ + + + + + + + + + + + + + + + +
+ +
+ +
+

+ + + / + + js-exercises + + +

+ + +
+ +
    + +
  • +
    + +
    + + + + Watch + + + +
    + Notifications +
    +
    + + + + + + + +
    +
    +
    + +
    +
  • + +
  • +
    +
    + + +
    +
    + + +
    + +
  • + +
  • +
    +
    + + + Fork + + + +
    + +

    Fork js-exercises

    +
    + +
    + +
    +

    If this dialog fails to load, you can visit the fork page directly.

    +
    +
    + +
    +
    +
    + + +
  • +
+ +
+ + + +
+ +
+
+ + + + + + + + Permalink + + + + +
+ +
+ + + + Branch: + master + + + + +
+ + + +
+
+
+ + + + Go to file + + +
+ + + + + + + + + +
+
+ + + +
+ +
+
+
 
+
+ +
+
 
+ Cannot retrieve contributors at this time +
+
+ + + + + + +
+ +
+
+ + 24 lines (18 sloc) + + 475 Bytes +
+ +
+ +
+ Raw + Blame +
+ +
+ + + + +
+ +
+
+ +
+
+
+ + + + + +
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
/*
The following code contains syntax errors - try and fix them!
Once you fix them, run this file, it should output the correct values!
*/
+
let phone = {
brand: 'iPhone,
model 'iPhone X'
launchYear: 2017,
is Unlocked: true
;
+
let phoneBrand = phone.bbrand;
let phoneLaunchYear = phone[launchYear];
+
// DO NOT MODIFY BELOW THIS LINE
+
console.log(phoneBrand);
console.log(phoneLaunchYear);
+
// it should output:
// iPhone
// 2017
+ + + +
+ +
+ + + + +
+ + +
+ + +
+
+ + + + + + +
+
+ +
+
+ + +
+ + + + + + +
+ + + You can’t perform that action at this time. +
+ + + + + + + + + + + + + + + + + + + + + + + diff --git a/week-4/InClass/B-objects-get-set/exercise-3.js b/week-4/InClass/B-objects-get-set/exercise-3.js index cc0441e65..e8cb1c591 100644 --- a/week-4/InClass/B-objects-get-set/exercise-3.js +++ b/week-4/InClass/B-objects-get-set/exercise-3.js @@ -1,13 +1,1398 @@ -/* - Write code in the space provided so that it outputs "Gilbert" -*/ - -// WRITE CODE BELOW THIS -let kitten = { - name: "Gilbert" -} -// WRITE CODE ABOVE THIS - -console.log(kitten.name); - -// -> it should output: "Gilbert" \ No newline at end of file + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + js-exercises/exercise-3.js at master · CodeYourFuture/js-exercises + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
+ Skip to content + + + + + + + + + + + + + +
+ +
+ + + + +
+ + + +
+ + + + + + + + +
+
+
+ + + + + + + + + + + + + + + + +
+ +
+ +
+

+ + + / + + js-exercises + + +

+ + +
+ +
    + +
  • +
    + +
    + + + + Watch + + + +
    + Notifications +
    +
    + + + + + + + +
    +
    +
    + +
    +
  • + +
  • +
    +
    + + +
    +
    + + +
    + +
  • + +
  • +
    +
    + + + Fork + + + +
    + +

    Fork js-exercises

    +
    + +
    + +
    +

    If this dialog fails to load, you can visit the fork page directly.

    +
    +
    + +
    +
    +
    + + +
  • +
+ +
+ + + +
+ +
+
+ + + + + + + + Permalink + + + + +
+ +
+ + + + Branch: + master + + + + +
+ + + +
+
+
+ + + + Go to file + + +
+ + + + + + + + + +
+
+ + + +
+ +
+
+
 
+
+ +
+
 
+ Cannot retrieve contributors at this time +
+
+ + + + + + +
+ +
+
+ + 11 lines (7 sloc) + + 195 Bytes +
+ +
+ +
+ Raw + Blame +
+ +
+ + + + +
+ +
+
+ +
+
+
+ + + + + +
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
/*
Write code in the space provided so that it outputs "Gilbert"
*/
+
// WRITE CODE BELOW THIS
+
// WRITE CODE ABOVE THIS
+
console.log(kitten.name);
+
// -> it should output: "Gilbert"
+ + + +
+ +
+ + + + +
+ + +
+ + +
+
+ + + + + + +
+
+ +
+
+ + +
+ + + + + + +
+ + + You can’t perform that action at this time. +
+ + + + + + + + + + + + + + + + + + + + + + + diff --git a/week-4/InClass/B-objects-get-set/exercise-4.js b/week-4/InClass/B-objects-get-set/exercise-4.js index 5e1a98438..36e85c241 100644 --- a/week-4/InClass/B-objects-get-set/exercise-4.js +++ b/week-4/InClass/B-objects-get-set/exercise-4.js @@ -1,23 +1,1450 @@ -/* - Write code in the space provided so that the expected values output -*/ - -let dog = { - name: 'Billy', - wantsToPlay: false -}; - -// WRITE CODE BELOW THIS LINE -dog.name = "Rex", - dog.wantsToPlay = true - -// WRITE CODE ABOVE THIS LINE - - -//DO NOT MODIFY BELOW -console.log(dog.name); -console.log(dog.wantsToPlay); - -// it should output: -// Rex -// true \ No newline at end of file + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + js-exercises/exercise-4.js at master · CodeYourFuture/js-exercises + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
+ Skip to content + + + + + + + + + + + + + +
+ +
+ + + + +
+ + + +
+ + + + + + + + +
+
+
+ + + + + + + + + + + + + + + + +
+ +
+ +
+

+ + + / + + js-exercises + + +

+ + +
+ +
    + +
  • +
    + +
    + + + + Watch + + + +
    + Notifications +
    +
    + + + + + + + +
    +
    +
    + +
    +
  • + +
  • +
    +
    + + +
    +
    + + +
    + +
  • + +
  • +
    +
    + + + Fork + + + +
    + +

    Fork js-exercises

    +
    + +
    + +
    +

    If this dialog fails to load, you can visit the fork page directly.

    +
    +
    + +
    +
    +
    + + +
  • +
+ +
+ + + +
+ +
+
+ + + + + + + + Permalink + + + + +
+ +
+ + + + Branch: + master + + + + +
+ + + +
+
+
+ + + + Go to file + + +
+ + + + + + + + + +
+
+ + + +
+ +
+
+
 
+
+ +
+
 
+ Cannot retrieve contributors at this time +
+
+ + + + + + +
+ +
+
+ + 23 lines (15 sloc) + + 335 Bytes +
+ +
+ +
+ Raw + Blame +
+ +
+ + + + +
+ +
+
+ +
+
+
+ + + + + +
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
/*
Write code in the space provided so that the expected values output
*/
+
let dog = {
name: 'Billy',
wantsToPlay: false
};
+
// WRITE CODE BELOW THIS LINE
+
+
+
// WRITE CODE ABOVE THIS LINE
+
+
//DO NOT MODIFY BELOW
console.log(dog.name);
console.log(dog.wantsToPlay);
+
// it should output:
// Rex
// true
+ + + +
+ +
+ + + + +
+ + +
+ + +
+
+ + + + + + +
+
+ +
+
+ + +
+ + + + + + +
+ + + You can’t perform that action at this time. +
+ + + + + + + + + + + + + + + + + + + + + + + diff --git a/week-4/InClass/C-more-complex-objects/README.md b/week-4/InClass/C-more-complex-objects/README.md index f33291682..38a09a287 100644 --- a/week-4/InClass/C-more-complex-objects/README.md +++ b/week-4/InClass/C-more-complex-objects/README.md @@ -1,18 +1,1290 @@ -### More objects! - - Object properties can even be assigned other objects or variables too. The example below shows an object with keys that have been assigned a variable, an array, and an object. - -```js -let kittenName = "Feathers"; - -let kitten = { - name: kittenName, - toyCollection: ['blue ball', 'green ball', 'hoover box'], - favoriteLocation: { - roomName: 'Living room', - napPlace: 'window', - idealTemperatureCelsius: 24 - } -}; -``` - + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + js-exercises/README.md at master · CodeYourFuture/js-exercises + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
+ Skip to content + + + + + + + + + + + + + +
+ +
+ + + + +
+ + + +
+ + + + + + + + +
+
+
+ + + + + + + + + + + + + + + + +
+ +
+ +
+

+ + + / + + js-exercises + + +

+ + +
+ +
    + +
  • +
    + +
    + + + + Watch + + + +
    + Notifications +
    +
    + + + + + + + +
    +
    +
    + +
    +
  • + +
  • +
    +
    + + +
    +
    + + +
    + +
  • + +
  • +
    +
    + + + Fork + + + +
    + +

    Fork js-exercises

    +
    + +
    + +
    +

    If this dialog fails to load, you can visit the fork page directly.

    +
    +
    + +
    +
    +
    + + +
  • +
+ +
+ + + +
+ +
+
+ + + + + + + + Permalink + + + + +
+ +
+ + + + Branch: + master + + + + +
+ + + +
+
+
+ + + + Go to file + + +
+ + + + + + + + + +
+
+ + + +
+ +
+
+
 
+
+ +
+
 
+ Cannot retrieve contributors at this time +
+
+ + + + + + +
+ +
+
+ + 18 lines (14 sloc) + + 485 Bytes +
+ +
+ +
+ Raw + Blame +
+ +
+ + + + +
+ +
+
+ +
+
+
+ + + + +
+

More objects!

+

Object properties can even be assigned other objects or variables too. The example below shows an object with keys that have been assigned a variable, an array, and an object.

+
let kittenName = "Feathers";
+
+let kitten = {
+    name: kittenName,
+    toyCollection: ['blue ball', 'green ball', 'hoover box'],
+    favoriteLocation: {
+        roomName: 'Living room',
+        napPlace: 'window',
+        idealTemperatureCelsius: 24
+    }
+};
+
+
+ +
+ + + + +
+ + +
+ + +
+
+ + + + + + +
+
+ +
+
+ + +
+ + + + + + +
+ + + You can’t perform that action at this time. +
+ + + + + + + + + + + + + + + + + + + + + + + diff --git a/week-4/InClass/C-more-complex-objects/exercise-1.js b/week-4/InClass/C-more-complex-objects/exercise-1.js index db9402600..d39739f1e 100644 --- a/week-4/InClass/C-more-complex-objects/exercise-1.js +++ b/week-4/InClass/C-more-complex-objects/exercise-1.js @@ -1,35 +1,1488 @@ -/* - Given the following house - follow the instructions below. - - Make sure you run the file after and it outputs the correct results. -*/ - -let house = { - address: "1 Kinning Park", - previousOwners: ["Claire M.", "John A."], - currentOwner: { - firstName: "Margaret", - lastName: "Conway" - } -}; - -/* - DO NOT EDIT ANYTHING ABOVE THIS LINE - - WRITE YOUR CODE BELOW -*/ - -// - change the address of "house" to '51 Berkley Road' -house.address = "51 Berkley Road" -// - change the previous owners of "house" to ["Brian M.", "Fiona S."] -house.previousOwners = ["Brian M.", "Fiona S."], - // - change the last name of the current owner of "house" to "Montgomery" - house.currentOwner.lastName = "Montgomery", - - /* - DO NOT EDIT ANYTHING BELOW THIS LINE - */ - - console.log("Expected result: 51 Berkley Road. Actual result: " + house.address); -console.log("Expected result: Brian M., Fiona S. Actual result: " + house.previousOwners.toString()); -console.log("Expected result: Montgomery. Actual result: " + house.currentOwner.lastName); \ No newline at end of file + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + js-exercises/exercise-1.js at master · CodeYourFuture/js-exercises + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
+ Skip to content + + + + + + + + + + + + + +
+ +
+ + + + +
+ + + +
+ + + + + + + + +
+
+
+ + + + + + + + + + + + + + + + +
+ +
+ +
+

+ + + / + + js-exercises + + +

+ + +
+ +
    + +
  • +
    + +
    + + + + Watch + + + +
    + Notifications +
    +
    + + + + + + + +
    +
    +
    + +
    +
  • + +
  • +
    +
    + + +
    +
    + + +
    + +
  • + +
  • +
    +
    + + + Fork + + + +
    + +

    Fork js-exercises

    +
    + +
    + +
    +

    If this dialog fails to load, you can visit the fork page directly.

    +
    +
    + +
    +
    +
    + + +
  • +
+ +
+ + + +
+ +
+
+ + + + + + + + Permalink + + + + +
+ +
+ + + + Branch: + master + + + + +
+ + + +
+
+
+ + + + Go to file + + +
+ + + + + + + + + +
+
+ + + +
+ +
+
+
 
+
+ +
+
 
+ Cannot retrieve contributors at this time +
+
+ + + + + + +
+ +
+
+ + 33 lines (25 sloc) + + 941 Bytes +
+ +
+ +
+ Raw + Blame +
+ +
+ + + + +
+ +
+
+ +
+
+
+ + + + + +
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
/*
Given the following house - follow the instructions below.
Make sure you run the file after and it outputs the correct results.
*/
+
let house = {
address: "1 Kinning Park",
previousOwners: ["Claire M.", "John A."],
currentOwner: {
firstName: "Margaret",
lastName: "Conway"
}
};
+
/*
DO NOT EDIT ANYTHING ABOVE THIS LINE
WRITE YOUR CODE BELOW
*/
+
// - change the address of "house" to '51 Berkley Road'
// - change the previous owners of "house" to ["Brian M.", "Fiona S."]
// - change the last name of the current owner of "house" to "Montgomery"
+
+
/*
DO NOT EDIT ANYTHING BELOW THIS LINE
*/
+
console.log("Expected result: 51 Berkley Road. Actual result: " + house.address);
console.log("Expected result: Brian M., Fiona S. Actual result: " + house.previousOwners.toString());
console.log("Expected result: Montgomery. Actual result: " + house.currentOwner.lastName);
+ + + +
+ +
+ + + + +
+ + +
+ + +
+
+ + + + + + +
+
+ +
+
+ + +
+ + + + + + +
+ + + You can’t perform that action at this time. +
+ + + + + + + + + + + + + + + + + + + + + + + diff --git a/week-4/InClass/C-more-complex-objects/exercise-2.js b/week-4/InClass/C-more-complex-objects/exercise-2.js index 5f18b2c79..0d43f0774 100644 --- a/week-4/InClass/C-more-complex-objects/exercise-2.js +++ b/week-4/InClass/C-more-complex-objects/exercise-2.js @@ -1,44 +1,1526 @@ -/* - Given the same "house" object again - - Follow the instructions below and then run the file - and make sure it outputs the correct results -*/ - -let house = { - address: "1 Kinning Park", - previousOwners: ["Claire M.", "John A."], - currentOwner: { - firstName: "Margaret", - lastName: "Conway" - } -}; - -let newCurrentOwner = { - firstName: "Georgina", - lastName: "Hernandez" -}; - -/* - DO NOT EDIT ANYTHING ABOVE THIS LINE - - WRITE YOUR CODE BELOW -*/ - -// - assign the value of the variable 'newCurrentOwner' as the value to the house's "currentOwner" -house.currentOwner = newCurrentOwner, - // - from the list of previous owners, replace only "John A." with "Stephen B." - house.previousOwners[1] = "Stephen B.", - // - give the house a new property called 'isForSale' with the value 'false' - house.isForSale = false - - - -/* - DO NOT EDIT ANYTHING BELOW THIS LINE -*/ -console.log( - "Did you correctly assign the new owner using the given variable?", - `Expected result: true. Actual result: ${(house.currentOwner === newCurrentOwner)}`); -console.log(`Expected result: Claire M., Stephen B.Actual result: ${house.previousOwners.toString()}`); -console.log(`Expected result: false.Actual result: ${house.isForSale}`); \ No newline at end of file + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + js-exercises/exercise-2.js at master · CodeYourFuture/js-exercises + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
+ Skip to content + + + + + + + + + + + + + +
+ +
+ + + + +
+ + + +
+ + + + + + + + +
+
+
+ + + + + + + + + + + + + + + + +
+ +
+ +
+

+ + + / + + js-exercises + + +

+ + +
+ +
    + +
  • +
    + +
    + + + + Watch + + + +
    + Notifications +
    +
    + + + + + + + +
    +
    +
    + +
    +
  • + +
  • +
    +
    + + +
    +
    + + +
    + +
  • + +
  • +
    +
    + + + Fork + + + +
    + +

    Fork js-exercises

    +
    + +
    + +
    +

    If this dialog fails to load, you can visit the fork page directly.

    +
    +
    + +
    +
    +
    + + +
  • +
+ +
+ + + +
+ +
+
+ + + + + + + + Permalink + + + + +
+ +
+ + + + Branch: + master + + + + +
+ + + +
+
+
+ + + + Go to file + + +
+ + + + + + + + + +
+
+ + + +
+ +
+
+
 
+
+ +
+
 
+ Cannot retrieve contributors at this time +
+
+ + + + + + +
+ +
+
+ + 42 lines (32 sloc) + + 1.15 KB +
+ +
+ +
+ Raw + Blame +
+ +
+ + + + +
+ +
+
+ +
+
+
+ + + + + +
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
/*
Given the same "house" object again
Follow the instructions below and then run the file
and make sure it outputs the correct results
*/
+
let house = {
address: "1 Kinning Park",
previousOwners: ["Claire M.", "John A."],
currentOwner: {
firstName: "Margaret",
lastName: "Conway"
}
};
+
let newCurrentOwner = {
firstName: "Georgina",
lastName: "Hernandez"
};
+
/*
DO NOT EDIT ANYTHING ABOVE THIS LINE
WRITE YOUR CODE BELOW
*/
+
// - assign the value of the variable 'newCurrentOwner' as the value to the house's "currentOwner"
// - from the list of previous owners, replace only "John A." with "Stephen B."
// - give the house a new property called 'isForSale' with the value 'false'
+
+
+
+
/*
DO NOT EDIT ANYTHING BELOW THIS LINE
*/
console.log(
"Did you correctly assign the new owner using the given variable?",
`Expected result: true. Actual result: ${(house.currentOwner === newCurrentOwner)}`);
console.log(`Expected result: Claire M., Stephen B.Actual result: ${house.previousOwners.toString()}`);
console.log(`Expected result: false.Actual result: ${house.isForSale}`);
+ + + +
+ +
+ + + + +
+ + +
+ + +
+
+ + + + + + +
+
+ +
+
+ + +
+ + + + + + +
+ + + You can’t perform that action at this time. +
+ + + + + + + + + + + + + + + + + + + + + + + diff --git a/week-4/InClass/C-more-complex-objects/exercise-3.js b/week-4/InClass/C-more-complex-objects/exercise-3.js index efb2e77ec..b37eb37d2 100644 --- a/week-4/InClass/C-more-complex-objects/exercise-3.js +++ b/week-4/InClass/C-more-complex-objects/exercise-3.js @@ -1,54 +1,1589 @@ -/* - Given the same "house" object again - - Write the code for the functions as per the description above them -*/ - -let kinningParkHouse = { - address: "1 Kinning Park", - price: 180000, - currentOwner: { - firstName: "Margaret", - lastName: "Conway", - email: "margaret@fake-emails.com" - } -}; - -let parkAvenueHouse = { - address: "50 Park Avenue", - price: 195000, - currentOwner: { - firstName: "Marie", - lastName: "McDonald", - email: "marie.m@real-emails.com" - } -}; - -/* - DO NOT EDIT ANYTHING ABOVE THIS LINE - - WRITE YOUR CODE BELOW -*/ - -// returns the full name (first name + last name) of the owner of the house -function getOwnerFullName(house) { - return `${kinningParkHouse.currentOwner.firstName} ${kinningParkHouse.currentOwner.lastName}` -} - -// returns an array of the owners' email addresses of the two houses -function getEmailAddresses(house1, house2) { - return [house1.currentOwner.email, house2.currentOwner.email] -} - -// returns the address for the cheapest house out of the two -function getCheapestAddress(house1, house2) { - return house1.price < house2.price ? house1.address : house2.address -} - - -/* - DO NOT EDIT ANYTHING BELOW THIS LINE -*/ -console.log(`Expected result: Margaret Conway. Actual result: ${getOwnerFullName(kinningParkHouse)}`); -console.log(`Expected result: margaret@fake-emails.com, marie.m@real-emails.com. Actual result: ${getEmailAddresses(kinningParkHouse, parkAvenueHouse)}`); -console.log(`Expected result: 1 Kinning Park. Actual result: ${getCheapestAddress(parkAvenueHouse, kinningParkHouse)}`); \ No newline at end of file + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + js-exercises/exercise-3.js at master · CodeYourFuture/js-exercises + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
+ Skip to content + + + + + + + + + + + + + +
+ +
+ + + + +
+ + + +
+ + + + + + + + +
+
+
+ + + + + + + + + + + + + + + + +
+ +
+ +
+

+ + + / + + js-exercises + + +

+ + +
+ +
    + +
  • +
    + +
    + + + + Watch + + + +
    + Notifications +
    +
    + + + + + + + +
    +
    +
    + +
    +
  • + +
  • +
    +
    + + +
    +
    + + +
    + +
  • + +
  • +
    +
    + + + Fork + + + +
    + +

    Fork js-exercises

    +
    + +
    + +
    +

    If this dialog fails to load, you can visit the fork page directly.

    +
    +
    + +
    +
    +
    + + +
  • +
+ +
+ + + +
+ +
+
+ + + + + + + + Permalink + + + + +
+ +
+ + + + Branch: + master + + + + +
+ + + +
+
+
+ + + + Go to file + + +
+ + + + + + + + + +
+
+ + + +
+ +
+
+
 
+
+ +
+
 
+ Cannot retrieve contributors at this time +
+
+ + + + + + +
+ +
+
+ + 54 lines (41 sloc) + + 1.38 KB +
+ +
+ +
+ Raw + Blame +
+ +
+ + + + +
+ +
+
+ +
+
+
+ + + + + +
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
/*
Given the same "house" object again
Write the code for the functions as per the description above them
*/
+
let kinningParkHouse = {
address: "1 Kinning Park",
price: 180000,
currentOwner: {
firstName: "Margaret",
lastName: "Conway",
email: "margaret@fake-emails.com"
}
};
+
let parkAvenueHouse = {
address: "50 Park Avenue",
price: 195000,
currentOwner: {
firstName: "Marie",
lastName: "McDonald",
email: "marie.m@real-emails.com"
}
};
+
/*
DO NOT EDIT ANYTHING ABOVE THIS LINE
WRITE YOUR CODE BELOW
*/
+
// returns the full name (first name + last name) of the owner of the house
function getOwnerFullName(house) {
+
}
+
// returns an array of the owners' email addresses of the two houses
function getEmailAddresses(house1, house2) {
+
}
+
// returns the address for the cheapest house out of the two
function getCheapestAddress(house1, house2) {
+
}
+
+
/*
DO NOT EDIT ANYTHING BELOW THIS LINE
*/
console.log(`Expected result: Margaret Conway. Actual result: ${getOwnerFullName(kinningParkHouse)}`);
console.log(`Expected result: margaret@fake-emails.com, marie.m@real-emails.com. Actual result: ${getEmailAddresses(kinningParkHouse, parkAvenueHouse)}`);
console.log(`Expected result: 1 Kinning Park. Actual result: ${getCheapestAddress(parkAvenueHouse, kinningParkHouse)}`);
+ + + +
+ +
+ + + + +
+ + +
+ + +
+
+ + + + + + +
+
+ +
+
+ + +
+ + + + + + +
+ + + You can’t perform that action at this time. +
+ + + + + + + + + + + + + + + + + + + + + + + From c1c852d02f7508082b9bb71a6f540b82a2e60774 Mon Sep 17 00:00:00 2001 From: azadaafo Date: Thu, 9 Jul 2020 23:51:38 +0100 Subject: [PATCH 19/19] object method exercises done --- week-4/InClass/D-methods/exercise-1.js | 6 +++--- week-4/InClass/D-methods/exercise-2.js | 6 +++--- week-4/InClass/D-methods/exercise-3.js | 4 ++-- week-4/InClass/D-methods/exercise-4.js | 6 +++--- week-4/InClass/D-methods/exercise-5.js | 11 +++++++++-- 5 files changed, 20 insertions(+), 13 deletions(-) diff --git a/week-4/InClass/D-methods/exercise-1.js b/week-4/InClass/D-methods/exercise-1.js index 183cb1f51..3f8039b73 100644 --- a/week-4/InClass/D-methods/exercise-1.js +++ b/week-4/InClass/D-methods/exercise-1.js @@ -8,10 +8,10 @@ let person = { name: "Alice", age: 25, greet: function () { - return "hello everybody"; - }, + return 'hello everybody'; + } }; -person.greet(); + /* DO NOT EDIT ANYTHING BELOW THIS LINE diff --git a/week-4/InClass/D-methods/exercise-2.js b/week-4/InClass/D-methods/exercise-2.js index f0359aa96..0b03c1a10 100644 --- a/week-4/InClass/D-methods/exercise-2.js +++ b/week-4/InClass/D-methods/exercise-2.js @@ -9,10 +9,10 @@ let person = { name: "Alice", age: 25, sayName: function () { - return "My name is " + this.name; - }, + return 'My name is ' + this.name; + } }; -person.sayName(); + /* DO NOT EDIT ANYTHING BELOW THIS LINE diff --git a/week-4/InClass/D-methods/exercise-3.js b/week-4/InClass/D-methods/exercise-3.js index df8cb2974..be1a721a4 100644 --- a/week-4/InClass/D-methods/exercise-3.js +++ b/week-4/InClass/D-methods/exercise-3.js @@ -9,10 +9,10 @@ let person = { age: 25, currentAddress: "Glasgow", changeAddress: function (newAddress) { - return this.currentAddress = newAddress; + this.currentAddress = 'Edinburgh'; }, celebrateBirthday: function () { - this.age = this.age + 1; + return this.age = this.age + 1; } }; diff --git a/week-4/InClass/D-methods/exercise-4.js b/week-4/InClass/D-methods/exercise-4.js index 5abe80db2..74d14f96e 100644 --- a/week-4/InClass/D-methods/exercise-4.js +++ b/week-4/InClass/D-methods/exercise-4.js @@ -7,9 +7,9 @@ Define a method "makeFriend" to add a new friend to her list. let person = { name: "Alice", friends: ["John", "Nina"], - makeFriend: function (friend) { - return this.friends.push(friend) - }, + makeFriend: function (newFriend) { + return this.friends.push(newFriend); + } }; diff --git a/week-4/InClass/D-methods/exercise-5.js b/week-4/InClass/D-methods/exercise-5.js index dcd198c47..1f5d282fc 100644 --- a/week-4/InClass/D-methods/exercise-5.js +++ b/week-4/InClass/D-methods/exercise-5.js @@ -17,19 +17,26 @@ let coffeeMachine = { }, insertedAmount: 0, insertMoney: function (amount) { - + this.insertedAmount = amount; }, getCoffee: function (coffee) { - + if (this.insertedAmount >= this.prices[coffee]) { // why coffee is in square brackets? + return `Please take your ${coffee}` + } else { + return `Sorry you don't have enough money for a ${coffee}` + } } }; + + /* DO NOT EDIT ANYTHING BELOW THIS LINE */ coffeeMachine.insertMoney(2.40); + console.log(`Expected result: 'Please take your cappuccino'. Actual result: ${coffeeMachine.getCoffee('cappuccino')}`); coffeeMachine.insertMoney(1.50);