Skip to content
This repository was archived by the owner on Jan 3, 2023. It is now read-only.

Week 3 #79

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
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
6 changes: 5 additions & 1 deletion Week-1/Homework/mandatory/1-writers.js
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,11 @@ let writers = [
alive: true
}
];

for(let key in writers){
if(writers[key].alive === true ){
console.log(`Hi, my name is ${writers[key].firstName} ${writers[key].lastName}. I am ${writers[key].age} years old, and work as a ${writers[key].occupation}`);
}
}
/*
If you want an extra challenge, only `console.log()` the writers that are alive.
*/
13 changes: 11 additions & 2 deletions Week-1/Homework/mandatory/2-water-bottle.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,14 +11,23 @@ We made a start on this for you here:
let bottle = {
volume: 0,
fill: function() {
// calling this function should make you bottles volume = 100;
calling this function should make you bottles volume = 100;
this.volume = 100;
return this.volume;

},
drink: function() {
// calling this function should decrease your bottles volume by 10;
calling this function should decrease your bottles volume by 10;
this.volume -= 10;
return this.volume;
},
empty: function() {
// this function should return true if your bottles volume = 0
if(this.volume === 0){
return true;
}
}

};

/*
Expand Down
10 changes: 7 additions & 3 deletions Week-1/Homework/mandatory/3-groceries.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,11 @@
let groceriesToBuy = [];

let groceryList = {
item1: "",
item2: "",
item3: ""
item1: "Potatoes",
item2: "Orange Juice",
item3: "Rice"
};
for(let key in groceryList){
groceriesToBuy.push(groceryList[key]);
}
console.log(groceriesToBuy);
13 changes: 12 additions & 1 deletion Week-1/Homework/projects/1-recipes.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,4 +22,15 @@ cocoa

**/

let recipes = {};
let recipes = {
title: 'Mole',
servings: 2,
ingredients: ['cinnamon', 'cumin', 'cocoa'],
};
console.log(recipes.title);
console.log(`Serves: ${recipes.servings}`);
console.log(`Ingredients:`);
console.log(recipes.ingredients[0]);
console.log(recipes.ingredients[1]);
console.log(recipes.ingredients[2]);

53 changes: 52 additions & 1 deletion Week-1/Homework/projects/2-reading-list.js
Original file line number Diff line number Diff line change
Expand Up @@ -25,4 +25,55 @@ If you read it, log a string like 'You already read "The Hobbit" by J.R.R. Tolki

**/

let books = [];
let books = [
{
title: 'To Kill a Mockingbird',
author: 'Harper Lee',
alreadyRead: true,
},
{
title: 'The Great Gatsby',
author: 'F. Scott Fitzgerald',
alreadyRead: false,
},
{
title: 'One Hundred Years of Solitude',
author: 'Gabriel García Márquez',
alreadyRead: true,
},
{
title: 'The Lord of the Rings',
author: 'J.R.R',
alreadyRead: true,
},
{
title: 'Invisible Man',
author: 'Ralph Ellison',
alreadyRead: false,
},
{
title: 'Don Quixote',
author: 'Miguel de Cervantes',
alreadyRead: false,
},
{
title: 'Beloved',
author: 'Toni Morrison',
alreadyRead: true,
},
{
title: 'The Hobbit',
author: 'J.R.R',
alreadyRead: false,
},
];
// for(let value in books){
// console.log(`${books[value].title} by ${books[value].author}.`);
// }
for(let key in books){
if(books[key].alreadyRead === true){
console.log(`You already read ${books[key].title} by ${books[key].author}.`)
}else{
console.log(`You still need to read ${books[key].title} by ${books[key].author}.`)
}
}
19 changes: 18 additions & 1 deletion Week-1/InClass/A-objects-intro/exercise-part-0.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,21 @@ Describe your own laptop as a JavaScript object

Try to think of as many properties as you can!

*/
*/
let laptop = {
brand: 'Lenovo',
screenSize: 14,
memory: '4-GB',
processor: 'Intel Core i5',
disk: 320,
operatingSystem: 'Linux-Ubuntu',
touchScreen: false,
};
console.log(laptop);
console.log(laptop.brand);
console.log(laptop.screenSize);
console.log(laptop.memory);
console.log(laptop.processor);
console.log(laptop.disk);
console.log(laptop.operatingSystem);
console.log(laptop.touchScreen);
17 changes: 17 additions & 0 deletions Week-1/InClass/A-objects-intro/exercise-part-1.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,4 +6,21 @@ can describe with a JavaScript object
Assign each of them to a separate variable

