From d0eb2ef7c9e4273a779025ca9904018bdf0fd875 Mon Sep 17 00:00:00 2001 From: Ashaghel Date: Sun, 26 Apr 2020 19:18:51 +0100 Subject: [PATCH 01/55] added notes to w2-j4 --- week-2/Homework/extra/4-radio-stations.js | 9 ++++----- week-2/Homework/mandatory/4-sorting-algorithm.js | 3 ++- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/week-2/Homework/extra/4-radio-stations.js b/week-2/Homework/extra/4-radio-stations.js index 95c0e5611..a58292537 100644 --- a/week-2/Homework/extra/4-radio-stations.js +++ b/week-2/Homework/extra/4-radio-stations.js @@ -26,7 +26,6 @@ */ // `getStations` goes here - /* ======= TESTS - DO NOT MODIFY ======= */ function getAvailableStations() { @@ -36,10 +35,10 @@ function getAvailableStations() { const stationCount = 4; getAvailableStations.stations = new Array(stationCount) .fill(undefined) - .map(function() { + .map(function () { return Math.floor(Math.random() * (108 - 87 + 1) + 87); }) - .sort(function(frequencyA, frequencyB) { + .sort(function (frequencyA, frequencyB) { return frequencyA - frequencyB; }); } @@ -64,7 +63,7 @@ function test(testName, fn) { } } -test("getAllFrequencies() returns all frequencies between 87 and 108", function() { +test("getAllFrequencies() returns all frequencies between 87 and 108", function () { const frequencies = getAllFrequencies(); assert.deepStrictEqual(frequencies, [ 87, @@ -88,7 +87,7 @@ test("getAllFrequencies() returns all frequencies between 87 and 108", function( 105, 106, 107, - 108 + 108, ]); }); diff --git a/week-2/Homework/mandatory/4-sorting-algorithm.js b/week-2/Homework/mandatory/4-sorting-algorithm.js index ec5d4208b..df953cca4 100644 --- a/week-2/Homework/mandatory/4-sorting-algorithm.js +++ b/week-2/Homework/mandatory/4-sorting-algorithm.js @@ -7,13 +7,14 @@ Today, you will be applying the sorting algorithm you used in that exercise in c Create a function called sortAges which: - takes an array of mixed data types as input - removes any non-number data types without using the built-in javascript filter method + - returns an array of sorted ages in ascending order - HARD MODE - without using the built-in javascript sort method 😎 You don't have to worry about making this algorithm work fast! The idea is to get you to "think" like a computer and practice your knowledge of basic JavaScript. */ - +//(think about loops and nested loops function sortAges(arr) {} /* ======= TESTS - DO NOT MODIFY ===== */ From c30ee0fd48c5db74915aa09b2541d9fb2214b6a8 Mon Sep 17 00:00:00 2001 From: Ashaghel Date: Sun, 26 Apr 2020 22:03:13 +0100 Subject: [PATCH 02/55] Hakona Matata Anthony and Ahmad --- ...-radio-stations.js => 1-radio-stations.js} | 0 week-2/Homework/extra/2-array-methods.js | 35 +++++++++++++++++++ .../{0-freecodecamp.md => 0-introduction.md} | 19 +++++++++- week-2/Homework/mandatory/1-fix-functions.js | 35 ++++++++++++++++--- .../Homework/mandatory/2-function-creation.js | 12 +++---- .../Homework/mandatory/3-playing-computer.js | 10 ++++-- .../Homework/mandatory/4-sorting-algorithm.js | 15 +++++--- 7 files changed, 108 insertions(+), 18 deletions(-) rename week-2/Homework/extra/{4-radio-stations.js => 1-radio-stations.js} (100%) create mode 100644 week-2/Homework/extra/2-array-methods.js rename week-2/Homework/mandatory/{0-freecodecamp.md => 0-introduction.md} (77%) diff --git a/week-2/Homework/extra/4-radio-stations.js b/week-2/Homework/extra/1-radio-stations.js similarity index 100% rename from week-2/Homework/extra/4-radio-stations.js rename to week-2/Homework/extra/1-radio-stations.js diff --git a/week-2/Homework/extra/2-array-methods.js b/week-2/Homework/extra/2-array-methods.js new file mode 100644 index 000000000..4fa4028fe --- /dev/null +++ b/week-2/Homework/extra/2-array-methods.js @@ -0,0 +1,35 @@ +/* +Following are set of small functions that you need to create using loops and array methods + +*/ +//1)Find the Smallest Number in an Array +//Create a function that takes an array of numbers and return the smallest number in it + +function findSmallestNum(arr) {} + +findSmallestNum([354, 15, 114, 2]); //Expected: 2 + +findSmallestNum([-76, 1, -79, 1, 0]); //Expected: -79 + +//2)Checking Even Numbers +//Create a function that takes in an array and returns true if all its values are even, and false otherwise. +function checkAllEven(arr) {} + +checkAllEven([1, 2, 2, 6, 9, 4]); //Expected: false + +checkAllEven([2, 4, 6]); //Expected: true +//3)Half, Quarter and Eighth +//Create a function that takes a number and return an array of three numbers: half of the number, quarter of the number and an eighth of the number. +function getHalfQuarterEighth(number) {} +getHalfQuarterEighth(6); //Expected:[3, 1.5, 0.75] + +//4)Add the index to the number +//Given an array of numbers, create a function which returns the same array but with each element's index in the array added to itself. This means you add 0 to the number at index 0, add 1 to the number at index 1, etc... +function addIndexes(arr) {} +addIndexes([1, 4, 3, 4, 5]); //Expected: [1, 5, 5, 7, 9] + +//4)Get the Sum of All Array Elements +//Create a function that takes an array and returns the sum of all numbers in the array. +function getSumOfItems(arr) {} + +getSumOfItems([-2, 84, 23]); //Expected: 105 diff --git a/week-2/Homework/mandatory/0-freecodecamp.md b/week-2/Homework/mandatory/0-introduction.md similarity index 77% rename from week-2/Homework/mandatory/0-freecodecamp.md rename to week-2/Homework/mandatory/0-introduction.md index b21a59a19..3b2e23897 100644 --- a/week-2/Homework/mandatory/0-freecodecamp.md +++ b/week-2/Homework/mandatory/0-introduction.md @@ -1,4 +1,21 @@ -## FreeCodeCamp +# Introducion + +## Instructions + +- Just making the tests become `passed` is not enough, you need to use the code already there, to help answer your the task properly +- Read instructions in the README.md on how to make correct PRs to the main repo +- Remember to use Google as much as you can help + +**Good Luck! Keep calm and code along** + +## Resources + +To get a better understanding of loops and arrays + +- [while and for loops](https://javascript.info/while-for) +- [arrays](https://javascript.info/array) + +## Freecodecamp If you haven't already, you should complete all of these lessons on FreeCodeCamp - https://www.freecodecamp.org/learn diff --git a/week-2/Homework/mandatory/1-fix-functions.js b/week-2/Homework/mandatory/1-fix-functions.js index 6316fad54..297865fdf 100644 --- a/week-2/Homework/mandatory/1-fix-functions.js +++ b/week-2/Homework/mandatory/1-fix-functions.js @@ -1,6 +1,15 @@ +// Fix Functions + +// Aim: to understand the change code inside functions +// // The below functions are syntactically correct but not outputting the right results. // Look at the tests and see how you can fix them. + + +// 1) mood function does this return `"I am not happy"` +// Only make edits inside the function + function mood() { let isHappy = true; @@ -11,9 +20,13 @@ function mood() { } } +// 2) For any numerical value greater or equal to 10 +// Hint: use constant `num` and only change isBigEnough. +// Variable isBigEnough needs to evaluate to a boolean + function greaterThan10() { - let num = 10; - let isBigEnough; + const num = 10; + const isBigEnough; if (isBigEnough) { return "num is greater than or equal to 10"; @@ -22,13 +35,21 @@ function greaterThan10() { } } +// 3) For any numerical value greater or equal to 10 +// Hint: use the Array method sort() +// Remember to Google how to use sort method + function sortArray() { - let letters = ["a", "n", "c", "e", "z", "f"]; + const letters = ["a", "n", "c", "e", "z", "f"]; let sortedLetters; return sortedLetters; } +// 4) first5 function shold return the first 5 elements of array +// Hint: use the Array method splice() +// Remember to Google how to use splice() + function first5() { let numbers = [1, 2, 3, 4, 5, 6, 7, 8]; let sliced; @@ -36,6 +57,12 @@ function first5() { return sliced; } +// 5) get3rdIndex function needs to take an array `arr` give +// back third element value. +// For example with array `[1, 2, 3, 4, 5]` it needs to return `4` +// +// Hint: remember that arrays are zero-index based + function get3rdIndex(arr) { let index = 3; let element; @@ -82,7 +109,7 @@ test("first5 function works", arraysEqual(first5(), [1, 2, 3, 4, 5])); test( "get3rdIndex function works - case 1", get3rdIndex(["fruit", "banana", "apple", "strawberry", "raspberry"]) === - "strawberry" + "strawberry" ); test( "get3rdIndex function works - case 2", diff --git a/week-2/Homework/mandatory/2-function-creation.js b/week-2/Homework/mandatory/2-function-creation.js index bf7ecfde8..2c6ddf073 100644 --- a/week-2/Homework/mandatory/2-function-creation.js +++ b/week-2/Homework/mandatory/2-function-creation.js @@ -37,9 +37,7 @@ Write a function that: - numbers greater 100 must be replaced with 100 */ -function formatPercentage(arr) { - -} +function formatPercentage(arr) {} /* ======= TESTS - DO NOT MODIFY ===== */ @@ -72,7 +70,7 @@ test( "daniel", "irina", "gordon", - "ashleigh" + "ashleigh", ]) ); test( @@ -101,7 +99,7 @@ test( "c", "d", "e", - "f" + "f", ]) ); @@ -111,6 +109,6 @@ test( "23%", "18%", "100%", - "0.37%" + "0.37%", ]) -); \ No newline at end of file +); diff --git a/week-2/Homework/mandatory/3-playing-computer.js b/week-2/Homework/mandatory/3-playing-computer.js index 0fa7c043f..3f2832738 100644 --- a/week-2/Homework/mandatory/3-playing-computer.js +++ b/week-2/Homework/mandatory/3-playing-computer.js @@ -1,3 +1,9 @@ +// Playing computer +// +// Aim: to understand and predict the answers of loops, and if statmetns +// +// You need write the answers of the below questions 1-7 + /* You have to predict the output of this program WITHOUT EXECUTING IT. @@ -18,11 +24,11 @@ let x = 2; let a = 6; -const f1 = function(a, b) { +const f1 = function (a, b) { return a + b; }; -const f2 = function(a, b) { +const f2 = function (a, b) { return a + b + x; }; diff --git a/week-2/Homework/mandatory/4-sorting-algorithm.js b/week-2/Homework/mandatory/4-sorting-algorithm.js index df953cca4..af6b2949e 100644 --- a/week-2/Homework/mandatory/4-sorting-algorithm.js +++ b/week-2/Homework/mandatory/4-sorting-algorithm.js @@ -1,3 +1,9 @@ +// Sorting Algorithms +// +// Aim: to understand the work of loops and nested loops and array methods +// +// You need to create the function sortAges that takes one array as parameter input + /* At the start of the course, you worked in teams to sort your team members, labelled by numbers, in ascending or descending order. @@ -6,16 +12,17 @@ Today, you will be applying the sorting algorithm you used in that exercise in c Create a function called sortAges which: - takes an array of mixed data types as input -- removes any non-number data types without using the built-in javascript filter method - +- removes any non-number data types without using the built-in javascript filter method - returns an array of sorted ages in ascending order - HARD MODE - without using the built-in javascript sort method 😎 You don't have to worry about making this algorithm work fast! The idea is to get you to "think" like a computer and practice your knowledge of basic JavaScript. */ -//(think about loops and nested loops -function sortAges(arr) {} +//1)Create the function inside, Think about nested loops +function sortAges(arr) { + //create function here +} /* ======= TESTS - DO NOT MODIFY ===== */ From 74e3f469e6bafa2e7bad1b2a3447573a1ea4f901 Mon Sep 17 00:00:00 2001 From: Jane Trimmer Date: Mon, 27 Apr 2020 11:50:48 +0100 Subject: [PATCH 03/55] fix minor spelling and grammatical errors --- week-2/Homework/mandatory/1-fix-functions.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/week-2/Homework/mandatory/1-fix-functions.js b/week-2/Homework/mandatory/1-fix-functions.js index 297865fdf..442f1816a 100644 --- a/week-2/Homework/mandatory/1-fix-functions.js +++ b/week-2/Homework/mandatory/1-fix-functions.js @@ -46,7 +46,7 @@ function sortArray() { return sortedLetters; } -// 4) first5 function shold return the first 5 elements of array +// 4) first5 function should return the first 5 elements of array // Hint: use the Array method splice() // Remember to Google how to use splice() @@ -57,7 +57,7 @@ function first5() { return sliced; } -// 5) get3rdIndex function needs to take an array `arr` give +// 5) get3rdIndex function needs to take an array `arr` and give // back third element value. // For example with array `[1, 2, 3, 4, 5]` it needs to return `4` // From 6fcaeb5d1a0be3d4a44b0679bf63cd0b155da14c Mon Sep 17 00:00:00 2001 From: Ashaghel Date: Fri, 1 May 2020 23:40:32 +0100 Subject: [PATCH 04/55] editing exercises for week3 mcr3 --- week-3/Homework/extra/1-card-vailidator.md | 35 ------ .../{0-freecodecamp.md => 0- Introduction.md} | 12 +- week-3/Homework/mandatory/3-space-colonies.js | 17 +-- .../Homework/mandatory/5-journey-planner.js | 115 +++++++++++++----- .../{8-codewars.md => 7-codewars.md} | 12 +- .../mandatory/7-password-validator.js | 69 ----------- 6 files changed, 104 insertions(+), 156 deletions(-) delete mode 100644 week-3/Homework/extra/1-card-vailidator.md rename week-3/Homework/mandatory/{0-freecodecamp.md => 0- Introduction.md} (73%) rename week-3/Homework/mandatory/{8-codewars.md => 7-codewars.md} (88%) delete mode 100644 week-3/Homework/mandatory/7-password-validator.js diff --git a/week-3/Homework/extra/1-card-vailidator.md b/week-3/Homework/extra/1-card-vailidator.md deleted file mode 100644 index d0f9f81ef..000000000 --- a/week-3/Homework/extra/1-card-vailidator.md +++ /dev/null @@ -1,35 +0,0 @@ -## **PROJECT: Credit Card Validator** - -In this project you'll write a script that validates whether or not a credit card number is valid. - -Here are the rules for a valid number: - -- Number must be 16 digits, all of them must be numbers -- You must have at least two different digits represented (all of the digits cannot be the same) -- The final digit must be even -- The sum of all the digits must be greater than 16 -- The following credit card numbers are valid: - -```markdown -9999777788880000 -6666666666661666 -``` - -The following credit card numbers are invalid: - -```markdown -a92332119c011112 (invalid characters) -4444444444444444 (only one type of number) -1111111111111110 (sum less than 16) -6666666666666661 (odd final number) -``` - -These are the requirements your project needs to fulfill: - -- Make a JavaScript file with a name that describes its contents -- Create a function with a descriptive name, for example: `doSomething` or `calcAnotherThing` -- Write at least 2 comments that explain to others what a line of code is meant to do -- Make the return value of the function a template string, so you can insert variables! -- Use `node` from the command line to test if your code works as expected - -Good luck! diff --git a/week-3/Homework/mandatory/0-freecodecamp.md b/week-3/Homework/mandatory/0- Introduction.md similarity index 73% rename from week-3/Homework/mandatory/0-freecodecamp.md rename to week-3/Homework/mandatory/0- Introduction.md index 65d254cbe..e6a9ef8eb 100644 --- a/week-3/Homework/mandatory/0-freecodecamp.md +++ b/week-3/Homework/mandatory/0- Introduction.md @@ -2,6 +2,10 @@ You should complete all of these FreeCodeCamp exercises - https://www.freecodecamp.org/learn +> -Go to JavaScript Algorithms and Data Structures Certification (300 hours) +> -Then oepn Basic Data Structures +> Do the following exercises + - Introduction to the Basic Data Structure Challenges - Use an Array to Store a Collection of Data - Access an Array's Contents Using Bracket Notation @@ -15,14 +19,6 @@ You should complete all of these FreeCodeCamp exercises - https://www.freecodeca - Check For The Presence of an Element With indexOf() - Iterate Through All an Array's Items Using For Loops - Create complex multi-dimensional arrays -- Add Key-Value Pairs to JavaScript Objects -- Modify an Object Nested Within an Object -- Access Property Names with Bracket Notation -- Use the delete Keyword to Remove Object Properties -- Check if an Object has a Property -- Iterate Through the Keys of an Object with a for...in Statement -- Generate an Array of All Object Keys with Object.keys() -- Modify an Array Stored in an Object and you should attempt all of these diff --git a/week-3/Homework/mandatory/3-space-colonies.js b/week-3/Homework/mandatory/3-space-colonies.js index f99891a85..85c1b820c 100644 --- a/week-3/Homework/mandatory/3-space-colonies.js +++ b/week-3/Homework/mandatory/3-space-colonies.js @@ -8,9 +8,7 @@ NOTE: don't include any element that is not a "family". */ -function colonisers() { - -} +function colonisers() {} /* ======= TESTS - DO NOT MODIFY ===== */ @@ -26,7 +24,7 @@ const voyagers = [ "Asimov", "Oscar family", "Avery family", - "Archer family" + "Archer family", ]; function arraysEqual(a, b) { @@ -52,6 +50,11 @@ function test(test_name, expr) { console.log(`${test_name}: ${status}`); } -test("colonisers function works", - arraysEqual(colonisers(voyagers), ["Adam family", "Avery family", "Archer family"]) -) \ No newline at end of file +test( + "colonisers function works", + arraysEqual(colonisers(voyagers), [ + "Adam family", + "Avery family", + "Archer family", + ]) +); diff --git a/week-3/Homework/mandatory/5-journey-planner.js b/week-3/Homework/mandatory/5-journey-planner.js index 53499c372..d180ab8b9 100644 --- a/week-3/Homework/mandatory/5-journey-planner.js +++ b/week-3/Homework/mandatory/5-journey-planner.js @@ -1,3 +1,29 @@ +/* +Before we go the big story; we will introduce more string methods. Some of the methods you're using in Array have similar ones with strings +Methods like : IndexOf, Include, Search, Slice , Spilt and more. You can always google how a method of a string work +Here is links for some of them +https://www.w3schools.com/js/js_string_methods.asp +https://javascript.info/string#quotes + + +Now let's do this small exercise +Using string mapulation methods update the checkCodeIsThere() function +- The function will have a string as a paramter +-The function should check if the string has the word "code" exists in the string +- If it does exist, return the index of it, if not return not found +Hint: search string methods like Includes, IndexOF can be helpful +*/ + +function checkCodeIsThere(stringText) { + let magicWord = "code"; + //edit code below + if (stringText) { + return stringText; + } else { + return "Not found"; + } +} + /* I am new to London and would like to know what transport I can take to different famous locations. An array with London locations have been provided. @@ -6,19 +32,24 @@ NOTE: only the names should be returned, not the means of transport. */ +//Hint some string methods needed as well as array methods +//search slice and includes for string +// and filter and map for array -function journeyPlanner() { - -} +function journeyPlanner() {} /* ======= TESTS - DO NOT MODIFY ===== */ +const string1 = "I Love coding and perfect code makes me happy"; +const string2 = "I don't like to do coding"; +const string3 = "Can you scan the barcode for me"; + const londonLocations = [ ["Angel", "tube", "bus"], ["London Bridge", "tube", "river boat"], ["Tower Bridge", "tube", "bus"], - ["Greenwich", "bus", "river boat"] -] + ["Greenwich", "bus", "river boat"], +]; function arraysEqual(a, b) { if (a === b) return true; @@ -33,33 +64,51 @@ function arraysEqual(a, b) { } function test(test_name, expr) { - let status; - if (expr) { - status = "PASSED"; - } else { - status = "FAILED"; - } - - console.log(`${test_name}: ${status}`); + let status; + if (expr) { + status = "PASSED"; + } else { + status = "FAILED"; + } + + console.log(`${test_name}: ${status}`); } -test("journeyPlanner function works - case 1", - arraysEqual( - journeyPlanner(londonLocations, "river boat"), - ["London Bridge", "Greenwich"] - ) -) - -test("journeyPlanner function works - case 2", - arraysEqual( - journeyPlanner(londonLocations, "bus"), - ["Angel", "Tower Bridge", "Greenwich"] - ) -) - -test("journeyPlanner function works - case 3", - arraysEqual( - journeyPlanner(londonLocations, "tube"), - ["Angel", "London Bridge", "Tower Bridge"] - ) -) +test( + "checkCodeIsThere function works - case 1", + checkCodeIsThere(string1) === 26 +); + +test( + "checkCodeIsThere function works - case 2", + checkCodeIsThere(string2) === "Not found" +); +test( + "checkCodeIsThere function works - case 3", + checkCodeIsThere(string3) === 20 +); +test( + "journeyPlanner function works - case 1", + arraysEqual(journeyPlanner(londonLocations, "river boat"), [ + "London Bridge", + "Greenwich", + ]) +); + +test( + "journeyPlanner function works - case 2", + arraysEqual(journeyPlanner(londonLocations, "bus"), [ + "Angel", + "Tower Bridge", + "Greenwich", + ]) +); + +test( + "journeyPlanner function works - case 3", + arraysEqual(journeyPlanner(londonLocations, "tube"), [ + "Angel", + "London Bridge", + "Tower Bridge", + ]) +); diff --git a/week-3/Homework/mandatory/8-codewars.md b/week-3/Homework/mandatory/7-codewars.md similarity index 88% rename from week-3/Homework/mandatory/8-codewars.md rename to week-3/Homework/mandatory/7-codewars.md index b9cab92f1..3820c0637 100644 --- a/week-3/Homework/mandatory/8-codewars.md +++ b/week-3/Homework/mandatory/7-codewars.md @@ -1,12 +1,15 @@ # Codewars Exercises -Today, you'll be using a platform called [CodeWars](https://codewars.com) to help you recap the materials you learnt in JS1. CodeWars is an excellent platform for going through interesting JavaScript exercises, and allows you to communicate with the wider community to learn about the best way of writing JavaScript code. +Today, you'll be using a platform called [CodeWars](https://codewars.com) to help you recap the materials you learnt in JS1. CodeWars is an excellent platform for going through interesting JavaScript exercises, and allows you to communicate with the wider community to learn about the best way of writing JavaScript code. 1. Make sure you finish all the pending exercies in week-1, week-2 and week-3 of the [js-exercises repo](https://github.com/CodeYourFuture/js-exercises). 2. Signup to [CodeWars](https://codewars.com) and work on these challenges: -*Functions, types, conditionals etc...* +3. You need to finish a minimum of 3 Exercises from [functions part](Section_1) and a minimum of 3 Exercises from [Arrays part](Section_2) + +(Section*1) +\_Functions, types, conditionals etc...* - [even or odd](https://www.codewars.com/kata/even-or-odd/train/javascript) - [code under pressure](https://www.codewars.com/kata/you-cant-code-under-pressure-number-1/train/javascript) @@ -21,7 +24,8 @@ Today, you'll be using a platform called [CodeWars](https://codewars.com) to hel - [string repeat](https://www.codewars.com/kata/string-repeat/train/javascript) - [mathematical operations](https://www.codewars.com/kata/basic-mathematical-operations/train/javascript) -*Arrays* +(Section*2) +\_Arrays* - [invert values](https://www.codewars.com/kata/invert-values/train/javascript) - [needle in haystack](https://www.codewars.com/kata/a-needle-in-the-haystack/train/javascript) @@ -30,4 +34,4 @@ Today, you'll be using a platform called [CodeWars](https://codewars.com) to hel - [people in bus](https://www.codewars.com/kata/number-of-people-in-the-bus/train/javascript) - [sum without highest and lowest](https://www.codewars.com/kata/sum-without-highest-and-lowest-number/train/javascript) - [reveersed array of digits](https://www.codewars.com/kata/convert-number-to-reversed-array-of-digits/train/javascript) -- [slash sum of negatives](https://www.codewars.com/kata/count-of-positives-slash-sum-of-negatives/train/javascript) \ No newline at end of file +- [slash sum of negatives](https://www.codewars.com/kata/count-of-positives-slash-sum-of-negatives/train/javascript) diff --git a/week-3/Homework/mandatory/7-password-validator.js b/week-3/Homework/mandatory/7-password-validator.js deleted file mode 100644 index 57b3d538c..000000000 --- a/week-3/Homework/mandatory/7-password-validator.js +++ /dev/null @@ -1,69 +0,0 @@ -/* -Password Validation - -Write a program that should check if each password in an array -contains a valid password (see below for password criterias) and return -new array with true or false booleans. - -Passwords must -- Have at least 5 characters. -- Have English uppercase letters (A-Z) -- Have English lowercase letters (a-z) -- Have numbers (0-9) -- Have non-alphanumeric symbols ("!", "#", "$", "%", ".") - -Passwords must not be any previous password in the passwords array. - -Example 1: -PreviousPassword = ["fhD8!yrjj", "ttkTu.wer3", "dvyyeyY!5", "qwbfj76%", "tytT3729."]; - -Expected Result: -PasswordValidationResult= [false, false, false, false, true] - -*/ - -function validatePasswords(passwords) { - -} - -/* ======= TESTS - DO NOT MODIFY ===== */ - -const passwords1 = ["Se%5", "TktE.TJTU", "384#HsHF", "dvyyeyy!5", "tryT3729"] -const passwords2 = ["StUFf27%", "Pl3nty!", "Jai33", "shajsaUA**&&", "Pl3nty!"] - -function arraysEqual(a, b) { - if (a === b) return true; - if (a == null || b == null) return false; - if (a.length != b.length) return false; - - for (let i = 0; i < a.length; ++i) { - if (a[i] !== b[i]) return false; - } - - return true; -} - -function test(test_name, expr) { - let status; - if (expr) { - status = "PASSED"; - } else { - status = "FAILED"; - } - - console.log(`${test_name}: ${status}`); -} - -test( - "validatePasswords function works - case 1", - arraysEqual( - validatePasswords(passwords1), [false, false, true, false, false] - ) - ); - - test( - "validatePasswords function works - case 2", - arraysEqual( - validatePasswords(passwords2), [true, true, false, false, false] - ) - ); From 468db413657a3dae0ff6a341bb513d22b619bea7 Mon Sep 17 00:00:00 2001 From: Ashaghel <43817672+Ashaghel@users.noreply.github.com> Date: Sat, 2 May 2020 08:47:07 +0100 Subject: [PATCH 05/55] Update 5-journey-planner.js --- week-3/Homework/mandatory/5-journey-planner.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/week-3/Homework/mandatory/5-journey-planner.js b/week-3/Homework/mandatory/5-journey-planner.js index d180ab8b9..f4073976d 100644 --- a/week-3/Homework/mandatory/5-journey-planner.js +++ b/week-3/Homework/mandatory/5-journey-planner.js @@ -7,11 +7,11 @@ https://javascript.info/string#quotes Now let's do this small exercise -Using string mapulation methods update the checkCodeIsThere() function +Using string methods update the checkCodeIsThere() function - The function will have a string as a paramter -The function should check if the string has the word "code" exists in the string - If it does exist, return the index of it, if not return not found -Hint: search string methods like Includes, IndexOF can be helpful +Hint: search string methods like Includes,and IndexOf */ function checkCodeIsThere(stringText) { From 61639440aa942d307996e2e2d57c603bed72cb9f Mon Sep 17 00:00:00 2001 From: Ashaghel <43817672+Ashaghel@users.noreply.github.com> Date: Sat, 2 May 2020 08:48:32 +0100 Subject: [PATCH 06/55] Update 0- Introduction.md --- week-3/Homework/mandatory/0- Introduction.md | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/week-3/Homework/mandatory/0- Introduction.md b/week-3/Homework/mandatory/0- Introduction.md index e6a9ef8eb..bea3c9449 100644 --- a/week-3/Homework/mandatory/0- Introduction.md +++ b/week-3/Homework/mandatory/0- Introduction.md @@ -2,9 +2,9 @@ You should complete all of these FreeCodeCamp exercises - https://www.freecodecamp.org/learn -> -Go to JavaScript Algorithms and Data Structures Certification (300 hours) -> -Then oepn Basic Data Structures -> Do the following exercises +> >>Go to JavaScript Algorithms and Data Structures Certification (300 hours) +> >>Then oepn Basic Data Structures +> >>Do the following exercises - Introduction to the Basic Data Structure Challenges - Use an Array to Store a Collection of Data From 9346bcbd464b490557165513b6de4d775a7706ee Mon Sep 17 00:00:00 2001 From: Augs0 Date: Sat, 2 May 2020 10:18:51 +0100 Subject: [PATCH 07/55] added info on every and some to exercise 2 --- week-3/Homework/mandatory/2-bush-berries.js | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) diff --git a/week-3/Homework/mandatory/2-bush-berries.js b/week-3/Homework/mandatory/2-bush-berries.js index d90032302..ab696a3e2 100644 --- a/week-3/Homework/mandatory/2-bush-berries.js +++ b/week-3/Homework/mandatory/2-bush-berries.js @@ -8,7 +8,19 @@ Create a function which checks if the bush has ALL PINK berries and is safe for the astronauts to eat from the bush. Use the tests to confirm which message to return -*/ + + This exercise can be solved in a few different ways. One way might include the array methods .some() and .every(). The .some() method tests to see if some of the values in an array match what you're looking for and returns true or false. .every() will only return true if all values match watch you're looking for. Let's first look at an example that will teach you how to use these methods. + */ + +let array = [12, 73, 92, 45, 100, 14, 61]; + +array.some((value) => {return (value % 2 == 0)}); // this will return true as SOME values will have a remainder of 0 i.e. they are even numbers + +array.every((value) => {return (value % 2 == 0)}); // this will return false as not ALL values will have a remainder of 0 i.e. there are some odd numbers in the array too + +/* + + + + + + + + + + + + + + */ + +/* Now try to complete the exercise */ function bushChecker() { From 960c002af1f702cf66949ec00025d3ed98b5eee0 Mon Sep 17 00:00:00 2001 From: Augs0 Date: Sat, 2 May 2020 10:22:53 +0100 Subject: [PATCH 08/55] fixed formatting --- week-3/Homework/mandatory/2-bush-berries.js | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/week-3/Homework/mandatory/2-bush-berries.js b/week-3/Homework/mandatory/2-bush-berries.js index ab696a3e2..1b73eafc2 100644 --- a/week-3/Homework/mandatory/2-bush-berries.js +++ b/week-3/Homework/mandatory/2-bush-berries.js @@ -9,14 +9,20 @@ Use the tests to confirm which message to return - This exercise can be solved in a few different ways. One way might include the array methods .some() and .every(). The .some() method tests to see if some of the values in an array match what you're looking for and returns true or false. .every() will only return true if all values match watch you're looking for. Let's first look at an example that will teach you how to use these methods. + This exercise can be solved in a few different ways. One way might include the array methods + .some() and .every(). The .some() method tests to see if some of the values in an array + match what you're looking for and returns true or false. .every() will only return true + if all values match watch you're looking for. Let's first look at an example that will + teach you how to use these methods. */ let array = [12, 73, 92, 45, 100, 14, 61]; -array.some((value) => {return (value % 2 == 0)}); // this will return true as SOME values will have a remainder of 0 i.e. they are even numbers +array.some((value) => {return (value % 2 == 0)}); /* this will return true as SOME values +will have a remainder of 0 i.e. they are even numbers*/ -array.every((value) => {return (value % 2 == 0)}); // this will return false as not ALL values will have a remainder of 0 i.e. there are some odd numbers in the array too +array.every((value) => {return (value % 2 == 0)}); /* this will return false as not ALL +values will have a remainder of 0 i.e. there are some odd numbers in the array too*/ /* + + + + + + + + + + + + + + */ From c5786a954f5571bbd74fe195112913de0cb7a8a2 Mon Sep 17 00:00:00 2001 From: Augs0 Date: Sat, 2 May 2020 10:54:23 +0100 Subject: [PATCH 09/55] added info on replace and substring --- week-3/Homework/mandatory/1-oxygen-levels.js | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) diff --git a/week-3/Homework/mandatory/1-oxygen-levels.js b/week-3/Homework/mandatory/1-oxygen-levels.js index 3c021350c..a105fdeb8 100644 --- a/week-3/Homework/mandatory/1-oxygen-levels.js +++ b/week-3/Homework/mandatory/1-oxygen-levels.js @@ -7,8 +7,26 @@ Their computer detects a list of nearby planets that have Oxygen in their atmosp To be safe, they need to land on the first unamed planet that has Oxygen levels between 19.5% and 23.5%. Write a function that finds the oxygen level of the first safe planet - Oxygen between 19.5% and 23.5% + +Some string methods that might help you here are .replace() and .substring(). Let's look at a quick +example before trying the exercise. */ +/* .replace() allows us to add something where we removed something*/ +let greeting = "Good Morning"; +greeting.replace('Morning', 'Evening'); // outputs Good Evening + + +/* .substring() allows us to remove things from strings */ +let dessert = "ice cream and pancakes"; + +let newdessert = dessert.substring(0, 9); + +console.log(newdessert); // returns ice cream + +/* + + + + + + + */ +/* Now try the exercise */ + function safeLevels() { } From eb54bc52a95a9f69dde4edf0ed862077f0a26e84 Mon Sep 17 00:00:00 2001 From: Zoltan Gal Date: Sat, 2 May 2020 13:01:44 +0200 Subject: [PATCH 10/55] Modify description and add extra tests to exercise week-3/4-eligible-students --- .../Homework/mandatory/4-eligible-students.js | 50 +++++++++++++++---- 1 file changed, 40 insertions(+), 10 deletions(-) diff --git a/week-3/Homework/mandatory/4-eligible-students.js b/week-3/Homework/mandatory/4-eligible-students.js index 6424b01bd..1a6551107 100644 --- a/week-3/Homework/mandatory/4-eligible-students.js +++ b/week-3/Homework/mandatory/4-eligible-students.js @@ -1,25 +1,47 @@ /* - Only students who have attended enough classes are eligible to sit an exam. + Colonisers would like to bring some researchers to the planet to scrunise the surface. + + They also need pupils who would act as assistants. Unfortunately, the number + of seats is limited on the spaceship therefore they set the following algorithm + to select students: + + Only students who have attended enough classes are eligible to join the research teams. + + Implement the body of function called "eligibleStudents" which: + - Accepts an array which contains all the students' names and their attendance counts. + For example: + [ + ["Hunor", 10], + ["Magor", 1] + ] + See that each student's information is stored separately as an embedded array. + + This is also called as 2 dimensional array when you can find array inside of array. - Create a function which: - - Accepts an array which contains all the students' names and their attendance counts - (see tests to confirm how this data will be structured) - Returns an array containing only the names of the who have attended AT LEAST 8 classes */ -function eligibleStudents() { - +function eligibleStudents(candidates) { + // You have to implement this function body } /* ======= TESTS - DO NOT MODIFY ===== */ -const attendances = [ +const alphaStudentGroup = [ ["Ahmed", 8], ["Clement", 10], ["Elamin", 6], ["Adam", 7], ["Tayoa", 11], - ["Nina", 10] + ["Nina", 10], + ["Bob", 9], + ["Lee", 1] +] + +const deltaStudentGroup = [ + ["Zoidber", 6], + ["Bender", 5], + ["Zapp", 7] ] function arraysEqual(a, b) { @@ -47,6 +69,14 @@ function test(test_name, expr) { test("eligibleStudents function works", arraysEqual( - eligibleStudents(attendances), ["Ahmed", "Clement", "Tayoa", "Nina"] + eligibleStudents(attendances), ["Ahmed", "Clement", "Tayoa", "Nina", "Bob"] ) -) \ No newline at end of file +) + +test("eligibleStudents function without eligible candidates", + arraysEqual(eligibleStudents(deltaStudentGroup), []) +) + +test("eligibleStudents function with no candidates", + arraysEqual(eligibleStudents([]), []) +) From 191b1224ff1b7b69539c3633780f65548c1cce1f Mon Sep 17 00:00:00 2001 From: Zoltan Gal Date: Sat, 2 May 2020 13:06:39 +0200 Subject: [PATCH 11/55] fix syntax --- week-3/Homework/mandatory/4-eligible-students.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/week-3/Homework/mandatory/4-eligible-students.js b/week-3/Homework/mandatory/4-eligible-students.js index 1a6551107..a36484e61 100644 --- a/week-3/Homework/mandatory/4-eligible-students.js +++ b/week-3/Homework/mandatory/4-eligible-students.js @@ -69,7 +69,7 @@ function test(test_name, expr) { test("eligibleStudents function works", arraysEqual( - eligibleStudents(attendances), ["Ahmed", "Clement", "Tayoa", "Nina", "Bob"] + eligibleStudents(alphaStudentGroup), ["Ahmed", "Clement", "Tayoa", "Nina", "Bob"] ) ) From e20bef6f33473c421676646d1b704d9f38277ded Mon Sep 17 00:00:00 2001 From: Zoltan Gal Date: Sat, 2 May 2020 13:32:21 +0200 Subject: [PATCH 12/55] Add extra exercise to week-3/4-eligible-students --- .../Homework/mandatory/4-eligible-students.js | 37 +++++++++++++++++-- 1 file changed, 33 insertions(+), 4 deletions(-) diff --git a/week-3/Homework/mandatory/4-eligible-students.js b/week-3/Homework/mandatory/4-eligible-students.js index a36484e61..45fb86a8b 100644 --- a/week-3/Homework/mandatory/4-eligible-students.js +++ b/week-3/Homework/mandatory/4-eligible-students.js @@ -25,6 +25,24 @@ function eligibleStudents(candidates) { // You have to implement this function body } +/* + + Later leaders of Alpha planet decided to change the rule as below: + + Only students whose name starts with the same letter than the name of the planer are eligible to join. + + Implement the body of function called "eligibleStudents2" which: + - Accepts an array in the same structure as before. + - Returns an array containing only the names that satisfies the new rule. + + Note: + Unfortunately, administrators messed up the letter casing of names, sometimes it starts with small letter. +*/ + +function eligibleStudents2(candidates) { + // You have to implement this function body +} + /* ======= TESTS - DO NOT MODIFY ===== */ const alphaStudentGroup = [ @@ -41,7 +59,8 @@ const alphaStudentGroup = [ const deltaStudentGroup = [ ["Zoidber", 6], ["Bender", 5], - ["Zapp", 7] + ["Zapp", 7], + ["amy", 0] ] function arraysEqual(a, b) { @@ -68,9 +87,7 @@ function test(test_name, expr) { } test("eligibleStudents function works", - arraysEqual( - eligibleStudents(alphaStudentGroup), ["Ahmed", "Clement", "Tayoa", "Nina", "Bob"] - ) + arraysEqual(eligibleStudents(alphaStudentGroup), ["Ahmed", "Clement", "Tayoa", "Nina", "Bob"]) ) test("eligibleStudents function without eligible candidates", @@ -80,3 +97,15 @@ test("eligibleStudents function without eligible candidates", test("eligibleStudents function with no candidates", arraysEqual(eligibleStudents([]), []) ) + +test("eligibleStudents2 function works", + arraysEqual(eligibleStudents2(alphaStudentGroup), ["Ahmed", "Adam"]) +) + +test("eligibleStudents2 function without eligible candidates", + arraysEqual(eligibleStudents2(deltaStudentGroup), ["amy"]) +) + +test("eligibleStudents2 function with no candidates", + arraysEqual(eligibleStudents2([]), []) +) From 79053325565dcde74256aae214bd4cd318202868 Mon Sep 17 00:00:00 2001 From: Ashaghel <43817672+Ashaghel@users.noreply.github.com> Date: Sat, 2 May 2020 13:39:53 +0100 Subject: [PATCH 13/55] added small note --- week-3/Homework/mandatory/2-bush-berries.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/week-3/Homework/mandatory/2-bush-berries.js b/week-3/Homework/mandatory/2-bush-berries.js index 1b73eafc2..ea5118004 100644 --- a/week-3/Homework/mandatory/2-bush-berries.js +++ b/week-3/Homework/mandatory/2-bush-berries.js @@ -10,7 +10,7 @@ Use the tests to confirm which message to return This exercise can be solved in a few different ways. One way might include the array methods - .some() and .every(). The .some() method tests to see if some of the values in an array + .some() and .every(). The .some() method tests to see if some of the values (at least 1) in an array match what you're looking for and returns true or false. .every() will only return true if all values match watch you're looking for. Let's first look at an example that will teach you how to use these methods. From 6c489f4225b8bde631adf702241ebd4c5a441261 Mon Sep 17 00:00:00 2001 From: Ashaghel <43817672+Ashaghel@users.noreply.github.com> Date: Sat, 2 May 2020 13:41:51 +0100 Subject: [PATCH 14/55] Added more instructions --- week-3/Homework/mandatory/3-space-colonies.js | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/week-3/Homework/mandatory/3-space-colonies.js b/week-3/Homework/mandatory/3-space-colonies.js index 85c1b820c..f9e7ba636 100644 --- a/week-3/Homework/mandatory/3-space-colonies.js +++ b/week-3/Homework/mandatory/3-space-colonies.js @@ -6,6 +6,11 @@ Create a function that returns an array of colonisers that will stay, according to the above rules. NOTE: don't include any element that is not a "family". + Hint: whenever you read the above the instructions, try to come up with the main input and output and logic + Input is an array + Output is an array + logic only strings that start with A, and finish with family + */ function colonisers() {} From ce4cdb03de2dd0b1d376e5cf10c19f0fc51f30ec Mon Sep 17 00:00:00 2001 From: Ashaghel <43817672+Ashaghel@users.noreply.github.com> Date: Sat, 2 May 2020 13:46:36 +0100 Subject: [PATCH 15/55] changed function name to follow previously sent common practice and instructions fixed some typos --- .../Homework/mandatory/4-eligible-students.js | 24 +++++++++---------- 1 file changed, 12 insertions(+), 12 deletions(-) diff --git a/week-3/Homework/mandatory/4-eligible-students.js b/week-3/Homework/mandatory/4-eligible-students.js index 45fb86a8b..f1ea07a3c 100644 --- a/week-3/Homework/mandatory/4-eligible-students.js +++ b/week-3/Homework/mandatory/4-eligible-students.js @@ -7,8 +7,8 @@ Only students who have attended enough classes are eligible to join the research teams. - Implement the body of function called "eligibleStudents" which: - - Accepts an array which contains all the students' names and their attendance counts. + Implement the body of function called "getEligibleStudents" which: + - Accepts an array which contains all the students' names and their attendance counts For example: [ ["Hunor", 10], @@ -21,7 +21,7 @@ - Returns an array containing only the names of the who have attended AT LEAST 8 classes */ -function eligibleStudents(candidates) { +function getEligibleStudents(candidates) { // You have to implement this function body } @@ -29,9 +29,9 @@ function eligibleStudents(candidates) { Later leaders of Alpha planet decided to change the rule as below: - Only students whose name starts with the same letter than the name of the planer are eligible to join. + Only students whose name starts with the same letter of the name of the planet are eligible to join. - Implement the body of function called "eligibleStudents2" which: + Implement the body of function called "getEligibleStudents2" which: - Accepts an array in the same structure as before. - Returns an array containing only the names that satisfies the new rule. @@ -39,7 +39,7 @@ function eligibleStudents(candidates) { Unfortunately, administrators messed up the letter casing of names, sometimes it starts with small letter. */ -function eligibleStudents2(candidates) { +function getEligibleStudents2(candidates) { // You have to implement this function body } @@ -87,25 +87,25 @@ function test(test_name, expr) { } test("eligibleStudents function works", - arraysEqual(eligibleStudents(alphaStudentGroup), ["Ahmed", "Clement", "Tayoa", "Nina", "Bob"]) + arraysEqual(getEligibleStudents(alphaStudentGroup), ["Ahmed", "Clement", "Tayoa", "Nina", "Bob"]) ) test("eligibleStudents function without eligible candidates", - arraysEqual(eligibleStudents(deltaStudentGroup), []) + arraysEqual(getEligibleStudents(deltaStudentGroup), []) ) test("eligibleStudents function with no candidates", - arraysEqual(eligibleStudents([]), []) + arraysEqual(getEligibleStudents([]), []) ) test("eligibleStudents2 function works", - arraysEqual(eligibleStudents2(alphaStudentGroup), ["Ahmed", "Adam"]) + arraysEqual(getEligibleStudents2(alphaStudentGroup), ["Ahmed", "Adam"]) ) test("eligibleStudents2 function without eligible candidates", - arraysEqual(eligibleStudents2(deltaStudentGroup), ["amy"]) + arraysEqual(getEligibleStudents2(deltaStudentGroup), ["amy"]) ) test("eligibleStudents2 function with no candidates", - arraysEqual(eligibleStudents2([]), []) + arraysEqual(getEligibleStudents2([]), []) ) From 46747c0078bfb1003595345abe68b4aaad7adf62 Mon Sep 17 00:00:00 2001 From: Ashaghel <43817672+Ashaghel@users.noreply.github.com> Date: Sat, 2 May 2020 13:49:04 +0100 Subject: [PATCH 16/55] Update 6-lane-names.js --- week-3/Homework/mandatory/6-lane-names.js | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/week-3/Homework/mandatory/6-lane-names.js b/week-3/Homework/mandatory/6-lane-names.js index eddfe44fe..caf88c4ca 100644 --- a/week-3/Homework/mandatory/6-lane-names.js +++ b/week-3/Homework/mandatory/6-lane-names.js @@ -2,8 +2,9 @@ You are given a list of some London street names. Write a function that will return all street names which contain 'Lane' in their name. + */ - +//hint: string and array methods that could be helpful (indexOf, filter) function getLanes() { } @@ -43,4 +44,4 @@ function test(test_name, expr) { test("getLanes function works", arraysEqual(getLanes(streetNames), ["Abchurch Lane", "Addle Lane"]) -) \ No newline at end of file +) From 14221335920a4d5ae793d66dfc7624c21772f6fb Mon Sep 17 00:00:00 2001 From: Ashaghel <43817672+Ashaghel@users.noreply.github.com> Date: Sat, 2 May 2020 13:50:30 +0100 Subject: [PATCH 17/55] formating --- week-3/Homework/mandatory/7-codewars.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/week-3/Homework/mandatory/7-codewars.md b/week-3/Homework/mandatory/7-codewars.md index 3820c0637..b68254e9a 100644 --- a/week-3/Homework/mandatory/7-codewars.md +++ b/week-3/Homework/mandatory/7-codewars.md @@ -6,7 +6,7 @@ Today, you'll be using a platform called [CodeWars](https://codewars.com) to hel 2. Signup to [CodeWars](https://codewars.com) and work on these challenges: -3. You need to finish a minimum of 3 Exercises from [functions part](Section_1) and a minimum of 3 Exercises from [Arrays part](Section_2) +3. You need to finish a minimum of **3 Exercises from [functions part](Section_1)** and a minimum of **3 Exercises from [Arrays part](Section_2)** (Section*1) \_Functions, types, conditionals etc...* From 4feab6b7f79b6d19743a62ab0c179cebf48d3208 Mon Sep 17 00:00:00 2001 From: Zoltan Gal Date: Sat, 2 May 2020 15:57:07 +0200 Subject: [PATCH 18/55] Add more details and restructure journey planner exercise --- .../Homework/mandatory/5-journey-planner.js | 155 +++++++++++++++--- 1 file changed, 135 insertions(+), 20 deletions(-) diff --git a/week-3/Homework/mandatory/5-journey-planner.js b/week-3/Homework/mandatory/5-journey-planner.js index f4073976d..e26e379f9 100644 --- a/week-3/Homework/mandatory/5-journey-planner.js +++ b/week-3/Homework/mandatory/5-journey-planner.js @@ -1,17 +1,23 @@ /* -Before we go the big story; we will introduce more string methods. Some of the methods you're using in Array have similar ones with strings -Methods like : IndexOf, Include, Search, Slice , Spilt and more. You can always google how a method of a string work -Here is links for some of them -https://www.w3schools.com/js/js_string_methods.asp -https://javascript.info/string#quotes - - -Now let's do this small exercise -Using string methods update the checkCodeIsThere() function -- The function will have a string as a paramter --The function should check if the string has the word "code" exists in the string -- If it does exist, return the index of it, if not return not found -Hint: search string methods like Includes,and IndexOf + Before we go the big story; we will introduce more string methods. + Some of the methods you're using in Array have similar ones with strings. + + Methods like : IndexOf, Include, Search, Slice , Spilt and more. + + You can always google how a method of a string works! + Here are links to some of those: + - https://www.w3schools.com/js/js_string_methods.asp + - https://javascript.info/string#quotes + + + Now let's do this small exercise + + Using string methods update the checkCodeIsThere() function + - The function will have a string as a paramter + - The function should check if the string has the word "code" exists in the string + - If it does exist, return the index of it, if not return "Not found" + + Hint: search for string methods like Includes and IndexOf. */ function checkCodeIsThere(stringText) { @@ -26,17 +32,94 @@ function checkCodeIsThere(stringText) { /* I am new to London and would like to know what transport I can take to different famous locations. - An array with London locations have been provided. + The input provided contains a list of locations in London. Each of locations is followed by a list + of transport modes that can be used to get there. + + Let's an example how your input will look. To take to Tower Bridge, you can use tube or river boat. + + This information will represented as + ["Tower Bridge", "tube", "river boat"] - Return an array of where I can go if I only want to use a specific mode of transport. + Where + the 1st element says the name of the location, + and rest of them says the transport modes. - NOTE: only the names should be returned, not the means of transport. + You will then get a list of these information, e.g: + [ + ["Tower Bridge", "tube", "river boat"], + ["Abbey road", "double decker"], + ["London Eye", "tube", "river boat", "bus"] + ] + + Finish up the body of journeyPlanner function that should tell where I can go if I only want to use a specific mode of transport. + + Before jumping straight to the journeyPlanner, we will break down the whole task into smaller steps that make our job easier. + + (This technic is also referred as problem decomposition. It helps you to reduce scope of the problem + by only focusing on a small chunk of the whole problem at a time.) */ -//Hint some string methods needed as well as array methods -//search slice and includes for string -// and filter and map for array -function journeyPlanner() {} +/* + Implement the function getTransportModes that + - Should accepts an array containing the location and available transport modes + e.g: ["Tower Bridge", "tube", "river boat"] + - Returns an array including the available transport modes to the given location + e.g: ["tube", "river boat"] + + Hint: Use the corresponding array method to split the array. +*/ +function getTransportModes() { } + +/* + Implement the function isAccessibleByTransportMode that + - Should accept two parameters: + 1) First parameter is an array of transport modes + e.g: ["tube", "river boat"] + 2) Second parameter is a string containing a transport mode + e.g: "river boat" + + - Returns + * True if the location in the first parameter is accessible by the transport mode given in second parameter + * Otherwise, returns false + + Hint: Use the corresponding array method to decide if an element is member of an array. +*/ +function isAccessibleByTransportMode() { } + +/* + Implement the function getLocationName that + - Should accepts a location and available transports in an array + e.g:["Tower Bridge", "tube", "river boat"] + - Returns the name of the location + e.g: "Tower Bridge" +*/ +function getLocationName() { } + +/* + We arrived at the final method. it won't take long if you use the previously implemented functions wisely. + + Finish up the implemention of the function journeyPlanner that + - Accepts two parameters: + 1) An array with a list of locations + e.g: + [ + ["Angel", "tube", "bus"], + ["London Bridge", "tube", "river boat"], + ] + 2) A string containing a transport mode + + - Returns an array of where I can go if I only want to use a specific mode of transport. + NOTE: only the names should be returned, not the name of transports. + + Hint: + - Use the function you implemented above. + - Use array method to remove locations that is not accessible by the given transportMode. + - Use array method to manipulate its elements. + +*/ +function journeyPlanner(locations, transportMode) { + // Implement the function body +} /* ======= TESTS - DO NOT MODIFY ===== */ @@ -87,6 +170,38 @@ test( "checkCodeIsThere function works - case 3", checkCodeIsThere(string3) === 20 ); + +test( + "getTransportModes function works", + arraysEqual(getTransportModes(["Angel", "tube", "bus"]), ["tube", "bus"]) +); + +test( + "isAccessibleByTransportMode function works - positive case 1", + arraysEqual(isAccessibleByTransportMode(["tube", "bus"], "tube"), true) +); + +test( + "isAccessibleByTransportMode function works - negative case 1", + arraysEqual(isAccessibleByTransportMode(["tube", "bus"], "river boat"), false) +); + +test( + "isAccessibleByTransportMode function works - negative case 2", + arraysEqual(isAccessibleByTransportMode(["tube", "bus", "river boat"], "boat"), false) +); + +test( + "getLocationName function works - case 1", + arraysEqual(getLocationName(["London Bridge", "tube", "river boat"]), "London Bridge") +); + +test( + "getLocationName function works - case 2", + arraysEqual(getLocationName(["Angel", "tube", "bus"]), "Angel") +); + + test( "journeyPlanner function works - case 1", arraysEqual(journeyPlanner(londonLocations, "river boat"), [ From 349fee57c3f5ca0f5856edab4f2076434feac41b Mon Sep 17 00:00:00 2001 From: Zoltan Gal Date: Sat, 2 May 2020 16:12:26 +0200 Subject: [PATCH 19/55] Reformatting journey planner description --- week-3/Homework/mandatory/5-journey-planner.js | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/week-3/Homework/mandatory/5-journey-planner.js b/week-3/Homework/mandatory/5-journey-planner.js index e26e379f9..046ab70d6 100644 --- a/week-3/Homework/mandatory/5-journey-planner.js +++ b/week-3/Homework/mandatory/5-journey-planner.js @@ -51,12 +51,12 @@ function checkCodeIsThere(stringText) { ["London Eye", "tube", "river boat", "bus"] ] - Finish up the body of journeyPlanner function that should tell where I can go if I only want to use a specific mode of transport. + You have to finish up the body of journeyPlanner function that should tell where I can go if I only + want to use a specific mode of transport. But before jumping straight to the main function, we will + break down the whole task into smaller steps that make our job easier. - Before jumping straight to the journeyPlanner, we will break down the whole task into smaller steps that make our job easier. - - (This technic is also referred as problem decomposition. It helps you to reduce scope of the problem - by only focusing on a small chunk of the whole problem at a time.) + This technic is also referred as problem decomposition. It helps you to reduce scope of the problem + by only focusing on a small chunk of the whole problem at a time.) */ /* From fe6726a4e30ba827c059363873eb3bbdf2f570d3 Mon Sep 17 00:00:00 2001 From: Zoltan Gal Date: Sat, 2 May 2020 16:16:00 +0200 Subject: [PATCH 20/55] Add extra challange tip to journey planner --- week-3/Homework/mandatory/5-journey-planner.js | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/week-3/Homework/mandatory/5-journey-planner.js b/week-3/Homework/mandatory/5-journey-planner.js index 046ab70d6..266ba4194 100644 --- a/week-3/Homework/mandatory/5-journey-planner.js +++ b/week-3/Homework/mandatory/5-journey-planner.js @@ -115,7 +115,8 @@ function getLocationName() { } - Use the function you implemented above. - Use array method to remove locations that is not accessible by the given transportMode. - Use array method to manipulate its elements. - + + Advanced challange: try to use arrow function when invoking an array method. */ function journeyPlanner(locations, transportMode) { // Implement the function body From 9678006689e84373e8d3d87b140f68d5fbd226d4 Mon Sep 17 00:00:00 2001 From: Zoltan Gal Date: Sat, 2 May 2020 17:50:56 +0200 Subject: [PATCH 21/55] Add examples and tweak descriptions --- .../Homework/mandatory/4-eligible-students.js | 30 ++++++++++++++----- .../Homework/mandatory/5-journey-planner.js | 13 ++++---- 2 files changed, 30 insertions(+), 13 deletions(-) diff --git a/week-3/Homework/mandatory/4-eligible-students.js b/week-3/Homework/mandatory/4-eligible-students.js index f1ea07a3c..13fcd0e7b 100644 --- a/week-3/Homework/mandatory/4-eligible-students.js +++ b/week-3/Homework/mandatory/4-eligible-students.js @@ -1,5 +1,5 @@ /* - Colonisers would like to bring some researchers to the planet to scrunise the surface. + Colonisers would like to bring some researchers to the planet to scrutinise the surface. They also need pupils who would act as assistants. Unfortunately, the number of seats is limited on the spaceship therefore they set the following algorithm @@ -7,7 +7,7 @@ Only students who have attended enough classes are eligible to join the research teams. - Implement the body of function called "getEligibleStudents" which: + Finish the "getEligibleStudents" function which: - Accepts an array which contains all the students' names and their attendance counts For example: [ @@ -15,14 +15,29 @@ ["Magor", 1] ] See that each student's information is stored separately as an embedded array. - This is also called as 2 dimensional array when you can find array inside of array. - Returns an array containing only the names of the who have attended AT LEAST 8 classes + */ -function getEligibleStudents(candidates) { - // You have to implement this function body +// Remember how to access to embedded arrays +let twoDimensionalArray = [ + ["cat", "dog"], + ["giraffe", "lion", "elephant"] +]; + +let pets = twoDimensionalArray[0]; // this reads the first embedded array +console.log(pets[1]) // this prints "cat" to the console + +// you can also read straight the embedded array +console.log(twoDimensionalArray[1][2]); +// this reads the second embedded array and then reads its last element and finally prints "elephant" to the console + +/* + + + + + + + */ +/* Now try the exercise */ + +function getEligibleStudents() { } /* @@ -37,10 +52,11 @@ function getEligibleStudents(candidates) { Note: Unfortunately, administrators messed up the letter casing of names, sometimes it starts with small letter. + + Hint: To complete the function, search how to change text to lower or upper case by using string method. */ -function getEligibleStudents2(candidates) { - // You have to implement this function body +function getEligibleStudents2() { } /* ======= TESTS - DO NOT MODIFY ===== */ diff --git a/week-3/Homework/mandatory/5-journey-planner.js b/week-3/Homework/mandatory/5-journey-planner.js index 266ba4194..c716f2192 100644 --- a/week-3/Homework/mandatory/5-journey-planner.js +++ b/week-3/Homework/mandatory/5-journey-planner.js @@ -61,7 +61,7 @@ function checkCodeIsThere(stringText) { /* Implement the function getTransportModes that - - Should accepts an array containing the location and available transport modes + - Accepts an array containing the location and available transport modes e.g: ["Tower Bridge", "tube", "river boat"] - Returns an array including the available transport modes to the given location e.g: ["tube", "river boat"] @@ -72,7 +72,7 @@ function getTransportModes() { } /* Implement the function isAccessibleByTransportMode that - - Should accept two parameters: + - Accepts two parameters: 1) First parameter is an array of transport modes e.g: ["tube", "river boat"] 2) Second parameter is a string containing a transport mode @@ -88,7 +88,7 @@ function isAccessibleByTransportMode() { } /* Implement the function getLocationName that - - Should accepts a location and available transports in an array + - Accepts a location and available transports in an array e.g:["Tower Bridge", "tube", "river boat"] - Returns the name of the location e.g: "Tower Bridge" @@ -100,16 +100,17 @@ function getLocationName() { } Finish up the implemention of the function journeyPlanner that - Accepts two parameters: - 1) An array with a list of locations + 1) An array with a list of locations' and their transports e.g: [ ["Angel", "tube", "bus"], - ["London Bridge", "tube", "river boat"], + ["London Bridge", "tube", "river boat"] ] 2) A string containing a transport mode + e.g: "bus" - Returns an array of where I can go if I only want to use a specific mode of transport. - NOTE: only the names should be returned, not the name of transports. + NOTE: only the location names should be returned, not the name of transports. Hint: - Use the function you implemented above. From 222a34bb9b719a755e4837445ab4ed995fe9b494 Mon Sep 17 00:00:00 2001 From: Zoltan Gal Date: Sat, 2 May 2020 18:02:58 +0200 Subject: [PATCH 22/55] tweak week-3 intro description --- week-3/Homework/mandatory/0- Introduction.md | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/week-3/Homework/mandatory/0- Introduction.md b/week-3/Homework/mandatory/0- Introduction.md index bea3c9449..89c260200 100644 --- a/week-3/Homework/mandatory/0- Introduction.md +++ b/week-3/Homework/mandatory/0- Introduction.md @@ -2,9 +2,10 @@ You should complete all of these FreeCodeCamp exercises - https://www.freecodecamp.org/learn -> >>Go to JavaScript Algorithms and Data Structures Certification (300 hours) -> >>Then oepn Basic Data Structures -> >>Do the following exercises +> Go to **JavaScript Algorithms and Data Structures Certification (300 hours)** \ +> Then open **Basic Data Structures** + +Do the following exercises - Introduction to the Basic Data Structure Challenges - Use an Array to Store a Collection of Data From ccc11b51354c2bf6fb8e7b5722383842b088bedc Mon Sep 17 00:00:00 2001 From: Zoltan Gal Date: Sat, 2 May 2020 18:07:11 +0200 Subject: [PATCH 23/55] tweak week-3 intro description --- week-3/Homework/mandatory/0- Introduction.md | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/week-3/Homework/mandatory/0- Introduction.md b/week-3/Homework/mandatory/0- Introduction.md index 89c260200..52a8ca0ee 100644 --- a/week-3/Homework/mandatory/0- Introduction.md +++ b/week-3/Homework/mandatory/0- Introduction.md @@ -2,10 +2,9 @@ You should complete all of these FreeCodeCamp exercises - https://www.freecodecamp.org/learn -> Go to **JavaScript Algorithms and Data Structures Certification (300 hours)** \ -> Then open **Basic Data Structures** +Go to **JavaScript Algorithms and Data Structures Certification (300 hours)** -Do the following exercises +Open section **Basic Data Structures** and do the following exercises - Introduction to the Basic Data Structure Challenges - Use an Array to Store a Collection of Data @@ -21,7 +20,7 @@ Do the following exercises - Iterate Through All an Array's Items Using For Loops - Create complex multi-dimensional arrays -and you should attempt all of these +Then open **Basic Algorithm Scripting** and attempt all of these - Convert Celsius to Fahrenheit - Reverse a String From 7a91d2e800bea2291520858efeaf0fa590072a83 Mon Sep 17 00:00:00 2001 From: Zoltan Gal Date: Sat, 2 May 2020 18:32:42 +0200 Subject: [PATCH 24/55] fix text --- week-3/Homework/mandatory/5-journey-planner.js | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/week-3/Homework/mandatory/5-journey-planner.js b/week-3/Homework/mandatory/5-journey-planner.js index c716f2192..0ac48b8cd 100644 --- a/week-3/Homework/mandatory/5-journey-planner.js +++ b/week-3/Homework/mandatory/5-journey-planner.js @@ -35,9 +35,9 @@ function checkCodeIsThere(stringText) { The input provided contains a list of locations in London. Each of locations is followed by a list of transport modes that can be used to get there. - Let's an example how your input will look. To take to Tower Bridge, you can use tube or river boat. - - This information will represented as + Let's see an example: + + To take to Tower Bridge, you can use tube or river boat. This information will represented as ["Tower Bridge", "tube", "river boat"] Where From 1a7abaff7e47823ecdcb1d0cdeb3f85a1a144d5a Mon Sep 17 00:00:00 2001 From: Zoltan Gal Date: Sat, 2 May 2020 19:09:01 +0200 Subject: [PATCH 25/55] Improve examples in ex4 --- .../Homework/mandatory/4-eligible-students.js | 22 ++++++++++++++++--- 1 file changed, 19 insertions(+), 3 deletions(-) diff --git a/week-3/Homework/mandatory/4-eligible-students.js b/week-3/Homework/mandatory/4-eligible-students.js index 13fcd0e7b..e72ddedb1 100644 --- a/week-3/Homework/mandatory/4-eligible-students.js +++ b/week-3/Homework/mandatory/4-eligible-students.js @@ -19,20 +19,36 @@ - Returns an array containing only the names of the who have attended AT LEAST 8 classes + */ // Remember how to access to embedded arrays + let twoDimensionalArray = [ ["cat", "dog"], ["giraffe", "lion", "elephant"] ]; +// Examples accessing to array element directly +// Example 1 let pets = twoDimensionalArray[0]; // this reads the first embedded array -console.log(pets[1]) // this prints "cat" to the console +console.log(pets[1]); // this prints "cat" to the console -// you can also read straight the embedded array +// Example 2 +// You can also read straight the element of an embedded array: console.log(twoDimensionalArray[1][2]); -// this reads the second embedded array and then reads its last element and finally prints "elephant" to the console +// This reads the second embedded array and then reads its last element and finally prints "elephant" to the console + +// Examples accessing to array element through array methods +// Example 1 +let moreThanTwoArrays = twoDimensionalArray.filter(embeddedArray => embeddedArray.length > 2); +console.log(moreThanTwoArrays); +// This filter only keeps embededd arrays that have more than 3 elements + +// Example 2 +let arrayLengths = twoDimensionalArray.map(embeddedArray => embeddedArray.length); +console.log(arrayLengths); +// This gives back how many elements of each array have /* + + + + + + + */ /* Now try the exercise */ From f8f41b0369751c06c6020bf57d194e62f791cf66 Mon Sep 17 00:00:00 2001 From: Ashaghel <43817672+Ashaghel@users.noreply.github.com> Date: Sat, 16 May 2020 10:36:42 +0100 Subject: [PATCH 26/55] more info --- week-4/InClass/F-object-keys/exercise-part-2.js | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/week-4/InClass/F-object-keys/exercise-part-2.js b/week-4/InClass/F-object-keys/exercise-part-2.js index 6b6a1bb59..0c1571253 100644 --- a/week-4/InClass/F-object-keys/exercise-part-2.js +++ b/week-4/InClass/F-object-keys/exercise-part-2.js @@ -33,15 +33,15 @@ let storeBranches = { // ONLY EDIT BELOW THIS LINE -// # 1 +// # 1 get the names of the cities // prints [ 'glasgow', 'edinburgh' ] console.log() -// # 2 +// # 2 get the positions in Glasgow // prints [ 'manager', 'assistant', 'interns' ] console.log() -// # 3 +// # 3 get the positions for internt in Glasgow // prints [ 'head_intern', 'intern' ] console.log() From 68f6d7906e729d80b1f9dcbf0480c15251e32e4a Mon Sep 17 00:00:00 2001 From: Ashaghel <43817672+Ashaghel@users.noreply.github.com> Date: Sat, 16 May 2020 10:55:12 +0100 Subject: [PATCH 27/55] Create forinLoop.js --- week-4/InClass/forinLoop.js | 30 ++++++++++++++++++++++++++++++ 1 file changed, 30 insertions(+) create mode 100644 week-4/InClass/forinLoop.js diff --git a/week-4/InClass/forinLoop.js b/week-4/InClass/forinLoop.js new file mode 100644 index 000000000..1083c9e84 --- /dev/null +++ b/week-4/InClass/forinLoop.js @@ -0,0 +1,30 @@ +/* +The given object shows the population of largest cities in UK +You need to extract some information from it +The numbers are fake +*/ +var UKBigCitiesInMillions = { + Manchester: 2.5, + London: 12.5, + Birmingham: 1.8, + Glasgow: 2, + Newcastle: 1.5, + Cardiff: 0.9, + Swansea: 0.25, + Edinburgh: 0.7, +}; +//1- We discovered a small error in the calculations, we need to add 200 thousdands to each city under 1 million +//create a loop that write the names of the city over 1 million only to the console +// Example : "The city of x has a popluation of 1.5 million" +for (let city in UKBigCitiesInMillions) { +} + +//2-We need to know in which area each city is +//we looking for an output like "x is in Scotland and has population of y millions" + +var Scotland = ["Glasgow", "Edinburgh"]; +var England = ["Manchester", "Birmingham", "London", "Newcastle"]; +var Wales = ["Cardiff", "Swansea"]; + +for (let city in UKBigCitiesInMillions) { +} From 57dc8b0a70947378eaab56d31f2688abb5e91aae Mon Sep 17 00:00:00 2001 From: Zoltan Gal Date: Sat, 16 May 2020 11:56:21 +0200 Subject: [PATCH 28/55] Select freecodecamp resource list --- week-4/Homework/mandatory/1-freecodecamp.md | 19 ++++++------------- 1 file changed, 6 insertions(+), 13 deletions(-) diff --git a/week-4/Homework/mandatory/1-freecodecamp.md b/week-4/Homework/mandatory/1-freecodecamp.md index a05de7191..df2c86ae6 100644 --- a/week-4/Homework/mandatory/1-freecodecamp.md +++ b/week-4/Homework/mandatory/1-freecodecamp.md @@ -1,20 +1,13 @@ ## FreeCodeCamp Lessons -Complete all 26 of the 'Object Oriented Programming' lessons on FreeCodeCamp at https://www.freecodecamp.org/learn +You should complete all of these FreeCodeCamp exercises - https://www.freecodecamp.org/learn + +Go to **JavaScript Algorithms and Data Structures Certification (300 hours)** + +Open section **Object Oriented Programming** and do the following exercises - Introduction to the Object Oriented Programming Challenges - Create a Basic JavaScript Object - Use Dot Notation to Access the Properties of an Object - Create a Method on an Object -- Make Code More Reusable with the this Keyword -- Define a Constructor Function -- Use a Constructor to Create Objects -- Extend Constructors to Receive Arguments -- Verify an Object's Constructor with instanceof -- Understand Own Properties -- Use Prototype Properties to Reduce Duplicate Code -- Iterate Over All Properties -- Understand the Constructor Property -- Change the Prototype to a New Object -- Remember to Set the Constructor Property when Changing the Prototype -- Understand Where an Object’s Prototype Comes From +- Make Code More Reusable with the this Keyword \ No newline at end of file From 891b2aa8546745f76fac84fc03cd43450ce9c73b Mon Sep 17 00:00:00 2001 From: Zoltan Gal Date: Sat, 16 May 2020 11:56:56 +0200 Subject: [PATCH 29/55] Add extra exercise and description to writers exercise --- week-4/Homework/mandatory/2-writers.js | 39 ++++++++++++++++++++++---- 1 file changed, 33 insertions(+), 6 deletions(-) diff --git a/week-4/Homework/mandatory/2-writers.js b/week-4/Homework/mandatory/2-writers.js index 974a173aa..415ca52bc 100644 --- a/week-4/Homework/mandatory/2-writers.js +++ b/week-4/Homework/mandatory/2-writers.js @@ -1,13 +1,21 @@ -/* Challenge 1: Famous Writers -Did you know you can also have an array of objects? We've created one for you here. Loop through the array, -and for each object, `console.log()` out the sentence: +/* +Challenge 1: Famous Writers -"Hi, my name is {firstName} {lastName}. I am {age} years old, and work as a {occupation}." +Did you know you can also have an Array of Objects? You might think "This is madness!" but in everyday coding life +it is quite frequent combination. Just think about it what benefits we can get from this construct. -Here is the array: +Object lets you store multiple values in a single variable, then you can store complex objects in an array. +Let's assume you have list of data about people names and their birthday and you would like to print each name +with corresponding birthdays together. Storing these information in different arrays and then pairing them up +makes the iteration unnecessarily complicated, code will be less intuitive, needs extra cognitive effort to +reason about and last but not least it can be error-prone for example you pick up the wrong birthday to a name. +In this exercise you will practice how to access to Objects stored in Array and to their properties. +You already know different ways how to loop through Arrays, it won't be different in this case too. +The only extra is that you have to use values inside Objects. */ +// We've created an array of objects for you here: let writers = [ { firstName: "Virginia", @@ -40,5 +48,24 @@ let writers = [ ]; /* -If you want an extra challenge, only `console.log()` the writers that are alive. +Exercise 1: + Loop through the Array, and for each object, `console.log()` out the sentence and + insert corresponding values to the place holder that are indicated in courle braces: + "Hi, my name is {firstName} {lastName}. I am {age} years old, and work as a {occupation}." */ + + + +/* +Exercise 2: + Only `console.log()` the writers who are in their 40 with us anymore with the sentence: + "Writer {firstName} {lastName} died at {age} years old." +*/ + + + +/* +Exercise 3: + Only `console.log()` contemporary writers who are in their forties: + "Hi, my name is {firstName} {lastName}. I am {age} years old." +*/ \ No newline at end of file From e50722ef2de24563f3350fc688d6871b9491a23b Mon Sep 17 00:00:00 2001 From: Zoltan Gal Date: Sat, 16 May 2020 13:25:30 +0200 Subject: [PATCH 30/55] Add extra exercises to water bottle exercise --- week-4/Homework/mandatory/3-water-bottle.js | 145 +++++++++++++++++--- 1 file changed, 124 insertions(+), 21 deletions(-) diff --git a/week-4/Homework/mandatory/3-water-bottle.js b/week-4/Homework/mandatory/3-water-bottle.js index cb8041140..623bfc022 100644 --- a/week-4/Homework/mandatory/3-water-bottle.js +++ b/week-4/Homework/mandatory/3-water-bottle.js @@ -1,41 +1,144 @@ /* -Create an object that acts like a water bottle. -It will need a volume key to store how full or empty the bottle is. -It will be 100 when full and 0 when empty. -Give your water bottle methods for filling it up, -drinking some of it, and emptying it. +Create an object that acts a water bottle. -We made a start on this for you here: +It will need a volume property to store how full or empty the bottle is. +Volume will be 100 when bottle is full and 0 when empty. + +Give your water bottle methods for + - filling it up + - pouring 10 unit of water into it + Note: You cannot over exceed the bottle capacity. + - drinking 10 unit from it + Note: You cannot drink more than its actual content. + - and telling if the bottle is full + - and telling if the bottle is empty + +We made a start on this for you here by giving the sceleton of our object. +You have to implement the missing features according to the specification. */ +// Here is your starting point: let bottle = { volume: 0, - fill: function() { - // calling this function should make you bottles volume = 100; + fillUp: function() { + // calling this function should pour your bottle full (volume = 100); + }, + pour: function () { + // calling this function should increase your bottle volume by 10 unit; }, drink: function() { - // calling this function should decrease your bottles volume by 10; + // calling this function should decrease your bottle volume by 10 unit; }, - empty: function() { - // this function should return true if your bottles volume = 0 + isFull: function () { + // this function should return true if your bottle is empty; + }, + isEmpty: function() { + // this function should return true if your bottle is full; } }; /* ---TIP-- +TIP: + Remember that for changing properties on the current object inside one of its + methods you can refer to it by its variable name: `bottle` or using the keywords `this`. +*/ -Remember that for changing properties on the current object inside one of its -methods you can refer to it by its variable name: `bottle`. +/* +Extra question: + What do you think why it is preferred using `this` inside object over its variable name in our case `bottle`? -Once you have completed your object run the following and see if your answer -matches the expected result at the bottom :) + Leave your answer below: */ -bottle.fill(); +// HERE COMES YOUR ANSWER + +/* +Once you have completed your object run the following +and see if your answer matches the expected result at the bottom :) +*/ + +// ONYL READ AND DO NOT MODIFY BELOW + +// ACTIONS +bottle.fillUp(); + +// CHECKS +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.`); + +// ACTIONS +bottle.pour(); + +// CHECKS +if (bottle.volume > 100) console.log(`That's correct. Bottle is alread 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.`); + +// ACTIONS +bottle.drink(); +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}.`); + +// ACTIONS +bottle.drink(); +bottle.drink(); bottle.drink(); + +// CHECKS +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.`); + +// ACTIONS bottle.drink(); bottle.drink(); -if (!bottle.empty()) { - console.log(`bottles volume = ${bottle.volume}`); -} -console.log("Above volume should be: 70"); +bottle.drink(); +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.`); + +// ACTIONS +bottle.drink(); + +// CHECKS +if (bottle.volume === 0) console.log(`That's correct! Empty bottle valome is repesented as zero.`); +else console.warn(`Not quite right. Volume should be zero instead of ${bottle.volume}.`); + +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.`); + +// ACTIONS +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.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.`); + +// 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.`); From 02492c947ec606ba44d87f2d42e7a333497518ef Mon Sep 17 00:00:00 2001 From: Zoltan Gal Date: Sat, 16 May 2020 13:45:18 +0200 Subject: [PATCH 31/55] Remove extra resources recommendations that have not been taught yet --- week-4/Homework/extra/extra-homework.md | 5 +---- week-4/Homework/mandatory/5-codewars.md | 4 ---- 2 files changed, 1 insertion(+), 8 deletions(-) diff --git a/week-4/Homework/extra/extra-homework.md b/week-4/Homework/extra/extra-homework.md index 4aa5066a0..53f991b79 100644 --- a/week-4/Homework/extra/extra-homework.md +++ b/week-4/Homework/extra/extra-homework.md @@ -4,17 +4,14 @@ Complete the following CodeWars exercises. Go to the webpages below and follow t Click "ATTEMPT" to test your solution. -Exercises: +Exercise: - [Fix my Method](https://www.codewars.com/kata/558710234f02dcc4a8000005) -- [Regular Ball Super Ball](https://www.codewars.com/kata/53f0f358b9cb376eca001079/train/javascript) ## Reading 1.['You Don't Know JS: this & Object Prototypes' - Chapter 3, 'Objects'](https://github.com/getify/You-Dont-Know-JS/blob/1st-ed/this%20%26%20object%20prototypes/ch3.md) - 2. Eloquent JavaScript Chapter 4 - 'Data Structures: Objects and Arrays': https://eloquentjavascript.net/04_data.html -3. Eloquent JavaScript Chapter 6 - 'The Secret Life of Objects': https://eloquentjavascript.net/06_object.html ## Viewing diff --git a/week-4/Homework/mandatory/5-codewars.md b/week-4/Homework/mandatory/5-codewars.md index cc5c8e86b..4d9c78fa5 100644 --- a/week-4/Homework/mandatory/5-codewars.md +++ b/week-4/Homework/mandatory/5-codewars.md @@ -1,7 +1,3 @@ -## Reading - -- [Understanding JavaScript Constructors](https://css-tricks.com/understanding-javascript-constructors/) - ## CodeWars Exercises Complete the following CodeWars exercises. Go to the webpages below and follow the instructions there. From 1feffbead203990115c526131f77a82bee42baef Mon Sep 17 00:00:00 2001 From: Zoltan Gal Date: Sat, 16 May 2020 15:54:03 +0200 Subject: [PATCH 32/55] Rewrite grocery list exercise --- week-4/Homework/mandatory/4-groceries.js | 68 ++++++++++++++++++++---- 1 file changed, 59 insertions(+), 9 deletions(-) diff --git a/week-4/Homework/mandatory/4-groceries.js b/week-4/Homework/mandatory/4-groceries.js index 2b34cdb53..d21331527 100644 --- a/week-4/Homework/mandatory/4-groceries.js +++ b/week-4/Homework/mandatory/4-groceries.js @@ -1,12 +1,62 @@ -// You're going shopping, and you need a shopping list. -// 1. Update your groceryList with the items you need: Potatoes, Orange Juice and Rice. -// 2. Loop through the groceryList object to gather the item properties into the groceriesToBuy array. -// 3. Then use console.log() to print out the list. It should print ['Potatoes', 'Orange Juice', 'Rice'] +/* +As you you can have an Array of Objects, you can also store Arrays in Objects. +In this exercise, you'll practice: + - How to loop through the properties (keys) of an Object and read its values. + - How to access Array stored inside Object. + - How to access to a specific property of an array and set it. -let groceriesToBuy = []; +You're going shopping, and you need a shopping list. You've already created your weekly meal plan +that contains the missing ingredients to your menus. It is stored in the "weeklyMealPlan" object. -let groceryList = { - item1: "", - item2: "", - item3: "" +Complete the exercises below. +*/ + +// 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: [] }; + +/* +Exercise 1: + Loop through the weekly meal plan object to gather weakly ingredients into the weeklyGroceriesToBuy array. + Then use console.log() to print out the list. +*/ +// Gather all week item names into this array +let weeklyGroceriesToBuy = []; + + + +/* +Exercise 2: + Loop through your list again, but now only collect the weekend items into the weeklyGroceriesToBuy array. + Then use console.log() to print out the list. +*/ +// Gather weekend item names into this array +let weekendGroceriesToBuy = []; + + + +/* +Exercise 2: + Loop through your weekly meal plan: + - count how many ingredients you should buy per each day + - and update the corresponding properties of numberOfItemsPerWeak object. + + Finally use console.log() to print out the Object. +*/ +// Gather weekend item names into this array +let numberOfItemsPerWeak = { + monday: 0, + tuesday: 0, + wednesday: 0, + thursday: 0, + fridray: 0, + saturday: 0, + sunday: 0 +} From 4a1fa48eadae34c5b327f39e978194b7719f07b7 Mon Sep 17 00:00:00 2001 From: Zoltan Gal Date: Sat, 16 May 2020 19:20:08 +0200 Subject: [PATCH 33/55] Fix week-4 exercise issues --- week-4/Homework/mandatory/3-water-bottle.js | 10 +++++----- week-4/Homework/mandatory/4-groceries.js | 2 +- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/week-4/Homework/mandatory/3-water-bottle.js b/week-4/Homework/mandatory/3-water-bottle.js index 623bfc022..4ad72fdd9 100644 --- a/week-4/Homework/mandatory/3-water-bottle.js +++ b/week-4/Homework/mandatory/3-water-bottle.js @@ -73,7 +73,7 @@ else console.warn(`Not quite right! Bottle should not be empty but it is already bottle.pour(); // CHECKS -if (bottle.volume > 100) console.log(`That's correct. Bottle is alread full water volume cannot go beyond.`); +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.`); @@ -110,14 +110,14 @@ bottle.drink(); 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}.`); + // ACTIONS bottle.drink(); // CHECKS -if (bottle.volume === 0) console.log(`That's correct! Empty bottle valome is repesented as zero.`); -else console.warn(`Not quite right. Volume should be zero instead of ${bottle.volume}.`); - -if (bottle.volume < 0) console.log(`That's correct! Water volume cannot go below zero.`); +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.`); diff --git a/week-4/Homework/mandatory/4-groceries.js b/week-4/Homework/mandatory/4-groceries.js index d21331527..c70b3a0c7 100644 --- a/week-4/Homework/mandatory/4-groceries.js +++ b/week-4/Homework/mandatory/4-groceries.js @@ -59,4 +59,4 @@ let numberOfItemsPerWeak = { fridray: 0, saturday: 0, sunday: 0 -} +}; From a3c1d0c38d5e4f2f9f726403ea70f72c8aa86c41 Mon Sep 17 00:00:00 2001 From: Ashaghel <43817672+Ashaghel@users.noreply.github.com> Date: Sun, 17 May 2020 00:05:09 +0100 Subject: [PATCH 34/55] more reading --- week-4/Homework/mandatory/0-classwork.md | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/week-4/Homework/mandatory/0-classwork.md b/week-4/Homework/mandatory/0-classwork.md index 33d2658e9..5f063ece2 100644 --- a/week-4/Homework/mandatory/0-classwork.md +++ b/week-4/Homework/mandatory/0-classwork.md @@ -2,4 +2,15 @@ Firstly, complete any exercises you did not complete during class. They are essential practice for the rest of the homework tasks. -If you get stuck, reach out to your classmates on Slack for help! \ No newline at end of file +If you get stuck, reach out to your classmates on Slack for help! + +## Reading +Read the following article +https://javascript.info/object +and do the tasks in the end + +## helpful videos +1. [Methods and 'this' keyword in JavaScript](https://www.youtube.com/watch?v=0wN-L9CG3y0) +2. [Modern JavaScript Tutorial #5 - Objects](https://www.youtube.com/watch?v=X0ipw1k7ygU) +3. [More Object methods](https://youtu.be/kL9bC-e5UeE) +4. [Loops in JS recap](https://www.youtube.com/watch?v=Kn06785pkJg) From 393cab187d4f05632669b828717343deba412cca Mon Sep 17 00:00:00 2001 From: Ashaghel <43817672+Ashaghel@users.noreply.github.com> Date: Sun, 17 May 2020 00:06:51 +0100 Subject: [PATCH 35/55] Update 1-freecodecamp.md --- week-4/Homework/mandatory/1-freecodecamp.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/week-4/Homework/mandatory/1-freecodecamp.md b/week-4/Homework/mandatory/1-freecodecamp.md index df2c86ae6..51f667248 100644 --- a/week-4/Homework/mandatory/1-freecodecamp.md +++ b/week-4/Homework/mandatory/1-freecodecamp.md @@ -4,10 +4,10 @@ You should complete all of these FreeCodeCamp exercises - https://www.freecodeca Go to **JavaScript Algorithms and Data Structures Certification (300 hours)** -Open section **Object Oriented Programming** and do the following exercises +Open section **Object Oriented Programming** and do the following exercises (if you have not done already in the previous homework) - Introduction to the Object Oriented Programming Challenges - Create a Basic JavaScript Object - Use Dot Notation to Access the Properties of an Object - Create a Method on an Object -- Make Code More Reusable with the this Keyword \ No newline at end of file +- Make Code More Reusable with the this Keyword From 05218bcfa9ecc04bd965005dd30d29c57be8f9f5 Mon Sep 17 00:00:00 2001 From: Ashaghel <43817672+Ashaghel@users.noreply.github.com> Date: Sun, 17 May 2020 00:07:32 +0100 Subject: [PATCH 36/55] Update extra-homework.md --- week-4/Homework/extra/extra-homework.md | 4 ---- 1 file changed, 4 deletions(-) diff --git a/week-4/Homework/extra/extra-homework.md b/week-4/Homework/extra/extra-homework.md index 53f991b79..516534a30 100644 --- a/week-4/Homework/extra/extra-homework.md +++ b/week-4/Homework/extra/extra-homework.md @@ -13,7 +13,3 @@ Exercise: 1.['You Don't Know JS: this & Object Prototypes' - Chapter 3, 'Objects'](https://github.com/getify/You-Dont-Know-JS/blob/1st-ed/this%20%26%20object%20prototypes/ch3.md) 2. Eloquent JavaScript Chapter 4 - 'Data Structures: Objects and Arrays': https://eloquentjavascript.net/04_data.html -## Viewing - -1. [Methods and 'this' keyword in JavaScript](https://www.youtube.com/watch?v=0wN-L9CG3y0) -2. [Modern JavaScript Tutorial #5 - Objects](https://www.youtube.com/watch?v=X0ipw1k7ygU) From f836b8909cf71c0d8a307fd76e27ab3d12673249 Mon Sep 17 00:00:00 2001 From: Ashaghel <43817672+Ashaghel@users.noreply.github.com> Date: Sun, 17 May 2020 00:08:29 +0100 Subject: [PATCH 37/55] Update 1-freecodecamp.md --- week-4/Homework/mandatory/1-freecodecamp.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/week-4/Homework/mandatory/1-freecodecamp.md b/week-4/Homework/mandatory/1-freecodecamp.md index 51f667248..82548f8d6 100644 --- a/week-4/Homework/mandatory/1-freecodecamp.md +++ b/week-4/Homework/mandatory/1-freecodecamp.md @@ -4,7 +4,7 @@ You should complete all of these FreeCodeCamp exercises - https://www.freecodeca Go to **JavaScript Algorithms and Data Structures Certification (300 hours)** -Open section **Object Oriented Programming** and do the following exercises (if you have not done already in the previous homework) +Open section **Object Oriented Programming** and do the following exercises **(if you have not done already in the previous homework)** - Introduction to the Object Oriented Programming Challenges - Create a Basic JavaScript Object From 90f6f0b271eb71761be4f394a6239a0c094fe7b0 Mon Sep 17 00:00:00 2001 From: Ashaghel <43817672+Ashaghel@users.noreply.github.com> Date: Sun, 17 May 2020 00:14:33 +0100 Subject: [PATCH 38/55] Update 1-freecodecamp.md --- week-4/Homework/mandatory/1-freecodecamp.md | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/week-4/Homework/mandatory/1-freecodecamp.md b/week-4/Homework/mandatory/1-freecodecamp.md index 82548f8d6..707468cd9 100644 --- a/week-4/Homework/mandatory/1-freecodecamp.md +++ b/week-4/Homework/mandatory/1-freecodecamp.md @@ -4,6 +4,16 @@ You should complete all of these FreeCodeCamp exercises - https://www.freecodeca Go to **JavaScript Algorithms and Data Structures Certification (300 hours)** +## Scope in functions (important topic to learn about for later on) +- Basic JavaScript: Global Scope and Functions +- Basic JavaScript: Local Scope and Functions +- Basic JavaScript: Global vs. Local Scope in Functions + +Helpufl Video: + +[Scope in JS](https://www.youtube.com/watch?v=iJKkZA215tQ) + + Open section **Object Oriented Programming** and do the following exercises **(if you have not done already in the previous homework)** - Introduction to the Object Oriented Programming Challenges From a4055cad6e9c5662c1f21e3ae00fcaffc6e0e104 Mon Sep 17 00:00:00 2001 From: Ashaghel <43817672+Ashaghel@users.noreply.github.com> Date: Sun, 17 May 2020 00:15:06 +0100 Subject: [PATCH 39/55] Update 1-freecodecamp.md --- week-4/Homework/mandatory/1-freecodecamp.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/week-4/Homework/mandatory/1-freecodecamp.md b/week-4/Homework/mandatory/1-freecodecamp.md index 707468cd9..d95c80d21 100644 --- a/week-4/Homework/mandatory/1-freecodecamp.md +++ b/week-4/Homework/mandatory/1-freecodecamp.md @@ -4,14 +4,14 @@ You should complete all of these FreeCodeCamp exercises - https://www.freecodeca Go to **JavaScript Algorithms and Data Structures Certification (300 hours)** -## Scope in functions (important topic to learn about for later on) +## Scope in functions - Basic JavaScript: Global Scope and Functions - Basic JavaScript: Local Scope and Functions - Basic JavaScript: Global vs. Local Scope in Functions Helpufl Video: -[Scope in JS](https://www.youtube.com/watch?v=iJKkZA215tQ) +- [Scope in JS](https://www.youtube.com/watch?v=iJKkZA215tQ) Open section **Object Oriented Programming** and do the following exercises **(if you have not done already in the previous homework)** From e559c9a854134743a9c0374f77837d6ff6ec97f7 Mon Sep 17 00:00:00 2001 From: Ashaghel <43817672+Ashaghel@users.noreply.github.com> Date: Sun, 17 May 2020 00:17:36 +0100 Subject: [PATCH 40/55] Update 2-writers.js --- week-4/Homework/mandatory/2-writers.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/week-4/Homework/mandatory/2-writers.js b/week-4/Homework/mandatory/2-writers.js index 415ca52bc..4d4bfebaf 100644 --- a/week-4/Homework/mandatory/2-writers.js +++ b/week-4/Homework/mandatory/2-writers.js @@ -58,7 +58,7 @@ Exercise 1: /* Exercise 2: - Only `console.log()` the writers who are in their 40 with us anymore with the sentence: + Only `console.log()` the writers who are in their 40s with us anymore with the sentence:(meaning between 40 and 49) "Writer {firstName} {lastName} died at {age} years old." */ @@ -68,4 +68,4 @@ Exercise 2: Exercise 3: Only `console.log()` contemporary writers who are in their forties: "Hi, my name is {firstName} {lastName}. I am {age} years old." -*/ \ No newline at end of file +*/ From 9b87a3e0beb4e67a62464a8787f855d239ca18cf Mon Sep 17 00:00:00 2001 From: Zoltan Gal Date: Sun, 17 May 2020 22:45:43 +0200 Subject: [PATCH 41/55] fix description --- week-4/Homework/mandatory/2-writers.js | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/week-4/Homework/mandatory/2-writers.js b/week-4/Homework/mandatory/2-writers.js index 4d4bfebaf..ad7a685dd 100644 --- a/week-4/Homework/mandatory/2-writers.js +++ b/week-4/Homework/mandatory/2-writers.js @@ -58,7 +58,8 @@ Exercise 1: /* Exercise 2: - Only `console.log()` the writers who are in their 40s with us anymore with the sentence:(meaning between 40 and 49) + Only `console.log()` out the writers who are in their 40s (meaning between 40 and 49) + and not with us anymore using the below sentence format: "Writer {firstName} {lastName} died at {age} years old." */ @@ -66,6 +67,6 @@ Exercise 2: /* Exercise 3: - Only `console.log()` contemporary writers who are in their forties: + Only `console.log()` out contemporary (meaning still alive) writers who are in their forties: "Hi, my name is {firstName} {lastName}. I am {age} years old." */ From 793cd9632e3eb0a1b045b528febff11244f35b6d Mon Sep 17 00:00:00 2001 From: Zoltan Gal Date: Sun, 17 May 2020 22:46:54 +0200 Subject: [PATCH 42/55] tweak description --- week-4/Homework/mandatory/2-writers.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/week-4/Homework/mandatory/2-writers.js b/week-4/Homework/mandatory/2-writers.js index ad7a685dd..399e0257a 100644 --- a/week-4/Homework/mandatory/2-writers.js +++ b/week-4/Homework/mandatory/2-writers.js @@ -49,7 +49,7 @@ let writers = [ /* Exercise 1: - Loop through the Array, and for each object, `console.log()` out the sentence and + Loop through the Array, and for each object, `console.log()` out the below sentence and insert corresponding values to the place holder that are indicated in courle braces: "Hi, my name is {firstName} {lastName}. I am {age} years old, and work as a {occupation}." */ @@ -59,7 +59,7 @@ Exercise 1: /* Exercise 2: Only `console.log()` out the writers who are in their 40s (meaning between 40 and 49) - and not with us anymore using the below sentence format: + and not with us anymore, use the below sentence format: "Writer {firstName} {lastName} died at {age} years old." */ From 1d25f8e4e8ddddac388051f257198517ef69b0da Mon Sep 17 00:00:00 2001 From: Alin Chindea Date: Tue, 19 May 2020 09:04:53 +0100 Subject: [PATCH 43/55] Update 2-writers.js Minor changes to make language consistent and simplify it where needed. --- week-4/Homework/mandatory/2-writers.js | 26 +++++++++++++------------- 1 file changed, 13 insertions(+), 13 deletions(-) diff --git a/week-4/Homework/mandatory/2-writers.js b/week-4/Homework/mandatory/2-writers.js index 399e0257a..b1f5d006c 100644 --- a/week-4/Homework/mandatory/2-writers.js +++ b/week-4/Homework/mandatory/2-writers.js @@ -2,17 +2,17 @@ Challenge 1: Famous Writers Did you know you can also have an Array of Objects? You might think "This is madness!" but in everyday coding life -it is quite frequent combination. Just think about it what benefits we can get from this construct. +it is quite a frequent combination. Just think about what benefits we can get from this construct. -Object lets you store multiple values in a single variable, then you can store complex objects in an array. -Let's assume you have list of data about people names and their birthday and you would like to print each name -with corresponding birthdays together. Storing these information in different arrays and then pairing them up +An object lets you store multiple values in a single variable, then you can store complex objects in an array. +Let's assume you have a list of data about people names and their birthday and you would like to print each name +with corresponding birthday together. Storing these pieces of information in different arrays and then pairing them up makes the iteration unnecessarily complicated, code will be less intuitive, needs extra cognitive effort to -reason about and last but not least it can be error-prone for example you pick up the wrong birthday to a name. +reason about and last but not least it can be error-prone (for example, you pick up the wrong birthday to a name). -In this exercise you will practice how to access to Objects stored in Array and to their properties. -You already know different ways how to loop through Arrays, it won't be different in this case too. -The only extra is that you have to use values inside Objects. +In this exercise you will practice how to access to Objects stored in an Array and their properties. You already know +different ways of looping through Arrays, it won't be different in this case. The only extra step is that you have to +use values inside Objects. */ // We've created an array of objects for you here: @@ -39,8 +39,8 @@ let writers = [ alive: false }, { - firstName: "bell", - lastName: "hooks", + firstName: "Bell", + lastName: "Hooks", occupation: "writer", age: 64, alive: true @@ -50,7 +50,7 @@ let writers = [ /* Exercise 1: Loop through the Array, and for each object, `console.log()` out the below sentence and - insert corresponding values to the place holder that are indicated in courle braces: + 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}." */ @@ -59,7 +59,7 @@ Exercise 1: /* Exercise 2: Only `console.log()` out the writers who are in their 40s (meaning between 40 and 49) - and not with us anymore, use the below sentence format: + and not alive anymore. Use the below sentence format: "Writer {firstName} {lastName} died at {age} years old." */ @@ -67,6 +67,6 @@ Exercise 2: /* Exercise 3: - Only `console.log()` out contemporary (meaning still alive) writers who are in their forties: + 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." */ From 55efde10249afba5af5c1b1c2e12bc1e44512ab6 Mon Sep 17 00:00:00 2001 From: Zoltan Gal Date: Wed, 20 May 2020 22:43:45 +0200 Subject: [PATCH 44/55] fix wording --- week-4/Homework/mandatory/4-groceries.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/week-4/Homework/mandatory/4-groceries.js b/week-4/Homework/mandatory/4-groceries.js index c70b3a0c7..09a69fee3 100644 --- a/week-4/Homework/mandatory/4-groceries.js +++ b/week-4/Homework/mandatory/4-groceries.js @@ -50,7 +50,7 @@ Exercise 2: Finally use console.log() to print out the Object. */ -// Gather weekend item names into this array +// Gather weekend item names into this object let numberOfItemsPerWeak = { monday: 0, tuesday: 0, From 27ce36210d474468315d05917e13b07487146d48 Mon Sep 17 00:00:00 2001 From: Zoltan Gal Date: Fri, 29 May 2020 22:36:01 +0200 Subject: [PATCH 45/55] Rewrite week-5/2-exercises --- .../mandatory/2-exercises/exercises.js | 108 ++++++++++-------- 1 file changed, 61 insertions(+), 47 deletions(-) diff --git a/week-5/Homework/mandatory/2-exercises/exercises.js b/week-5/Homework/mandatory/2-exercises/exercises.js index 174c5db04..c7f272042 100644 --- a/week-5/Homework/mandatory/2-exercises/exercises.js +++ b/week-5/Homework/mandatory/2-exercises/exercises.js @@ -1,63 +1,77 @@ +/* + In this exercise you will deal with Objects stored in array and DOM manipulation with JavaScript. + From now, exercise descriptions don't provide detailed examples about input and output of functions. + You should be already able to read and understand the code in order to extract the necessary information + you need to implement functions' body. + */ + +/* + Optional question: + + Notice how this JavaScript file linked to the index.html file. + What do you think when this JavaScript file is being executed? + + When you finished this exercise try to move the script tag around the Div tag with the id "content", + refresh the page and observe what happens. (This should answer the question above.) + + What do you think why this changes shouldn't work? + */ +// LEAVE YOUR ANSWER HERE (THIS IS OPTIONAL) + + /** + * This function recieves a lists of people. Each object should contain the name and the occupation of a person. + * Look for usage of the function in the code and see what variable is passed into it as an argument. + * + * Create and insert the below HTML elements to the DOM for each of Objects in the Array as follows: + * 1. Add a

