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

Hedyeh week 9 #1031

Open
wants to merge 8 commits into
base: manchester3
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
40 changes: 31 additions & 9 deletions week-4/Homework/mandatory/2-writers.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,29 +22,29 @@ let writers = [
lastName: "Woolf",
occupation: "writer",
age: 59,
alive: false
alive: false,
},
{
firstName: "Zadie",
lastName: "Smith",
occupation: "writer",
age: 41,
alive: true
alive: true,
},
{
firstName: "Jane",
lastName: "Austen",
occupation: "writer",
age: 41,
alive: false
alive: false,
},
{
firstName: "Bell",
lastName: "Hooks",
occupation: "writer",
age: 64,
alive: true
}
alive: true,
},
];

/*
Expand All @@ -53,20 +53,42 @@ Exercise 1:
insert corresponding values to the place holder that are indicated in curly braces:
"Hi, my name is {firstName} {lastName}. I am {age} years old, and work as a {occupation}."
*/


for (let key in writers)
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}.`
);

/*
Exercise 2:
Only `console.log()` out the writers who are in their 40s (meaning between 40 and 49)
and not alive anymore. Use the below sentence format:
"Writer {firstName} {lastName} died at {age} years old."
*/


for (let i = 0; i < writers.length; i++) {
if (
writers[i].age >= 40 &&
writers[i].age < 49 &&
writers[i].alive === false
) {
console.log(
`Writer ${writers[i].firstName} ${writers[i].lastName} died at ${writers[i].age} years old.`
);
}
}

/*
Exercise 3:
Only `console.log()` out alive writers who are in their 40s (meaning between 40 and 49):
"Hi, my name is {firstName} {lastName}. I am {age} years old."
*/
for (let i = 0; i < writers.length; i++) {
if (
writers[i].age >= 40 &&
writers[i].age < 49 &&
writers[i].alive === true
) {
console.log(
`Hi,my name is ${writers[i].firstName} ${writers[i].lastName}. I am ${writers[i].age} years old.`
);
}
}
101 changes: 77 additions & 24 deletions week-4/Homework/mandatory/3-water-bottle.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,21 +20,37 @@ You have to implement the missing features according to the specification.
// Here is your starting point:
let bottle = {
volume: 0,
fillUp: function() {
fillUp: function () {
this.volume = 100;
// calling this function should pour your bottle full (volume = 100);
},
pour: function () {
if (this.volume < 100) {
return (this.volume += 10);
}
// calling this function should increase your bottle volume by 10 unit;
},
drink: function() {
drink: function () {
if (this.volume >= 10) {
return (this.volume -= 10);
}
// calling this function should decrease your bottle volume by 10 unit;
},
isFull: function () {
if (this.volume == 100) return true;
else {
return false;
}
// this function should return true if your bottle is full;
},
isEmpty: function () {
if (this.volume == 0) {
return true;
} else {
return false;
}
// this function should return true if your bottle is empty;
},
isEmpty: function() {
// this function should return true if your bottle is full;
}
};

/*
Expand All @@ -49,7 +65,7 @@ Extra question:

Leave your answer below:
*/

// Because if we use `this` keyword and in the future the name of variable changes, it doesn't need to change the name in every single object.
// HERE COMES YOUR ANSWER

/*
Expand All @@ -67,14 +83,23 @@ if (bottle.isFull()) console.log(`That's correct! Bottle is full.`);
else console.warn(`Not quite right! Bottle should be full but it is not.`);

if (!bottle.isEmpty()) console.log(`That's correct! Bottle isn't empty.`);
else console.warn(`Not quite right! Bottle should not be empty but it is already.`);
else
console.warn(
`Not quite right! Bottle should not be empty but it is already.`
);

// ACTIONS
bottle.pour();

