Skip to content
This repository was archived by the owner on Oct 26, 2020. It is now read-only.

Azad week 4 inClass exercies (A, B, C) #1021

Open
wants to merge 19 commits into
base: manchester3
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
19 commits
Select commit Hold shift + click to select a range
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 15 additions & 0 deletions week-4/InClass/A-objects-intro/README (1).md
Original file line number Diff line number Diff line change
@@ -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
3 changes: 0 additions & 3 deletions week-4/InClass/A-objects-intro/exercise-part-0.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,4 @@
/*

Describe your own laptop as a JavaScript object

Try to think of as many properties as you can!

*/
14 changes: 5 additions & 9 deletions week-4/InClass/A-objects-intro/exercise-part-1.js
Original file line number Diff line number Diff line change
@@ -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
*/
1,458 changes: 1,437 additions & 21 deletions week-4/InClass/A-objects-intro/exercise-part-2.js

Large diffs are not rendered by default.

1,430 changes: 1,414 additions & 16 deletions week-4/InClass/A-objects-intro/exercise-part-3.js

Large diffs are not rendered by default.

1,358 changes: 1,306 additions & 52 deletions week-4/InClass/B-objects-get-set/README.md

Large diffs are not rendered by default.

1,448 changes: 1,430 additions & 18 deletions week-4/InClass/B-objects-get-set/exercise-1.js

Large diffs are not rendered by default.

1,475 changes: 1,451 additions & 24 deletions week-4/InClass/B-objects-get-set/exercise-2.js

Large diffs are not rendered by default.

1,409 changes: 1,398 additions & 11 deletions week-4/InClass/B-objects-get-set/exercise-3.js

Large diffs are not rendered by default.

1,473 changes: 1,450 additions & 23 deletions week-4/InClass/B-objects-get-set/exercise-4.js

Large diffs are not rendered by default.

1,308 changes: 1,290 additions & 18 deletions week-4/InClass/C-more-complex-objects/README.md

Large diffs are not rendered by default.

1,521 changes: 1,488 additions & 33 deletions week-4/InClass/C-more-complex-objects/exercise-1.js

Large diffs are not rendered by default.

1,568 changes: 1,526 additions & 42 deletions week-4/InClass/C-more-complex-objects/exercise-2.js

Large diffs are not rendered by default.

1,643 changes: 1,589 additions & 54 deletions week-4/InClass/C-more-complex-objects/exercise-3.js

Large diffs are not rendered by default.

5 changes: 4 additions & 1 deletion week-4/InClass/D-methods/exercise-1.js
Original file line number Diff line number Diff line change
Expand Up @@ -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';
}
};


Expand Down
5 changes: 4 additions & 1 deletion week-4/InClass/D-methods/exercise-2.js
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
};


Expand Down
8 changes: 4 additions & 4 deletions week-4/InClass/D-methods/exercise-3.js
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
};

Expand Down
5 changes: 4 additions & 1 deletion week-4/InClass/D-methods/exercise-4.js
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
};


Expand Down
11 changes: 9 additions & 2 deletions week-4/InClass/D-methods/exercise-5.js
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down