tag to the website containing the name of the person + * 2. Add a

tag to the website containing the job of the person * - * For each of the names in the array passed into this function - * - * - Add a

tag to the website containing the name of the person - * - Add a

tag to the website containing the job of the person - * - * All of your HTML should go inside the Div tag with the id "content". - * + * All of your HTML elements should go inside the Div tag with the id "content". + * + * An example "content" div should look like: *
- *

{Name Here}

- *

{Job Here}

- * ..... + *

Mario

+ *

Plumber

+ *

Luigi

+ *

Plumber

*
*/ -function exerciseOne(arrayOfPeople) { +function insertPeopleData(arrayOfPeople) { let content = document.querySelector("#content"); + //Write your code in here } /** * - * Create a list of shopping items. You should use an unordered list. - * - * All of your HTML should go inside the Div tag with the id "content". + * Create a list of shopping items using an unordered HTML list. + * The input of this function is a simple Array of Strings, look for the concrete example in the code. + * + * All of your HTML elements should go inside the Div tag with the id "content". * + * Hint for type of lists in HTML: https://www.w3schools.com/html/html_lists.asp */ -function exerciseTwo(shopping) { +function insertShoppingList(shoppingList) { //Write your code in here } /** - I'd like to display my three favorite books inside a nice webpage! - - const books = [ - { - title: "The Design of Everyday Things", - author: "Don Norman", - alreadyRead: false - }, - { - title: "The Most Human Human", - author: "Brian Christian", - alreadyRead: true - }, - { - title: "The Pragmatic Programmer", - author: "Andrew Hunt", - alreadyRead: true - } - ]; - - Iterate through the array of books. - - For each book, create a

element with the book title and author and append it to the page. - - Use a

    and
  • to display the books. - - Add an to each book that links to a URL of the book cover. - - Change the style of the book depending on whether you have read it (green) or not (red). - - The end result should look something like this: https://hyf-js2-week1-makeme-ex1-demo.herokuapp.com/ -**/ -function exerciseThree(books) { + * I'd like to display my three favorite books inside a nice webpage! + * + * Iterate through the array of books passed into this function and insert each book to page as follows: + * - Create a
      list and display each book details in
    • element. + * - For each book, create a

      element with the book title and author and append it to the page. + * - Add an after

      element to each book that links to a URL of the book cover. + * You should find an appropriate image to each book. + * - Change the style of the book depending on whether you have read it (green) or not (red).* + * + * Find in the code what properties a book object has in the array. + * + * All of your HTML elements should go inside the Div tag with the id "content". + * + * The end result should look something like this: https://hyf-js2-week1-makeme-ex1-demo.herokuapp.com/* + */ +function insertBooks(books) { //Write your code in here } @@ -77,11 +91,11 @@ let people = [ { name: "Boris", job: "Prime Minister" } ]; -exerciseOne(people); +insertPeopleData(people); let shopping = ["Milk", "Break", "Eggs", "A Dinosaur", "Cake", "Sugar", "Tea"]; -exerciseTwo(shopping); +insertShoppingList(shopping); const books = [ { @@ -101,4 +115,4 @@ const books = [ } ]; -exerciseThree(books); +insertBooks(books); From f555e277c769b7c2fe7783981b319dfa8b37e2dd Mon Sep 17 00:00:00 2001 From: Zoltan Gal Date: Fri, 29 May 2020 22:56:13 +0200 Subject: [PATCH 46/55] Rewrite week-5/3-project --- week-5/Homework/mandatory/1-study/study.md | 1 + week-5/Homework/mandatory/3-project/README.md | 17 +++++++++-------- 2 files changed, 10 insertions(+), 8 deletions(-) diff --git a/week-5/Homework/mandatory/1-study/study.md b/week-5/Homework/mandatory/1-study/study.md index 11acc1a13..3552ab87a 100644 --- a/week-5/Homework/mandatory/1-study/study.md +++ b/week-5/Homework/mandatory/1-study/study.md @@ -2,6 +2,7 @@ - [MDN - Introduction to the DOM](https://developer.mozilla.org/en-US/docs/Web/API/Document_Object_Model/Introduction) - [Eloquent JavaScript - The Document Object Model](https://eloquentjavascript.net/14_dom.html) +- [Window - Alert](https://developer.mozilla.org/en-US/docs/Web/API/Window/alert) # Watch diff --git a/week-5/Homework/mandatory/3-project/README.md b/week-5/Homework/mandatory/3-project/README.md index 5caa8a338..cfede8d7c 100644 --- a/week-5/Homework/mandatory/3-project/README.md +++ b/week-5/Homework/mandatory/3-project/README.md @@ -9,18 +9,18 @@ Clicking on the buttons should change the "theme" of the website: - When clicking **blue** it should change: - - **Jumbotron** background color to `#588fbd` + - Div tag with the id **Jumbotron** background color to `#588fbd` - **Donate a bike** button background color to `#ffa500` - **Volunteer** button background color to `black` and text color to `white` - When clicking **orange** it should change: - - **Jumbotron** background color to `#f0ad4e` + - Div tag with the id **Jumbotron** background color to `#f0ad4e` - **Donate a bike** button background color to `#5751fd` - **Volunteer** button background color to `#31b0d5` and text color to `white` - When clicking **green** it should change: - - **Jumbotron** background color to `#87ca8a` + - Div tag with the id **Jumbotron** background color to `#87ca8a` - **Donate a bike** button background color to `black` - **Volunteer** button background color to `#8c9c08` @@ -30,19 +30,20 @@ Here's an example of how the website should look for the blue button: ## Part 2 -Just below the buttons, there's a form called **Register with us**. +Just below the buttons, there's a form called **Register with us today**. Continue working in `./js/main.js` to add the following functionality: When the submit button is pressed, it should check that all the form fields are valid: -- The **Your name**, **Email** and **Describe yourself** fields need to be non-empty (Hint: their `value` length has to be greater than zero) -- For the **Email** field also check if it contains the `@` character +- The **Email address**, **Your name** and **Describe yourself** fields need to be non-empty (Hint: their `value` length has to be greater than zero) +- For the **Email Address** field also check if it contains the `@` character For all the fields that invalid, it should make their background color `red`. -IF all the fields are valid, when you click **Submit** it should: +If all the fields are valid, when you click **Submit** it should: -- Display an alert to thank you for filling out the form +- Display an alert to thank you for filling out the for. + Hint: (how to use alert)[https://www.w3schools.com/jsref/met_win_alert.asp] - Blank out (make empty) all the text fields **Important hint:** In your function that handles clicks on the `Submit` button you will need to call `event.preventDefault()` to stop the browser from refreshing the page. To read more on how to do this: https://developer.mozilla.org/en/docs/Web/API/Event/preventDefault From 6053f8ec647acaba2772ab25c436f9ccd645fa1e Mon Sep 17 00:00:00 2001 From: Zoltan Gal Date: Fri, 29 May 2020 22:58:30 +0200 Subject: [PATCH 47/55] tweak khanakademy hw descriptions --- week-5/Homework/extra/extra-homework.md | 2 +- week-5/Homework/mandatory/0-khanacademy/khanacademy.md | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/week-5/Homework/extra/extra-homework.md b/week-5/Homework/extra/extra-homework.md index ba6b6ddbc..e457abc93 100644 --- a/week-5/Homework/extra/extra-homework.md +++ b/week-5/Homework/extra/extra-homework.md @@ -1,6 +1,6 @@ # Complete this online course -You should complete the following sections from this tutorial: +You should complete the following sections from these tutorials on Khanacademy: - DOM animation - Using JS libraries in your webpage diff --git a/week-5/Homework/mandatory/0-khanacademy/khanacademy.md b/week-5/Homework/mandatory/0-khanacademy/khanacademy.md index 82aee9750..42d4b8537 100644 --- a/week-5/Homework/mandatory/0-khanacademy/khanacademy.md +++ b/week-5/Homework/mandatory/0-khanacademy/khanacademy.md @@ -1,6 +1,6 @@ # Complete this online course -You should complete the following sections from this online tutorial: +You should complete the following sections from these online tutorials on Khanacademy: - Get ready to make your webpages interactive - JS and the DOM From 37bc38e99900928f737feeb2787c0968a2830f62 Mon Sep 17 00:00:00 2001 From: Zoltan Gal Date: Sat, 30 May 2020 09:42:55 +0200 Subject: [PATCH 48/55] add extra description to week-5, exercise 3 --- week-5/Homework/mandatory/3-project/README.md | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/week-5/Homework/mandatory/3-project/README.md b/week-5/Homework/mandatory/3-project/README.md index cfede8d7c..ec3d47782 100644 --- a/week-5/Homework/mandatory/3-project/README.md +++ b/week-5/Homework/mandatory/3-project/README.md @@ -43,7 +43,10 @@ For all the fields that invalid, it should make their background color `red`. If all the fields are valid, when you click **Submit** it should: - Display an alert to thank you for filling out the for. - Hint: (how to use alert)[https://www.w3schools.com/jsref/met_win_alert.asp] - Blank out (make empty) all the text fields -**Important hint:** In your function that handles clicks on the `Submit` button you will need to call `event.preventDefault()` to stop the browser from refreshing the page. To read more on how to do this: https://developer.mozilla.org/en/docs/Web/API/Event/preventDefault +**Hints** +- [How to obtain values from form fields](https://www.khanacademy.org/computing/computer-programming/html-css-js/html-js-dom-events/pt/processing-forms-with-events) +- [How to use alert](https://www.w3schools.com/jsref/met_win_alert.asp) + +**Important hint:** In your function that handles clicks on the `Submit` button you will need to call `event.preventDefault()` to stop the browser from refreshing the page. To read more on how to do this: https://developer.mozilla.org/en/docs/Web/API/Event/preventDefault. Revisit the relevant part on [Kahnacademy](https://www.khanacademy.org/computing/computer-programming/html-css-js/html-js-dom-events/pt/preventing-default-behavior-of-events) for further practice. From 64096751228e34fc71fb96f312d2b2c2ef89cc07 Mon Sep 17 00:00:00 2001 From: Zoltan Gal Date: Mon, 1 Jun 2020 00:10:32 +0200 Subject: [PATCH 49/55] fix link --- week-5/Homework/mandatory/2-exercises/exercises.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/week-5/Homework/mandatory/2-exercises/exercises.js b/week-5/Homework/mandatory/2-exercises/exercises.js index c7f272042..cb8c0f42d 100644 --- a/week-5/Homework/mandatory/2-exercises/exercises.js +++ b/week-5/Homework/mandatory/2-exercises/exercises.js @@ -69,7 +69,7 @@ function insertShoppingList(shoppingList) { * * All of your HTML elements should go inside the Div tag with the id "content". * - * The end result should look something like this: https://hyf-js2-week1-makeme-ex1-demo.herokuapp.com/* + * The end result should look something like this: https://hyf-js2-week1-makeme-ex1-demo.herokuapp.com */ function insertBooks(books) { //Write your code in here From ff6e285cee898937440d96b3286cacf7f547dc09 Mon Sep 17 00:00:00 2001 From: Zoltan Gal Date: Sat, 6 Jun 2020 23:23:49 +0200 Subject: [PATCH 50/55] Update week-6 exercise description --- .../mandatory/1-alarmclock/alarmclock.js | 34 ++++++++++++++++++- .../mandatory/2-quotegenerator/quotes.js | 3 +- .../mandatory/2-quotegenerator/task.md | 8 ++--- 3 files changed, 38 insertions(+), 7 deletions(-) diff --git a/week-6/Homework/mandatory/1-alarmclock/alarmclock.js b/week-6/Homework/mandatory/1-alarmclock/alarmclock.js index 6ca81cd3b..99bb68186 100644 --- a/week-6/Homework/mandatory/1-alarmclock/alarmclock.js +++ b/week-6/Homework/mandatory/1-alarmclock/alarmclock.js @@ -1,7 +1,19 @@ -function setAlarm() {} +// Implement the missing functionality according to the task description. +// Hint: Remember which function you need to call when it's time to alarm. + +function setAlarm() { } // DO NOT EDIT BELOW HERE +/* + Try to reason about the code below and understand what it will do. + You will see that it attaches some event listeners to buttons on the page as well as how to play Audio from JS. + If you don't remember how to use events, please revisit the previous lession. +*/ +/* + Open the documentation below if you are keen to know what is Audio object and how it works + Audio documentation: https://developer.mozilla.org/en-US/docs/Web/API/HTMLAudioElement/Audio +*/ var audio = new Audio("alarmsound.mp3"); function setup() { @@ -22,4 +34,24 @@ function pauseAlarm() { audio.pause(); } +/* + This "window.onload" construct below might be something new that you haven't seen before. + + Window Object represents the current open window (tab) in the browser. + The Window interface contains loads of functionality among others the reference to the DOM Object. + + Here you can read more about window interface and see what properties it has: + https://developer.mozilla.org/en-US/docs/Web/API/Window + + We use the "onload" Window event to run a function when all resources and the DOM has been loaded and ready to use. + This ensures that "setup" function can find the elements defined in index.html file even if the script HTML tag + in the index file is appears earlier than the actual HTML elements we look up inside that function. + + You can play and try to see what happens if you replace "window.onload = setup;" with "setup();" function call instead. + If you open the browser console, you should see an error "Cannot read property 'addEventListener' of null". + It occurs because this script is being executed earlier and the elements it tries to find hasn't been yet loaded. + (An alternative way to fix it is by moving the script tags after element with the id "stop".) + + Documentation for onload event documentation: https://developer.mozilla.org/en-US/docs/Web/API/GlobalEventHandlers/onload +*/ window.onload = setup; diff --git a/week-6/Homework/mandatory/2-quotegenerator/quotes.js b/week-6/Homework/mandatory/2-quotegenerator/quotes.js index 39ab24529..99ae3ed9d 100644 --- a/week-6/Homework/mandatory/2-quotegenerator/quotes.js +++ b/week-6/Homework/mandatory/2-quotegenerator/quotes.js @@ -1,7 +1,6 @@ // DO NOT EDIT BELOW HERE -// A function which will return one item, at -// random, from the given array. +// A function which will return one item, at random, from the given array. // // Parameters // ---------- diff --git a/week-6/Homework/mandatory/2-quotegenerator/task.md b/week-6/Homework/mandatory/2-quotegenerator/task.md index 703785beb..bc566e3bb 100644 --- a/week-6/Homework/mandatory/2-quotegenerator/task.md +++ b/week-6/Homework/mandatory/2-quotegenerator/task.md @@ -2,7 +2,7 @@ In this folder you will find the basic setup of a quote generator. -You can change any of the files in this project +You can change any of the files in this project. ## How the Quote Generator should work @@ -10,14 +10,14 @@ When the page loads it should show a random quote from the `quotes` array on the When you click a button on the screen it should change the quote on the screen. -It can look however you like but there is an example in this folder at `quote_generator_example.png` +It can look however you like but there is an example in this folder at `quote_generator_example.png`. ## Need Help? - If you can't work out how to find a random element from the array, either: - - (advanced) try to use `Math.random()` + - (advanced) try to use [`Math.random()`](https://www.w3schools.com/js/js_random.asp) - OR - - (basic) use the `pickFromArray()` function supplied in the javascript file. + - (basic) use the `pickFromArray()` function supplied in the `quotes.js` javascript file. ## Further work From 4f470715a895e501b799a61fa9900d6340cb46a3 Mon Sep 17 00:00:00 2001 From: dsobkow Date: Fri, 26 Jun 2020 16:29:33 +0100 Subject: [PATCH 51/55] Update week-8 homework description --- week-8/Homework/mandatory/3-dog-photo-gallery/task.md | 2 +- week-8/Homework/mandatory/4-programmer-humour/task.md | 4 ++-- week-8/Homework/mandatory/5-project/task.md | 5 +++-- 3 files changed, 6 insertions(+), 5 deletions(-) diff --git a/week-8/Homework/mandatory/3-dog-photo-gallery/task.md b/week-8/Homework/mandatory/3-dog-photo-gallery/task.md index 114e4bb6d..af6b99a50 100644 --- a/week-8/Homework/mandatory/3-dog-photo-gallery/task.md +++ b/week-8/Homework/mandatory/3-dog-photo-gallery/task.md @@ -5,7 +5,7 @@ Let's make a randomized dog photo gallery! Write a function that makes an API call to `https://dog.ceo/api/breeds/image/random`. It should trigger after clicking a button in your webpage. Every time the button is clicked it should append a new dog image to the DOM. - Create an `index.html` file that will display your random image -- Add 2 `