// CHECKS
if (bottle.volume === 100) console.log(`That's correct. Bottle is already full water volume cannot go beyond.`);
else console.warn(`Whoops!!! Looks like you've changed your bottle to a bigger one, it went beyond its maximum capacity up to ${bottle.volume} unit.`);
if (bottle.volume === 100)
console.log(
`That's correct. Bottle is already full water volume cannot go beyond.`
);
else
console.warn(
`Whoops!!! Looks like you've changed your bottle to a bigger one, it went beyond its maximum capacity up to ${bottle.volume} unit.`
);

if (bottle.isFull()) console.log(`That's correct! Bottle is still full.`);
else console.warn(`Not quite right! Bottle should be still full but is not.`);
Expand All @@ -85,8 +110,12 @@ bottle.drink();
bottle.drink();

// CHECKS
if (bottle.volume === 70) console.log(`That's correct! Water volume is ${bottle.volume}.`);
else console.warn(`Not quite right! Water volume should be 70 unit instead of ${bottle.volume}.`);
if (bottle.volume === 70)
console.log(`That's correct! Water volume is ${bottle.volume}.`);
else
console.warn(
`Not quite right! Water volume should be 70 unit instead of ${bottle.volume}.`
);

// ACTIONS
bottle.drink();
Expand All @@ -98,7 +127,10 @@ if (!bottle.isFull()) console.log(`That's correct! Bottle isn't full.`);
else console.warn(`Not quite right! Bottle should not be full but it is.`);

if (!bottle.isEmpty()) console.log(`That's correct! Bottle isn't empty yet.`);
else console.warn(`Not quite right! Bottle should not be still empty but it is already.`);
else
console.warn(
`Not quite right! Bottle should not be still empty but it is already.`
);

// ACTIONS
bottle.drink();
Expand All @@ -108,17 +140,28 @@ bottle.drink();

// CHECKS
if (bottle.isEmpty()) console.log(`That's correct! Bottle is finally emptied.`);
else console.warn(`Not quite right. Bottle should be already empty but it is not.`);

if (bottle.volume === 0) console.log(`That's correct! Empty bottle volume is repesented as zero.`);
else console.warn(`Not quite right. Volume should be zero instead of ${bottle.volume}.`);
else
console.warn(
`Not quite right. Bottle should be already empty but it is not.`
);

if (bottle.volume === 0)
console.log(`That's correct! Empty bottle volume is repesented as zero.`);
else
console.warn(
`Not quite right. Volume should be zero instead of ${bottle.volume}.`
);

// ACTIONS
bottle.drink();

// CHECKS
if (bottle.volume === 0) console.log(`That's correct! Water volume cannot go below zero.`);
else console.warn(`Whoops!!! Looks like your water volume went negative. Your water volume is ${bottle.volume} unit.`);
if (bottle.volume === 0)
console.log(`That's correct! Water volume cannot go below zero.`);
else
console.warn(
`Whoops!!! Looks like your water volume went negative. Your water volume is ${bottle.volume} unit.`
);

if (bottle.isEmpty()) console.log(`That's correct! Bottle is still empty.`);
else console.warn(`Not quite right. Bottle should be empty but it is not.`);
Expand All @@ -127,18 +170,28 @@ else console.warn(`Not quite right. Bottle should be empty but it is not.`);
bottle.pour();

// CHECKS
if (bottle.volume === 10) console.log(`That's correct! Water volume is ${bottle.volume}.`);
else console.warn(`Not quite right! Water volume should be 10 unit instead of ${bottle.volume}.`);
if (bottle.volume === 10)
console.log(`That's correct! Water volume is ${bottle.volume}.`);
else
console.warn(
`Not quite right! Water volume should be 10 unit instead of ${bottle.volume}.`
);

if (!bottle.isFull()) console.log(`That's correct! Bottle isn't yet full.`);
else console.warn(`Not quite right! Bottle should not be full but it is.`);

if (!bottle.isEmpty()) console.log(`That's correct! Bottle isn't empty anymore.`);
else console.warn(`Not quite right! Bottle should not be empty again but it is still.`);
if (!bottle.isEmpty())
console.log(`That's correct! Bottle isn't empty anymore.`);
else
console.warn(
`Not quite right! Bottle should not be empty again but it is still.`
);

