Skip to content
This repository was archived by the owner on Jan 3, 2023. It is now read-only.
Closed
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
76 changes: 46 additions & 30 deletions mandatory/1-writers.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,35 +20,34 @@
*/

// We've created an array of objects for you here:
let writers = [
{
firstName: "Virginia",
lastName: "Woolf",
occupation: "writer",
age: 59,
alive: false,
},
{
firstName: "Zadie",
lastName: "Smith",
occupation: "writer",
age: 41,
alive: true,
},
{
firstName: "Jane",
lastName: "Austen",
occupation: "writer",
age: 41,
alive: false,
},
{
firstName: "Bell",
lastName: "Hooks",
occupation: "writer",
age: 64,
alive: true,
},
let writers = [{
firstName: "Virginia",
lastName: "Woolf",
occupation: "writer",
age: 59,
alive: false,
},
{
firstName: "Zadie",
lastName: "Smith",
occupation: "writer",
age: 41,
alive: true,
},
{
firstName: "Jane",
lastName: "Austen",
occupation: "writer",
age: 41,
alive: false,
},
{
firstName: "Bell",
lastName: "Hooks",
occupation: "writer",
age: 64,
alive: true,
},
];

/*
Expand All @@ -59,6 +58,14 @@ Exercise 1:

"Hi, my name is {firstName} {lastName}. I am {age} years old, and work as a {occupation}."
*/
writers.forEach(function(writers) {
console.log(`Hi, my name is ${writers.firstName} ${writers.lastName}. I am ${writers.age} years old, and work as a ${writers.occupation}.`);
});

function hello(arr) {
console.log(`Hello, my name is ${arr.map([firstName])}`);

}

/*
Exercise 2:
Expand All @@ -68,11 +75,20 @@ Exercise 2:

"Writer {firstName} {lastName} died at {age} years old."
*/

writers.forEach(function(writers) {
if (writers.age > 40 && writers.age < 49 && writers.alive === false) {
console.log(`Hi, my name is ${writers.firstName} ${writers.lastName}. I am ${writers.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."
*/
writers.forEach(function(writers) {
if (writers.age > 40 && writers.age < 49 && writers.alive === true) {
console.log(`Hi, my name is ${writers.firstName} ${writers.lastName}. I am ${writers.age} years old.`);
}
});
182 changes: 96 additions & 86 deletions mandatory/2-water-bottle.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,22 +21,32 @@ You have to implement the missing features according to the specification.

// Here is your starting point:
let bottle = {
volume: 0,
fillUp: function () {
// calling this function should completely fill your bottle (volume = 100);
},
pour: function () {
// calling this function should increase your bottle volume by 10 units;
},
drink: function () {
// calling this function should decrease your bottle volume by 10 units;
},
isFull: function () {
// this function should return true if your bottle is full;
},
isEmpty: function () {
// this function should return true if your bottle is empty;
},
volume: 0,
fillUp: function() {
// calling this function should completely fill your bottle (volume = 100);
return this.volume += 100;
},
pour: function() {
// calling this function should increase your bottle volume by 10 units;
if (this.volume <= 90) {
return this.volume += 10;
}
},
drink: function() {
// calling this function should decrease your bottle volume by 10 units;
if (this.volume >= 10) {
return this.volume -= 10;
}
},
isFull: function() {
// this function should return true if your bottle is full;
return this.volume === 100;
},
isEmpty: function() {
// this function should return true if your bottle is empty;
return this.volume === 0;

},
};

/*
Expand Down Expand Up @@ -66,41 +76,41 @@ bottle.fillUp();

// CHECKS
if (bottle.isFull()) {
console.log(`That's correct! Bottle is full.`);
console.log(`That's correct! Bottle is full.`);
} else {
failed = true;
console.warn(`Not quite right! Bottle should be full but it is not.`);
failed = true;
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.`);
console.log(`That's correct! Bottle isn't empty.`);
} else {
failed = true;
console.warn(
`Not quite right! Bottle should not be empty but it is already.`
);
failed = true;
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 {
failed = true;
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.`
);
console.log(
`That's correct. Bottle is already full water volume cannot go beyond.`
);
} else {
failed = true;
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.`);
console.log(`That's correct! Bottle is still full.`);
} else {
failed = true;
console.warn(`Not quite right! Bottle should be still full but is not.`);
failed = true;
console.warn(`Not quite right! Bottle should be still full but is not.`);
}

// ACTIONS
Expand All @@ -110,12 +120,12 @@ bottle.drink();

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

// ACTIONS
Expand All @@ -125,20 +135,20 @@ bottle.drink();

// CHECKS
if (!bottle.isFull()) {
console.log(`That's correct! Bottle isn't full.`);
console.log(`That's correct! Bottle isn't full.`);
} else {
failed = true;
console.warn(`Not quite right! Bottle should not be full but it is.`);
failed = true;
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.`);
console.log(`That's correct! Bottle isn't empty yet.`);
} else {
failed = true;
failed = true;

console.warn(
`Not quite right! Bottle should not be still empty but it is already.`
);
console.warn(
`Not quite right! Bottle should not be still empty but it is already.`
);
}

// ACTIONS
Expand All @@ -149,95 +159,95 @@ bottle.drink();

// CHECKS
if (bottle.isEmpty()) {
console.log(`That's correct! Bottle is finally emptied.`);
console.log(`That's correct! Bottle is finally emptied.`);
} else {
failed = true;
failed = true;

console.warn(
`Not quite right. Bottle should be already empty but it is not.`
);
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.`);
console.log(`That's correct! Empty bottle volume is repesented as zero.`);
} else {
failed = true;
failed = true;

console.warn(
`Not quite right. Volume should be zero instead of ${bottle.volume}.`
);
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.`);
console.log(`That's correct! Water volume cannot go below zero.`);
} else {
failed = true;
failed = true;

console.warn(
`Whoops!!! Looks like your water volume went negative. Your water volume is ${bottle.volume} unit.`
);
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.`);
console.log(`That's correct! Bottle is still empty.`);
} else {
console.warn(`Not quite right. Bottle should be empty but it is not.`);
console.warn(`Not quite right. Bottle should be empty but it is not.`);
}

// ACTIONS
bottle.pour();

// CHECKS
if (bottle.volume === 10) {
console.log(`That's correct! Water volume is ${bottle.volume}.`);
console.log(`That's correct! Water volume is ${bottle.volume}.`);
} else {
failed = true;
failed = true;

console.warn(
`Not quite right! Water volume should be 10 unit instead of ${bottle.volume}.`
);
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.`);
console.log(`That's correct! Bottle isn't yet full.`);
} else {
failed = true;
failed = true;

console.warn(`Not quite right! Bottle should not be full but it is.`);
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.`);
console.log(`That's correct! Bottle isn't empty anymore.`);
} else {
failed = true;
failed = true;

console.warn(
`Not quite right! Bottle should not be empty again but it is still.`
);
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.`);
console.log(`That's correct! Bottle is emptied once more.`);
} else {
failed = true;
failed = true;

console.warn(`Not quite right. Bottle should be empty again but it is not.`);
console.warn(`Not quite right. Bottle should be empty again but it is not.`);
}

console.log("");

if (failed) {
console.log(
"RESULT: Incorrect. Please read what went wrong above and try again"
);
console.log(
"RESULT: Incorrect. Please read what went wrong above and try again"
);
} else {
console.log("RESULT: Correct! Congratulations!");
}
console.log("RESULT: Correct! Congratulations!");
}
Loading