From 8ba7550a6d2f91347bb7795ea8b55d8f474b447a Mon Sep 17 00:00:00 2001 From: Andrei <68118535+Andryushik@users.noreply.github.com> Date: Mon, 24 Oct 2022 15:45:37 +0200 Subject: [PATCH 01/21] Update 3-log-number.js --- Week1/practice-exercises/3-log-number.js | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) diff --git a/Week1/practice-exercises/3-log-number.js b/Week1/practice-exercises/3-log-number.js index c29038c..dfd8506 100644 --- a/Week1/practice-exercises/3-log-number.js +++ b/Week1/practice-exercises/3-log-number.js @@ -4,20 +4,22 @@ */ // 1. Declare your variable numberX. Do not initialize it (which means, don't give it a starting value) yet - +let numberX; // 2. Add a console.log statement that explains in words what you think the value of x is - +console.log('X number is not defined'); // 3. Add a console.log statement that logs the value of numberX. - +console.log(numberX); // 4. Now initialize your variable numberX with a number (also called an integer in computer science terms) - +numberX = 5; // 5. Next, add a console.log statement that explains what you think the value of numberX is - +console.log('X number is now 5'); // 6. Add a console.log statement that logs the value of numberX +console.log(numberX); + From 3eed3b6bd9cd3b9bcdb410315059c62c765a4122 Mon Sep 17 00:00:00 2001 From: Andrei <68118535+Andryushik@users.noreply.github.com> Date: Mon, 24 Oct 2022 15:49:10 +0200 Subject: [PATCH 02/21] Update 1-hello-world.js --- Week1/practice-exercises/1-hello-world.js | 1 + 1 file changed, 1 insertion(+) diff --git a/Week1/practice-exercises/1-hello-world.js b/Week1/practice-exercises/1-hello-world.js index e345354..4a211e8 100644 --- a/Week1/practice-exercises/1-hello-world.js +++ b/Week1/practice-exercises/1-hello-world.js @@ -10,3 +10,4 @@ * Hola, mundo! // Spanish */ +console.log('Привет МИР!') //Russian From edd8a4d4fdda15f294d44cfcac18acd4da626361 Mon Sep 17 00:00:00 2001 From: Andrei <68118535+Andryushik@users.noreply.github.com> Date: Mon, 24 Oct 2022 15:50:07 +0200 Subject: [PATCH 03/21] Update 2-syntax-error.js --- Week1/practice-exercises/2-syntax-error.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Week1/practice-exercises/2-syntax-error.js b/Week1/practice-exercises/2-syntax-error.js index a0005dd..00d67ba 100644 --- a/Week1/practice-exercises/2-syntax-error.js +++ b/Week1/practice-exercises/2-syntax-error.js @@ -3,4 +3,4 @@ * Fix it so that when running this file it shows the message 'I'm awesome!' */ -console.log('I'm awesome'!; \ No newline at end of file +console.log("I'm awesome!"); From a310057b9208ef78c1b13f05a989b8a55d62040b Mon Sep 17 00:00:00 2001 From: Andrei <68118535+Andryushik@users.noreply.github.com> Date: Mon, 24 Oct 2022 15:57:15 +0200 Subject: [PATCH 04/21] Update 4-log-string.js --- Week1/practice-exercises/4-log-string.js | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/Week1/practice-exercises/4-log-string.js b/Week1/practice-exercises/4-log-string.js index 8e38cb3..196bab0 100644 --- a/Week1/practice-exercises/4-log-string.js +++ b/Week1/practice-exercises/4-log-string.js @@ -4,20 +4,20 @@ */ // 1. Declare a variable myString and assign a string to it. Use your full name, including spaces, as the content for the string. - +let myString = 'Andrei Popov'; // 2. Write a console.log statement in which you explain in words what you think the value of the string is. - +console.log('String value is my full name'); // 3. Now console.log the variable myString. - +console.log(myString); // 4. Now reassign to the variable myString a new string. - +myString = 'Andrei'; // 5. Just like what you did before write a console.log statement that explains in words what you think will be logged to the console. - +console.log('String value is my name'); // 6. Now console.log myString again. - +console.log(myString); From e994001087cbea759cfb588cb43e4c3d2247dbc5 Mon Sep 17 00:00:00 2001 From: Andrei <68118535+Andryushik@users.noreply.github.com> Date: Mon, 24 Oct 2022 16:08:53 +0200 Subject: [PATCH 05/21] Update 5-round-number.js --- Week1/practice-exercises/5-round-number.js | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) diff --git a/Week1/practice-exercises/5-round-number.js b/Week1/practice-exercises/5-round-number.js index 602c5f1..d0672f6 100644 --- a/Week1/practice-exercises/5-round-number.js +++ b/Week1/practice-exercises/5-round-number.js @@ -3,15 +3,20 @@ */ // 1. Declare a variable z and assign the number 7.25 to it. - +let z = 7.25; // 2. Write a console.log statement in which you log the value of z. - +console.log('z value is ' + z); // 3. Declare another variable a that has the value of z but rounded to the nearest integer. - +let a = Math.round(z); // 4. Write a console.log statement in which you log the value of a. - +console.log('a value is ' + a); // 5. So now we have z and a find a way to compare the two values and log true if a is greater than z or false if a is smaller than z. +if (a > z) { + console.log(true); +} else { + console.log(false); +} From ca86e2753999358c7b3ae82d916ea01661729b6f Mon Sep 17 00:00:00 2001 From: Andrei <68118535+Andryushik@users.noreply.github.com> Date: Mon, 24 Oct 2022 16:22:16 +0200 Subject: [PATCH 06/21] Update 6-log-animals.js --- Week1/practice-exercises/6-log-animals.js | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/Week1/practice-exercises/6-log-animals.js b/Week1/practice-exercises/6-log-animals.js index 65c2e41..3f6bcba 100644 --- a/Week1/practice-exercises/6-log-animals.js +++ b/Week1/practice-exercises/6-log-animals.js @@ -3,23 +3,23 @@ */ // 1. Declare variable and assign to it an empty array. Make sure that the name of the variable indicates it contains more than 1 item. For example items instead of item. - +const items = []; // 2. Write a console.log statement that explains in words what you think the value of the array is. - +console.log('array is empty as it declared'); // 3. Write a console.log statement that logs the array. - +console.log(items); // 4. Create a new variable with an array that has 3 of your favorite animals, each in a different string. Make sure the name of the variables says something about what the variable contains. - +const myFavoriteAnimals = ['cat', 'horse', 'monkey'] // 5. Write a console.log statement that logs the second array. - +console.log(myFavoriteAnimals); // 6. Add a statement that adds another string ("Piglet)" to the array of animals. - +myFavoriteAnimals.push('piglet'); // 7. Write a console.log statement that logs the second array! - +console.log(myFavoriteAnimals); From b989ed35e8181aaa40840cdcff4f8796c854cdcd Mon Sep 17 00:00:00 2001 From: Andrei <68118535+Andryushik@users.noreply.github.com> Date: Mon, 24 Oct 2022 16:48:03 +0200 Subject: [PATCH 07/21] Update 7-log-string-length.js --- Week1/practice-exercises/7-log-string-length.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/Week1/practice-exercises/7-log-string-length.js b/Week1/practice-exercises/7-log-string-length.js index b1ee540..cbc2698 100644 --- a/Week1/practice-exercises/7-log-string-length.js +++ b/Week1/practice-exercises/7-log-string-length.js @@ -3,7 +3,7 @@ */ // 1. Declare a variable called mySentence and initialize it with the following string: "Programming is so interesting!". - +const mySentence = "Programming is so interesting!" // 2. Figure out (using Google) how to get the length of mySentence. Then write a console.log statement to log the length of mySentence. - +console.log(`${mySentence} Length of this sentence is ${mySentence.length}.`); From 7fa710a5702c59051cd10e4c4735be6a7c62f09a Mon Sep 17 00:00:00 2001 From: Andrei <68118535+Andryushik@users.noreply.github.com> Date: Fri, 28 Oct 2022 15:31:25 +0200 Subject: [PATCH 08/21] done --- .../1-traffic-light/traffic-light-1.js | 17 ++++++++++++----- 1 file changed, 12 insertions(+), 5 deletions(-) diff --git a/Week2/prep-exercises/1-traffic-light/traffic-light-1.js b/Week2/prep-exercises/1-traffic-light/traffic-light-1.js index f1d9169..c9f3126 100644 --- a/Week2/prep-exercises/1-traffic-light/traffic-light-1.js +++ b/Week2/prep-exercises/1-traffic-light/traffic-light-1.js @@ -1,31 +1,38 @@ -"use strict"; +'use strict'; /** * The `state` property says what the traffic light's state (i.e. colour) is at * that moment. */ const trafficLight = { - state: "green", + state: 'green', }; let rotations = 0; while (rotations < 2) { const currentState = trafficLight.state; - console.log("The traffic light is on", currentState); + console.log('The traffic light is on', currentState); // TODO // if the color is green, turn it orange // if the color is orange, turn it red // if the color is red, add 1 to rotations and turn it green + + if (currentState == 'green') { + trafficLight.state = 'orange'; + } else if (currentState == 'orange') { + trafficLight.state = 'red'; + } else { + rotations++; + trafficLight.state = 'green'; + } } /** * The output should be: - The traffic light is on green The traffic light is on orange The traffic light is on red The traffic light is on green The traffic light is on orange The traffic light is on red - */ From ddb5f144c71e64275520199cd7b11dd29c4af3ea Mon Sep 17 00:00:00 2001 From: Andrei <68118535+Andryushik@users.noreply.github.com> Date: Fri, 28 Oct 2022 16:04:53 +0200 Subject: [PATCH 09/21] v1 done --- .../1-traffic-light/traffic-light-2.js | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/Week2/prep-exercises/1-traffic-light/traffic-light-2.js b/Week2/prep-exercises/1-traffic-light/traffic-light-2.js index 8c6ba95..802df67 100644 --- a/Week2/prep-exercises/1-traffic-light/traffic-light-2.js +++ b/Week2/prep-exercises/1-traffic-light/traffic-light-2.js @@ -18,16 +18,22 @@ while (cycle < 2) { // if the color is green, turn it orange // if the color is orange, turn it red // if the color is red, add 1 to cycles and turn it green + + if (currentState == 'green') { + trafficLight.stateIndex = 1; + } else if (currentState == 'orange') { + trafficLight.stateIndex = 2; + } else { + cycle++; + trafficLight.stateIndex = 0; + } } - /** * The output should be: - The traffic light is on green The traffic light is on orange The traffic light is on red The traffic light is on green The traffic light is on orange The traffic light is on red - */ From c561557c7aa106c840fe86ddde28a8cde7ff661f Mon Sep 17 00:00:00 2001 From: Andrei <68118535+Andryushik@users.noreply.github.com> Date: Fri, 28 Oct 2022 16:34:45 +0200 Subject: [PATCH 10/21] with short solution --- .../1-traffic-light/traffic-light-2.js | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) diff --git a/Week2/prep-exercises/1-traffic-light/traffic-light-2.js b/Week2/prep-exercises/1-traffic-light/traffic-light-2.js index 802df67..90b7afb 100644 --- a/Week2/prep-exercises/1-traffic-light/traffic-light-2.js +++ b/Week2/prep-exercises/1-traffic-light/traffic-light-2.js @@ -37,3 +37,21 @@ The traffic light is on green The traffic light is on orange The traffic light is on red */ +//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + +//Shortest solution for traffic light exercise +'use strict'; +const trafficLight = { + possibleStates: ['green', 'orange', 'red'], +}; + +for (let cycle = 0; cycle < 2; cycle++) { + for ( + trafficLight.stateIndex = 0; + trafficLight.stateIndex <= 2; + trafficLight.stateIndex++ + ) { + const currentState = trafficLight.possibleStates[trafficLight.stateIndex]; + console.log('The traffic light is on', currentState); + } +} From e93cb6891fbf2065373d1207f3d650b86bb68189 Mon Sep 17 00:00:00 2001 From: Andrei <68118535+Andryushik@users.noreply.github.com> Date: Fri, 28 Oct 2022 17:16:33 +0200 Subject: [PATCH 11/21] Update 1-remove-the-comma.js --- Week2/practice-exercises/1-remove-the-comma.js | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/Week2/practice-exercises/1-remove-the-comma.js b/Week2/practice-exercises/1-remove-the-comma.js index b71cffd..79d7d31 100644 --- a/Week2/practice-exercises/1-remove-the-comma.js +++ b/Week2/practice-exercises/1-remove-the-comma.js @@ -7,8 +7,9 @@ let myString = 'hello,this,is,a,difficult,to,read,sentence'; - +myString = myString.replace(/,/g, ' '); +//"g" means to all symbols in the string not only the first one /* --- Code that will test your solution, do NOT change. Write above this line --- */ -console.assert(myString === 'hello this is a difficult to read sentence', 'There is something wrong with your solution'); \ No newline at end of file +console.assert(myString === 'hello this is a difficult to read sentence', 'There is something wrong with your solution'); From 4354a5376608528a704550b2e518bce3f86b1d37 Mon Sep 17 00:00:00 2001 From: Andrei <68118535+Andryushik@users.noreply.github.com> Date: Fri, 28 Oct 2022 18:19:03 +0200 Subject: [PATCH 12/21] done --- Week2/practice-exercises/2-even-odd-reporter.js | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/Week2/practice-exercises/2-even-odd-reporter.js b/Week2/practice-exercises/2-even-odd-reporter.js index 6edf23e..ae4d8d8 100644 --- a/Week2/practice-exercises/2-even-odd-reporter.js +++ b/Week2/practice-exercises/2-even-odd-reporter.js @@ -7,3 +7,12 @@ * If it's even, log to the console The number [PUT_NUMBER_HERE] is even!. */ +let num = 0; +do { + if (num % 2 == 0) { + console.log(num + " is even"); + } else { + console.log(num + " is odd"); + } + num++ + } while (num <= 20); From 22d4dacdd3d6a9ded036730784402b99aeacf217 Mon Sep 17 00:00:00 2001 From: Andrei <68118535+Andryushik@users.noreply.github.com> Date: Fri, 28 Oct 2022 19:04:19 +0200 Subject: [PATCH 13/21] Update 3-recipe-card.js --- Week2/practice-exercises/3-recipe-card.js | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/Week2/practice-exercises/3-recipe-card.js b/Week2/practice-exercises/3-recipe-card.js index 24bcb54..f32882c 100644 --- a/Week2/practice-exercises/3-recipe-card.js +++ b/Week2/practice-exercises/3-recipe-card.js @@ -12,3 +12,12 @@ * Ingredients: 4 eggs, 2 strips of bacon, 1 tsp salt/pepper */ +const mealRecipe = { + mealName: 'Omelette', + serves: 2, + ingredients: ['eggs', 'bacon', 'salt', 'peppere', 'milk'] +}; + +for (const property in mealRecipe) { + console.log(`${property}: ${mealRecipe[property]}`); +} From 4437e904fb9056e34ecc6b85c74b9d72cde74343 Mon Sep 17 00:00:00 2001 From: Andrei <68118535+Andryushik@users.noreply.github.com> Date: Fri, 28 Oct 2022 19:32:33 +0200 Subject: [PATCH 14/21] better view of array's elements --- Week2/practice-exercises/3-recipe-card.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/Week2/practice-exercises/3-recipe-card.js b/Week2/practice-exercises/3-recipe-card.js index f32882c..2f8c2fb 100644 --- a/Week2/practice-exercises/3-recipe-card.js +++ b/Week2/practice-exercises/3-recipe-card.js @@ -15,9 +15,9 @@ const mealRecipe = { mealName: 'Omelette', serves: 2, - ingredients: ['eggs', 'bacon', 'salt', 'peppere', 'milk'] + ingredients: ['eggs', 'bacon', 'salt', 'pepper', 'milk'], }; for (const property in mealRecipe) { - console.log(`${property}: ${mealRecipe[property]}`); + console.log(`${property}: ${mealRecipe[property]}`.replace(/,/g, ', ')); //changing ',' to ', + space' for beauty in array elements } From 672bc3f1bd6b628fa8b998589bc9ffca797d0254 Mon Sep 17 00:00:00 2001 From: Andrei <68118535+Andryushik@users.noreply.github.com> Date: Fri, 28 Oct 2022 20:33:58 +0200 Subject: [PATCH 15/21] Update 4-reading-list.js --- Week2/practice-exercises/4-reading-list.js | 24 ++++++++++++++++++++++ 1 file changed, 24 insertions(+) diff --git a/Week2/practice-exercises/4-reading-list.js b/Week2/practice-exercises/4-reading-list.js index f535657..c9a395d 100644 --- a/Week2/practice-exercises/4-reading-list.js +++ b/Week2/practice-exercises/4-reading-list.js @@ -9,3 +9,27 @@ * If you haven't read it log a string like You still need to read "The Lord of the Rings" */ +const myBooks = [ + { + title: "Harry Potter and the Philosopher's Stone", + author: 'J. K. Rowling', + alreadyRead: true, + }, + { + title: 'Harry Potter and the Goblet of Fire', + author: 'J. K. Rowling', + alreadyRead: true, + }, + { + title: 'Harry Potter and the half-blood', + author: 'J. K. Rowling', + alreadyRead: false, + }, +]; +for (const book of myBooks) { + if (book.alreadyRead == true) { + console.log(`You already read "${book.title}" by ${book.author}`); + } else { + console.log(`You still need to read "${book.title}" by ${book.author}`); + } +} From 1deaa22c9b45672aef82304258f4d0e22fdcb290 Mon Sep 17 00:00:00 2001 From: Andrei <68118535+Andryushik@users.noreply.github.com> Date: Fri, 28 Oct 2022 21:35:32 +0200 Subject: [PATCH 16/21] Update 5-who-wants-a-drink.js --- .../practice-exercises/5-who-wants-a-drink.js | 23 ++++++++++++++++++- 1 file changed, 22 insertions(+), 1 deletion(-) diff --git a/Week2/practice-exercises/5-who-wants-a-drink.js b/Week2/practice-exercises/5-who-wants-a-drink.js index f37f02b..b757924 100644 --- a/Week2/practice-exercises/5-who-wants-a-drink.js +++ b/Week2/practice-exercises/5-who-wants-a-drink.js @@ -8,4 +8,25 @@ */ // There are 3 different types of drinks: -const drinkTypes = ['cola', 'lemonade', 'water']; \ No newline at end of file + +const drinkTypes = ['cola', 'lemonade', 'water']; +const drinkTray = []; +let n = 0; +for (let i = 0; i < 5; i++) { + if (n > 2) { + n = 0; + } + drinkTray.push(drinkTypes[n]); + n++; +} +console.log(`Hey guys! I brought a ${drinkTray}!`.replace(/,/g, ', ')); + +// Another version with rendom function + +const drinkTypes = ['cola', 'lemonade', 'water']; +const drinkTray = []; +for (let i = 0; i <5; i++) { + let n = Math.floor(Math.random() * 3); + drinkTray.push(drinkTypes[n]); +}; +console.log(`Hey guys, I brought a ${drinkTray}!`.replace(/,/g, ', ')); From 7f03ba251a83a59556973f7276bfd5ae88174515 Mon Sep 17 00:00:00 2001 From: Andrei <68118535+Andryushik@users.noreply.github.com> Date: Fri, 28 Oct 2022 21:49:25 +0200 Subject: [PATCH 17/21] Update 5-who-wants-a-drink.js --- Week2/practice-exercises/5-who-wants-a-drink.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/Week2/practice-exercises/5-who-wants-a-drink.js b/Week2/practice-exercises/5-who-wants-a-drink.js index b757924..c112bf2 100644 --- a/Week2/practice-exercises/5-who-wants-a-drink.js +++ b/Week2/practice-exercises/5-who-wants-a-drink.js @@ -19,7 +19,7 @@ for (let i = 0; i < 5; i++) { drinkTray.push(drinkTypes[n]); n++; } -console.log(`Hey guys! I brought a ${drinkTray}!`.replace(/,/g, ', ')); +console.log(`Hey guys, I brought a ${drinkTray.join(', ')}!`); // Another version with rendom function @@ -29,4 +29,4 @@ for (let i = 0; i <5; i++) { let n = Math.floor(Math.random() * 3); drinkTray.push(drinkTypes[n]); }; -console.log(`Hey guys, I brought a ${drinkTray}!`.replace(/,/g, ', ')); +console.log(`Hey guys, I brought a ${drinkTray.join(', ')}!`); From 03cb773047db6bbc9a038c41bf58e7c49f477b1f Mon Sep 17 00:00:00 2001 From: Andrei <68118535+Andryushik@users.noreply.github.com> Date: Thu, 3 Nov 2022 19:57:49 +0100 Subject: [PATCH 18/21] Update traffic-light.js --- .../1-traffic-light/traffic-light.js | 49 +++++++++---------- 1 file changed, 23 insertions(+), 26 deletions(-) diff --git a/Week3/prep-exercises/1-traffic-light/traffic-light.js b/Week3/prep-exercises/1-traffic-light/traffic-light.js index f4a5c1a..defe3a8 100644 --- a/Week3/prep-exercises/1-traffic-light/traffic-light.js +++ b/Week3/prep-exercises/1-traffic-light/traffic-light.js @@ -1,52 +1,49 @@ -"use strict"; -/** - * The `trafficLight` object is now no longer a global variable. Instead, - * it is defined in function `main()` and passed as a parameter to other - * functions, as and when needed. - */ +'use strict'; function getCurrentState(trafficLight) { - // TODO - // Should return the current state (i.e. colour) of the `trafficLight` - // object passed as a parameter. + return trafficLight.possibleStates[trafficLight.stateIndex]; } function getNextStateIndex(trafficLight) { - // TODO - // Return the index of the next state of the `trafficLight` such that: - // - if the color is green, it will turn to orange - // - if the color is orange, it will turn to red - // - if the color is red, it will turn to green + +// if (trafficLight.stateIndex === 0) { +// return (trafficLight.stateIndex = 1); +// } else if (trafficLight.stateIndex === 1) { +// return (trafficLight.stateIndex = 2); +// } else { +// return (trafficLight.stateIndex = 0); +// } + +// The same but shorter with ternary operators + return trafficLight.stateIndex === 0 + ? (trafficLight.stateIndex = 1) + : trafficLight.stateIndex === 1 + ? (trafficLight.stateIndex = 2) + : (trafficLight.stateIndex = 0); } -// This function loops for the number of seconds specified by the `secs` -// parameter and then returns. -// IMPORTANT: This is not the recommended way to implement 'waiting' in -// JavaScript. You will learn better ways of doing this when you learn about -// asynchronous code. function waitSync(secs) { const start = Date.now(); - while (Date.now() - start < secs * 1000) { - // nothing do to here - } + while (Date.now() - start < secs * 1000) {} } function main() { const trafficLight = { - possibleStates: ["green", "orange", "red"], + possibleStates: ['green', 'orange', 'red'], stateIndex: 0, }; for (let cycle = 0; cycle < 6; cycle++) { const currentState = getCurrentState(trafficLight); - console.log(cycle, "The traffic light is now", currentState); - - waitSync(1); // Wait a second before going to the next state + console.log(cycle, 'The traffic light is now', currentState); + waitSync(1); trafficLight.stateIndex = getNextStateIndex(trafficLight); + console.log(getNextStateIndex(trafficLight)); } } main(); + /** * The output should be: From fc5fc40c3992ab4635fa178658bc32cbf11ddc63 Mon Sep 17 00:00:00 2001 From: Andrei Date: Fri, 11 Nov 2022 19:01:53 +0100 Subject: [PATCH 19/21] week 4 preparation exercises done --- .../1-hyf-program/1-find-mentors.js | 23 +++++++++++++------ .../1-hyf-program/2-class-list.js | 23 +++++++++++++++---- 2 files changed, 35 insertions(+), 11 deletions(-) diff --git a/Week4/prep-exercises/1-hyf-program/1-find-mentors.js b/Week4/prep-exercises/1-hyf-program/1-find-mentors.js index a096de0..d474bba 100644 --- a/Week4/prep-exercises/1-hyf-program/1-find-mentors.js +++ b/Week4/prep-exercises/1-hyf-program/1-find-mentors.js @@ -1,4 +1,4 @@ -import { modules, students, mentors, classes } from "./hyf"; +import { modules, students, mentors, classes } from './hyf.js'; /** * Tjebbe would like help to get a list of possible mentors for a module. @@ -8,10 +8,14 @@ import { modules, students, mentors, classes } from "./hyf"; * ['John', 'Mary'] */ const possibleMentorsForModule = (moduleName) => { - // TODO complete this function + const possibleMentors = mentors.filter((mentor) => + mentor.canTeach.includes(moduleName), + ); + const possibleMentorsNames = []; + possibleMentors.forEach((mentor) => possibleMentorsNames.push(mentor.name)); + return possibleMentorsNames; }; -// You can uncomment out this line to try your function -// console.log(possibleMentorsForModule('using-apis')); +console.log(possibleMentorsForModule('using-apis')); /** * Tjebbe wants to make it even easier for himself. @@ -19,8 +23,13 @@ const possibleMentorsForModule = (moduleName) => { * * It should return a single name. */ + const findMentorForModule = (moduleName) => { - // TODO complete this function + const possibleMentorsNames = possibleMentorsForModule(moduleName); + const randomName = + possibleMentorsNames[ + Math.floor(Math.random() * possibleMentorsNames.length) + ]; + return randomName; }; -// You can uncomment out this line to try your function -// console.log(findMentorForModule('javascript')); +console.log(findMentorForModule('javascript')); diff --git a/Week4/prep-exercises/1-hyf-program/2-class-list.js b/Week4/prep-exercises/1-hyf-program/2-class-list.js index 995f9f1..ea9b3c2 100644 --- a/Week4/prep-exercises/1-hyf-program/2-class-list.js +++ b/Week4/prep-exercises/1-hyf-program/2-class-list.js @@ -1,4 +1,4 @@ -import { modules, students, mentors, classes } from "./hyf"; +import { modules, students, mentors, classes } from './hyf.js'; /** * We would like to have a list of everyone that is currently participating in a class. @@ -12,10 +12,25 @@ import { modules, students, mentors, classes } from "./hyf"; * [{ name: 'John', role: 'student' }, { name: 'Mary', role: 'mentor' }] */ const getPeopleOfClass = (className) => { - // TODO complete this function + const peopleOfClass = []; + const studentsOfClass = students.filter( + (student) => student.class == className, + ); + studentsOfClass.forEach((student) => + peopleOfClass.push({ name: student.name, role: 'student' }), + ); + const moduleName = classes.find( + (clasS) => clasS.name == className, + ).currentModule; + const mentorsOfClass = mentors.filter( + (mentor) => mentor.nowTeaching == moduleName, + ); + mentorsOfClass.forEach((mentor) => + peopleOfClass.push({ name: mentor.name, role: 'mentor' }), + ); + return peopleOfClass; }; -// You can uncomment out this line to try your function -// console.log(getPeopleOfClass('class34')); +console.log(getPeopleOfClass('class34')); /** * We would like to have a complete overview of the current active classes. From 11da1bfac6119f35a125ae96fe84b92b7fee855e Mon Sep 17 00:00:00 2001 From: Andrei Date: Fri, 11 Nov 2022 22:08:41 +0100 Subject: [PATCH 20/21] ex2.2 not finished --- .../1-hyf-program/2-class-list.js | 17 +++++++++++++---- 1 file changed, 13 insertions(+), 4 deletions(-) diff --git a/Week4/prep-exercises/1-hyf-program/2-class-list.js b/Week4/prep-exercises/1-hyf-program/2-class-list.js index ea9b3c2..00fe153 100644 --- a/Week4/prep-exercises/1-hyf-program/2-class-list.js +++ b/Week4/prep-exercises/1-hyf-program/2-class-list.js @@ -20,7 +20,7 @@ const getPeopleOfClass = (className) => { peopleOfClass.push({ name: student.name, role: 'student' }), ); const moduleName = classes.find( - (clasS) => clasS.name == className, + (classN) => classN.name == className, ).currentModule; const mentorsOfClass = mentors.filter( (mentor) => mentor.nowTeaching == moduleName, @@ -44,8 +44,17 @@ console.log(getPeopleOfClass('class34')); * class35: [{ name: 'Jane', role: 'student' }, { name: 'Steve', role: 'mentor' }] * } */ + const getActiveClasses = () => { - // TODO complete this function + const getActiveClassesArray = []; + const getActiveClasses = {}; + const getActive = classes.filter((classN) => classN.active == true); + getActive.forEach((classN) => getActiveClassesArray.push(classN.name)); + //getActiveClassesArray.reduce((acc, classN) => ({ ...acc, classN: [] })); + + console.log(getActiveClassesArray); + console.log(getActiveClasses); + return getActiveClasses; }; -// You can uncomment out this line to try your function -// console.log(getActiveClasses()); + +console.log(getActiveClasses()); From fd22db73f287c413fe794c0d162ea8de3566441a Mon Sep 17 00:00:00 2001 From: Andrei Date: Tue, 15 Nov 2022 12:43:24 +0100 Subject: [PATCH 21/21] done --- .../1-hyf-program/2-class-list.js | 22 ++++++++++++------- Week4/prep-exercises/1-hyf-program/index.html | 15 +++++++++++++ 2 files changed, 29 insertions(+), 8 deletions(-) create mode 100644 Week4/prep-exercises/1-hyf-program/index.html diff --git a/Week4/prep-exercises/1-hyf-program/2-class-list.js b/Week4/prep-exercises/1-hyf-program/2-class-list.js index 00fe153..a33b715 100644 --- a/Week4/prep-exercises/1-hyf-program/2-class-list.js +++ b/Week4/prep-exercises/1-hyf-program/2-class-list.js @@ -46,14 +46,20 @@ console.log(getPeopleOfClass('class34')); */ const getActiveClasses = () => { - const getActiveClassesArray = []; - const getActiveClasses = {}; - const getActive = classes.filter((classN) => classN.active == true); - getActive.forEach((classN) => getActiveClassesArray.push(classN.name)); - //getActiveClassesArray.reduce((acc, classN) => ({ ...acc, classN: [] })); - - console.log(getActiveClassesArray); - console.log(getActiveClasses); + const getActiveClasses = () => { + const getActiveClassesTemp = {}; + const getActive = classes.filter((classN) => classN.active == true); + getActive.forEach( + (classN) => + (getActiveClassesTemp[classN.name] = getPeopleOfClass(classN.name)), + ); + return getActiveClassesTemp; + }; + // Another method + // const activeClasses = {}; + // for (const item of classes) { + // if (item.active) activeClasses[item.name] = getPeopleOfClass(item.name); + // } return getActiveClasses; }; diff --git a/Week4/prep-exercises/1-hyf-program/index.html b/Week4/prep-exercises/1-hyf-program/index.html new file mode 100644 index 0000000..2dc3c6d --- /dev/null +++ b/Week4/prep-exercises/1-hyf-program/index.html @@ -0,0 +1,15 @@ + + + + + + + + Codestin Search App + + + + + + + \ No newline at end of file