// ACTIONS
bottle.drink();

// CHECKS
if (bottle.isEmpty()) console.log(`That's correct! Bottle is emptied once more.`);
else console.warn(`Not quite right. Bottle should be empty again but it is not.`);
if (bottle.isEmpty())
console.log(`That's correct! Bottle is emptied once more.`);
else
console.warn(`Not quite right. Bottle should be empty again but it is not.`);
25 changes: 16 additions & 9 deletions week-4/Homework/mandatory/4-groceries.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,15 +11,15 @@ that contains the missing ingredients to your menus. It is stored in the "weekly
Complete the exercises below.
*/

// Here is your
// Here is your
let weeklyMealPlan = {
monday: ["Cheese", "Eggs", "Tomato", "Paprika", "Leek"],
tuesday: ["Wrap", "Tuna", "Canned beans", "Cheese", "Carrot", "Aubergine"],
wednesday: ["Orange Juice", "Apple", "Ananas", "Black tea"],
thursday: ["Lamb", "Salt", "Bulgur", "Potato"],
fridray: ["Rice milk", "Blueberries", "Porridge", "Banana", "Cinnamon"],
saturday: ["Olive oil", "Potato", "Salmon", "Asparagus"],
sunday: []
sunday: [],
};

/*
Expand All @@ -29,8 +29,8 @@ Exercise 1:
*/
// Gather all week item names into this array
let weeklyGroceriesToBuy = [];


weeklyGroceriesToBuy = Object.values(weeklyMealPlan);
console.log(weeklyGroceriesToBuy);

/*
Exercise 2:
Expand All @@ -39,9 +39,11 @@ Exercise 2:
*/
// Gather weekend item names into this array
let weekendGroceriesToBuy = [];



weekendGroceriesToBuy = Object.values(
weeklyMealPlan.saturday,
weeklyMealPlan.sunday
);
console.log(weekendGroceriesToBuy);
/*
Exercise 2:
Loop through your weekly meal plan:
Expand All @@ -50,13 +52,18 @@ Exercise 2:

Finally use console.log() to print out the Object.
*/
// Gather weekend item names into this object
//Gather weekend item names into this array

let numberOfItemsPerWeak = {
monday: 0,
tuesday: 0,
wednesday: 0,
thursday: 0,
fridray: 0,
saturday: 0,
sunday: 0
sunday: 0,
};
for (let day in weeklyMealPlan) {
numberOfItemsPerWeak[day] = weeklyMealPlan[day].length;
}
console.log(numberOfItemsPerWeak);
11 changes: 10 additions & 1 deletion week-4/InClass/A-objects-intro/exercise-part-0.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,13 @@ Describe your own laptop as a JavaScript object

Try to think of as many properties as you can!

*/
*/
let laptop = {
Brand: "Dell",
Os: "Linux",
screenSize: 14,
cpu: "Core I 5",
Hdd: 256,
color: "Black",
};
console.log(laptop);
33 changes: 33 additions & 0 deletions week-4/InClass/A-objects-intro/exercise-part-1.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,3 +7,36 @@ Assign each of them to a separate variable

*/

let mobilePhone = {
Brand: "Iphone",
screenSize: "5.8",
Model: "7 plus",
capacity: "128 GB",
};
let tv = {
Brand: "Samsung",
screenSize: "55 inches",
color: "Silver",
smart: true,
preInstaldedApps: true,
};
let sofa = {
Brand: "DFS",
"How Many Seaters": 7,
color: "Teal",
material: "Fabric",
};
let house = {
"Number of Bedrooms": 2,
Flat: true,
house: false,
level: 2,
furnished: true,
};
let fridge = {
Brand: "Hot Point",
color: "Black",
capacity: "230 Liter",
"Fridge Freezer": true,
};
console.log(fridge);
Loading