Skip to content
This repository was archived by the owner on Jan 3, 2023. It is now read-only.
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
12 changes: 8 additions & 4 deletions mandatory/1-writers.js
Original file line number Diff line number Diff line change
Expand Up @@ -67,8 +67,7 @@ Exercise 1:
"Hi, my name is {firstName} {lastName}. I am {age} years old, and work as a {occupation}."
*/
function logAllWriters() {
// write your code to log all writers here
};
writers.forEach(writer => console.log(`Hi, my name is ${writer.firstName} ${writer.lastName}. I am ${writer.age} years old, and work as a ${writer.occupation}.`))};

/*
Exercise 2:
Expand All @@ -80,7 +79,10 @@ Exercise 2:
*/

function logDeadWritersInTheirForties() {
// write your code here
// CHOOSE WRITERS OVER 40 AND DIED
const writer40sAndDead = writers.filter(writer => writer.age >=40 && writer.age <=49 && !writer.alive );
writer40sAndDead.forEach(elm => console.log(`Writer ${elm.firstName} ${elm.lastName} died at ${elm.age} years old.`));

}

/*
Expand All @@ -92,7 +94,9 @@ Exercise 3:
*/

function logAliveWritersInTheirForties() {
// write your code here
// // CHOOSE WRITERS OVER 40 AND ALIVE
const writers40sAlive = writers.filter(writer => writer.age >=40 && writer.age <=49 && writer.alive );
writers40sAlive.forEach(writer => console.log(`Hi, my name is ${writer.firstName} ${writer.lastName}. I am ${writer.age} years old.`));
}

/* ======= TESTS - DO NOT MODIFY =====
Expand Down
22 changes: 22 additions & 0 deletions mandatory/10-cheap-diner.js
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,28 @@ Should give the answer "Nothing :("
**/

function chooseMeal(mealArray) {
// IF ARRAY IS EMPTY OR IF IT HAS 1 MENU, FIND IT AND RETURN
if(mealArray.length === 0){
return "Nothing :(";
} else if(mealArray.length === 1){
return mealArray[0].name;
}else{
let cheapestMenu= mealArray[0];
let secondCheapestMenu= mealArray[1];
// console.log(cheapestMenu.price,'<<<<<<<<<<<<<<<<<<<<<');
// LOOK THROUGH ALL ARRAY, IF CURRENT MENU 'menu' PRICE CHEAPEST =>
// CHANGE CHEAPEST MENU , ALSO OLD CHEAPEST WILL BECOME SECONDCHEAPEST
mealArray.forEach(menu => {
if(menu.price < cheapestMenu.price) {
secondCheapestMenu = cheapestMenu;
cheapestMenu = menu;
// IF CURRENT MENU PRICE BETWEEN CHEAPEST AND SECONDCHEAPEST => CHANGE SECONDCHEAPEST
} else if(menu.price > cheapestMenu.price && menu.price < secondCheapestMenu.price){
secondCheapestMenu =menu;
}
});
return secondCheapestMenu.name;
}
}

/* ======= TESTS - DO MODIFY (!!!) =====
Expand Down
22 changes: 21 additions & 1 deletion mandatory/11-choose-your-own-adventure.js
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,11 @@ let game = {
currentRoom: null,

start: function (roomName) {
if(roomName === "hall" || roomName === "classroom" ||roomName === "library"){
this.currentRoom = rooms[roomName];
} else {console.log("YOU ENTER WRONG NAME YOU WILL GO TO THE HALL");
this.currentRoom = rooms.hall
};
// This function is called with the name of the room that the player wants
// to start in.
// Finish the function so that the currentRoom property is set to the room
Expand All @@ -48,7 +53,22 @@ let game = {
// Hint: the only valid rooms are "hall", "classroom" and "library".
},

move: function (direction) {
move: function (dirc) {
//CHECK DIRETION, IT HAS TO BE RIGHT DIRECTION 'north/east/south/west'
if(dirc === 'north' || dirc === 'east' || dirc === 'south' || dirc === 'west' ){
//FIND DIRECTION FUNCTION IN YOUR CURRENT ROOM. IT WILL RETURN FUNCTION
// ASSIGNT IT TO 'directionFunction
let directionFunction = this.currentRoom[dirc];
//CALL THAT FUNCTION => IT WILL RETURN NULL OR NEW ROOM OBJECT, IF ITS A ROOM => ASSIGN IT TO CURRENT ROOM
// IF IT IS NULL, STAY ROOM AND GIVE MESSAGE
if(directionFunction()===null){
console.log(`****YOU CAN NOT GO THAT WAY PLEASE TRY ANOTHER WAY***`);
}else{
this.currentRoom = directionFunction();
}
} else {
console.log(`YOU ENTER WRONG DIRECTION NAME, PLEASE CHECK AND TRY AGAIN`)
}
// This function is called with the direction that the player wants to move.
// Finish the function so that the currentRoom property is updated with new
// room in the direction that the player wants to move in.
Expand Down
5 changes: 4 additions & 1 deletion mandatory/2-eligible-students.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,10 @@
*/