*/
let car = {
make: 'Volkswagon',
model: 'Golf',
year: 2006,
engineSize: '1.9 cc',
color: 'Green',
fuelType: 'Diesel',
automaticGearbox: false,
};
console.log(car);
console.log(car.make);
console.log(car.model);
console.log(car.year);
console.log(car.engineSize);
console.log(car.color);
console.log(car.fuelType);
console.log(car.automaticGearbox);

19 changes: 10 additions & 9 deletions Week-1/InClass/A-objects-intro/exercise-part-2.js
Original file line number Diff line number Diff line change
Expand Up @@ -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",
'operating system': "iOS",
hasStylus: true,
megapixels 12
"batteryLife": "24 hours"
megapixels: 12,
batteryLife: "24 hours",
};
4 changes: 3 additions & 1 deletion Week-1/InClass/B-objects-get-set/exercise-1.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,9 @@ let kitten = {

// YOUR CODE GOES BELOW HERE


console.log(kitten.ageMonths);
console.log(kitten.isFemale);
console.log(kitten.furColour);



Expand Down
12 changes: 6 additions & 6 deletions Week-1/InClass/B-objects-get-set/exercise-2.js
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
4 changes: 3 additions & 1 deletion Week-1/InClass/B-objects-get-set/exercise-3.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,9 @@
*/

// WRITE CODE BELOW THIS

let kitten = {
name: 'Gilbert'
};
// WRITE CODE ABOVE THIS

console.log(kitten.name);
Expand Down
4 changes: 2 additions & 2 deletions Week-1/InClass/B-objects-get-set/exercise-4.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,9 @@ let dog = {
};

// WRITE CODE BELOW THIS LINE
dog.name = 'Rex';



dog.wantsToPlay = true;
// WRITE CODE ABOVE THIS LINE


Expand Down
4 changes: 3 additions & 1 deletion Week-1/InClass/C-more-complex-objects/exercise-1.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,9 +20,11 @@ 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."]
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
Expand Down
3 changes: 3 additions & 0 deletions Week-1/InClass/C-more-complex-objects/exercise-2.js
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,11 @@ let newCurrentOwner = {
*/

// - 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;



Expand Down
10 changes: 7 additions & 3 deletions Week-1/InClass/C-more-complex-objects/exercise-3.js
Original file line number Diff line number Diff line change
Expand Up @@ -32,17 +32,21 @@ let parkAvenueHouse = {

// returns the full name (first name + last name) of the owner of the house
function getOwnerFullName(house) {

return `${house.currentOwner.firstName} ${house.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) {

if(house1.price < house2.price){
return house1.address;
}else{
return house2.address;
}
}


Expand Down
15 changes: 8 additions & 7 deletions Week-1/InClass/D-methods/exercise-1.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,16 +3,17 @@ A person named Alice is defined below.
Add a method "greet" so this person can say hello.
*/


let person = {
name: "Alice",
age: 25
name: "Alice",
age: 25,
};
person.greet = function greeting(){
return 'Hello everybody';
};


/*
DO NOT EDIT ANYTHING BELOW THIS LINE
*/


console.log(`Expected result: Hello everybody. Actual result: ${person.greet()}`);
console.log(
`Expected result: Hello everybody. Actual result: ${person.greet()}`
);
4 changes: 3 additions & 1 deletion Week-1/InClass/D-methods/exercise-2.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,9 @@ let person = {
name: "Alice",
age: 25
};

person.sayName = function sayingOwnName(){
return `My name is ${this.name}`;
};

/*
DO NOT EDIT ANYTHING BELOW THIS LINE
Expand Down
9 changes: 5 additions & 4 deletions Week-1/InClass/D-methods/exercise-3.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,12 @@ let person = {
name: "Alice",
age: 25,
currentAddress: "Glasgow",
changeAddress: (newAddress) {
currentAddress = newAddress;
changeAddress: function (newAddress) {
return this.currentAddress = newAddress;

},
celebrateBirthday: function {
that.age = that.age + 1;
celebrateBirthday: function(age) {
return this.age = this.age + 1;
}
};

Expand Down
6 changes: 4 additions & 2 deletions Week-1/InClass/D-methods/exercise-4.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,12 +8,14 @@ let person = {
name: "Alice",
friends: ["John", "Nina"]
};

person.makeFriend = function(newFriends){
return this.friends.push(newFriends);
};

/*
DO NOT EDIT ANYTHING BELOW THIS LINE
*/

person.makeFriend("Bob");

person.makeFriend("Alice");
console.log(`Expected result: 'John,Nina,Bob'. Actual result: ${person.friends}`);
5 changes: 3 additions & 2 deletions Week-1/InClass/D-methods/exercise-5.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,10 +17,11 @@ let coffeeMachine = {
},
insertedAmount: 0,
insertMoney: function (amount) {

amount = this.insertedAmount;
return amount;
},
getCoffee: function (coffee) {

}
};

Expand Down
Loading