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 58d6d28e7..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,7 +1,4 @@ /* - Describe your own laptop as a JavaScript object - Try to think of as many properties as you can! - */ \ 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 44cdf0ee0..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,9 +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 - -*/ - +/* +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 356828587..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,21 +1,1437 @@ -/* - -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" \ 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 491c6a064..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,16 +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 / number / boolean -- declaring a variable -- etc. - -*/ \ No newline at end of file + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + 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 4fd71e60b..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,18 +1,1430 @@ -/* - 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 \ 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 efdb092b1..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, - 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 \ 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 1f057083b..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,11 +1,1398 @@ -/* - 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" \ 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 4947cb50f..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 - - - -// 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 ae8fea487..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,33 +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' -// - 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); \ 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 69b3768aa..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,42 +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" -// - 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}`); \ 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 f461e7d64..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) { - -} - -// 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)}`); \ 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. +
+ + + + + + + + + + + + + + + + + + + + + + + diff --git a/week-4/InClass/D-methods/exercise-1.js b/week-4/InClass/D-methods/exercise-1.js index 8de0f8c30..3f8039b73 100644 --- a/week-4/InClass/D-methods/exercise-1.js +++ b/week-4/InClass/D-methods/exercise-1.js @@ -6,7 +6,10 @@ Add a method "greet" so this person can say hello. let person = { name: "Alice", - age: 25 + age: 25, + greet: function () { + return 'hello everybody'; + } }; diff --git a/week-4/InClass/D-methods/exercise-2.js b/week-4/InClass/D-methods/exercise-2.js index 8e993fc69..0b03c1a10 100644 --- a/week-4/InClass/D-methods/exercise-2.js +++ b/week-4/InClass/D-methods/exercise-2.js @@ -7,7 +7,10 @@ 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; + } }; diff --git a/week-4/InClass/D-methods/exercise-3.js b/week-4/InClass/D-methods/exercise-3.js index be237483b..be1a721a4 100644 --- a/week-4/InClass/D-methods/exercise-3.js +++ b/week-4/InClass/D-methods/exercise-3.js @@ -8,11 +8,11 @@ let person = { name: "Alice", age: 25, currentAddress: "Glasgow", - changeAddress: (newAddress) { - currentAddress = newAddress; + changeAddress: function (newAddress) { + this.currentAddress = 'Edinburgh'; }, - celebrateBirthday: function { - that.age = that.age + 1; + celebrateBirthday: function () { + 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 d89214a72..74d14f96e 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 (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);