function eligibleStudents(attendances) {

//filter objects over 8
const over8Objects= attendances.filter(student => student.attendance >=8);
// take names
return over8Objects.map(student => student.name);
}

/* ======= TESTS - DO NOT MODIFY =====
Expand Down
11 changes: 10 additions & 1 deletion mandatory/3-journey-planner.js
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,16 @@
*/

function journeyPlanner(locations, transportMode) {

const avaibleLocations = [];
// check all locations
for(const key in locations){
// if its avaible for transporMode add to the array (just names)
if(locations[key].includes(transportMode)){
avaibleLocations.push(key);
}
}
//return array
return avaibleLocations;
}

/* ======= TESTS - DO NOT MODIFY =====
Expand Down
11 changes: 10 additions & 1 deletion mandatory/4-water-bottle.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,22 +20,31 @@ You have to implement the missing features according to the specification.
*/

// Here is your starting point:
let bottle = {
const bottle = {
volume: 0,
fillUp: function () {
// calling this function should completely fill your bottle (volume = 100);
this.volume =100;
},
pour: function () {
// calling this function should increase your bottle volume by 10 units;
this.volume +=10;
//if bottle is full, update volume = 100
if(this.volume > 100) { this.volume =100;}
},
drink: function () {
// calling this function should decrease your bottle volume by 10 units;
this.volume -= 10;
//if bottle is empty, update volume = 0
if(this.volume < 0) { this.volume = 0;}
},
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
32 changes: 27 additions & 5 deletions mandatory/5-groceries.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ Complete the exercises below.
*/

// Here is your
let weeklyMealPlan = {
const weeklyMealPlan = {
monday: ["Cheese", "Eggs", "Tomato", "Paprika", "Leek"],
tuesday: ["Wrap", "Tuna", "Canned beans", "Cheese", "Carrot", "Aubergine"],
wednesday: ["Orange Juice", "Apple", "Ananas", "Black tea"],
Expand All @@ -28,23 +28,41 @@ Exercise 1:
The weeklyGroceriesToBuy array shouldn't contain any repeating items.
*/
// Gather all week item names into this array
let weeklyGroceriesToBuy = [];
const weeklyGroceriesToBuy = [];
// look through all days,
for(const day in weeklyMealPlan){
//take all items one-by-one from daily array
weeklyMealPlan[day].forEach(items => {
// if it is NOT inside weeklyGroceriesToBuy, add it
if(!weeklyGroceriesToBuy.includes(items)){ weeklyGroceriesToBuy.push(items);}
});
}

/*
Exercise 2:
Loop through your list again, but now only collect the weekend items into the weekendGroceriesToBuy array.
*/
// Gather weekend item names into this array
let weekendGroceriesToBuy = [];

const weekendGroceriesToBuy = [];
// look through all days,
for(const day in weeklyMealPlan){
//if days are saturday or sunday
if(day === 'saturday' || day === 'sunday') {
//take all items one-by-one from daily array
weeklyMealPlan[day].forEach(items => {
// if it is NOT inside weeklyGroceriesToBuy, add it
if(!weekendGroceriesToBuy.includes(items)){ weekendGroceriesToBuy.push(items);}
});
}
}
/*
Exercise 3:
Loop through your weekly meal plan:
- count how many ingredients you should buy each day
- and update the corresponding properties of numberOfItemsPerWeek object.
*/
// Gather daily item counts into this object
let numberOfItemsPerWeek = {
const numberOfItemsPerWeek = {
monday: 0,
tuesday: 0,
wednesday: 0,
Expand All @@ -53,6 +71,10 @@ let numberOfItemsPerWeek = {
saturday: 0,
sunday: 0,
};
for(const day in weeklyMealPlan){
numberOfItemsPerWeek[day] = weeklyMealPlan[day].length;
// console.log(day,'<<<<<<DAY KEY');
}

/* ======= TESTS - DO NOT MODIFY =====
- To run the tests for this exercise, run `npm test -- --testPathPattern 5-groceries.js`
Expand Down
35 changes: 27 additions & 8 deletions mandatory/6-people-I-know.js
Original file line number Diff line number Diff line change
Expand Up @@ -381,17 +381,19 @@ In the above object you can see my friends and the colleagues of my friends.
First, I want you to find all of my friends who are 35 or older.

*/

let thirtyFiveOrOlder = [];
// TAKE ALL FRIEND OVER 35
const thirtyFiveOrOlder = friends.filter(elem => elem.age >=35);;

/*
3) Find the email address

Next, I want you to find all of my friends who work for "POWERNET" and then store their emails in the array below

*/

let powerNetEmails = [];
//FILTER FRIENDS OBJECTS WHO HAS POWERNET MAIL
const friendsWithPowernet =friends.filter(elem => elem.email.includes('powernet'));
// TAKE THEIR EMAIL ADDRESSES
const powerNetEmails = friendsWithPowernet.map(elem => elem.email);

/*

Expand All @@ -404,8 +406,16 @@ You can see who people's colleagues are by seeing the "colleagues" array in each
This time, I only want the full names ("<firstname> <lastname>") of my friends who are colleagues of hers.

*/

let friendsWhoAreColleaguesOfStacie = [];
// LOOK THROUGH ALL FRIENDS ARRAY (MAIN)
const friendsObjectWhoColleaguesOfStacie= friends.filter(friend => {
//FOR EVERY FRIEND, LOOK 'COLLEAGUES' ARRAY AND IF THERE IS A NAME "Stacie Villarreal"(at least one) INSIDE IT = FILTER THEM
return friend.colleagues.some(obj => obj.name === "Stacie Villarreal" );

})
// TAKE THEIR NAMES AND LAST NAMES
const friendsWhoAreColleaguesOfStacie = friendsObjectWhoColleaguesOfStacie.map(friend => `${friend.name.first} ${friend.name.last}`);
//ORIGINAL ARRAY 'friendsWhoAreColleaguesOfStacie' TRUE BAT REVERSE, CHANGE IT
friendsWhoAreColleaguesOfStacie.reverse();
/*

5) Find "Multi-tasking" colleagues
Expand All @@ -417,8 +427,17 @@ You can tell if they are good at "Multi-tasking" because they will have it liste
This time, I only want the full names of the people who can multitask

*/

let colleaguesWhoCanMultitask = [];
// LOOK THROUGH ALL FRIENDS ARRAY (MAIN)
const colleaguesWhoCanMultitask =[];
friends.forEach(friend =>{
//FOR EVERY FRIEND, LOOK 'COLLEAGUES ' ARRAY
friend.colleagues.forEach(colleague => {
//IF 'SKILL' ARRAY INCLUDES(MULTUTASK) INSIDE IT = TAKE NAMES INTO ARRAY
if(colleague.skills.includes("Multi-tasking")){
colleaguesWhoCanMultitask.push(`${colleague.name}`)
}
})
});

/* ======= TESTS - DO NOT MODIFY =====
- To run the tests for this exercise, run `npm test -- --testPathPattern 6-people-I-know.js`
Expand Down
39 changes: 37 additions & 2 deletions mandatory/7-recipes.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,5 +24,40 @@ You should write and log at least 5 recipes

**/

let recipes = {};

const recipes = {
coffee : {
names:'Filter Coffee',
service : 2,
ingredients :['ground coffee', 'french press', 'hot water']
},
pasta : {
names:'Spaghetti Bolognese',
service : 2,
ingredients :['pasta', 'bolognese souce', 'hot water','salt','yogurt']
},
cake : {
names:'Cocoa Cake',
service : 4,
ingredients :['flour', 'sugar', 'milk', 'egg', 'oil', 'cocoa']
},
mole : {
names:'Mole',
service : 2,
ingredients :['cinnamon', 'cumin', 'cocoa']
},
fish : {
names:'Fish',
service : 3,
ingredients :['fish', 'onion', 'bay leaf', 'salt', 'oil', 'garlic']
}
};

for(const recipe in recipes){
console.log(`${recipes[recipe].names}`);
console.log(`Serves: ${recipes[recipe].service}`);
console.log('Ingredients');
recipes[recipe].ingredients.forEach(element => {
console.log(element);
});
console.log('**************************');
}
Loading