diff --git a/week-2/Homework/extra/4-radio-stations.js b/week-2/Homework/extra/1-radio-stations.js similarity index 95% rename from week-2/Homework/extra/4-radio-stations.js rename to week-2/Homework/extra/1-radio-stations.js index 95c0e5611..a58292537 100644 --- a/week-2/Homework/extra/4-radio-stations.js +++ b/week-2/Homework/extra/1-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/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..442f1816a 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 should 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` and 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 ec5d4208b..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,15 +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. */ - -function sortAges(arr) {} +//1)Create the function inside, Think about nested loops +function sortAges(arr) { + //create function here +} /* ======= TESTS - DO NOT MODIFY ===== */ 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 71% rename from week-3/Homework/mandatory/0-freecodecamp.md rename to week-3/Homework/mandatory/0- Introduction.md index 65d254cbe..52a8ca0ee 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)** + +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 - Access an Array's Contents Using Bracket Notation @@ -15,16 +19,8 @@ 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 +Then open **Basic Algorithm Scripting** and attempt all of these - Convert Celsius to Fahrenheit - Reverse a String 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() { } diff --git a/week-3/Homework/mandatory/2-bush-berries.js b/week-3/Homework/mandatory/2-bush-berries.js index d90032302..ea5118004 100644 --- a/week-3/Homework/mandatory/2-bush-berries.js +++ b/week-3/Homework/mandatory/2-bush-berries.js @@ -8,7 +8,25 @@ 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 (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. + */ + +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() { diff --git a/week-3/Homework/mandatory/3-space-colonies.js b/week-3/Homework/mandatory/3-space-colonies.js index f99891a85..f9e7ba636 100644 --- a/week-3/Homework/mandatory/3-space-colonies.js +++ b/week-3/Homework/mandatory/3-space-colonies.js @@ -6,11 +6,14 @@ 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() { - -} +function colonisers() {} /* ======= TESTS - DO NOT MODIFY ===== */ @@ -26,7 +29,7 @@ const voyagers = [ "Asimov", "Oscar family", "Avery family", - "Archer family" + "Archer family", ]; function arraysEqual(a, b) { @@ -52,6 +55,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/4-eligible-students.js b/week-3/Homework/mandatory/4-eligible-students.js index 6424b01bd..e72ddedb1 100644 --- a/week-3/Homework/mandatory/4-eligible-students.js +++ b/week-3/Homework/mandatory/4-eligible-students.js @@ -1,25 +1,98 @@ /* - Only students who have attended enough classes are eligible to sit an exam. + 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 + to select students: + + Only students who have attended enough classes are eligible to join the research teams. - Create a function which: + Finish the "getEligibleStudents" 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) + 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. + - Returns an array containing only the names of the who have attended AT LEAST 8 classes + + */ -function eligibleStudents() { +// 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 +// 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 + +// 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 */ + +function getEligibleStudents() { +} + +/* + + Later leaders of Alpha planet decided to change the rule as below: + + 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 "getEligibleStudents2" 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. + + Hint: To complete the function, search how to change text to lower or upper case by using string method. +*/ + +function getEligibleStudents2() { } /* ======= 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], + ["amy", 0] ] function arraysEqual(a, b) { @@ -46,7 +119,25 @@ function test(test_name, expr) { } test("eligibleStudents function works", - arraysEqual( - eligibleStudents(attendances), ["Ahmed", "Clement", "Tayoa", "Nina"] - ) -) \ No newline at end of file + arraysEqual(getEligibleStudents(alphaStudentGroup), ["Ahmed", "Clement", "Tayoa", "Nina", "Bob"]) +) + +test("eligibleStudents function without eligible candidates", + arraysEqual(getEligibleStudents(deltaStudentGroup), []) +) + +test("eligibleStudents function with no candidates", + arraysEqual(getEligibleStudents([]), []) +) + +test("eligibleStudents2 function works", + arraysEqual(getEligibleStudents2(alphaStudentGroup), ["Ahmed", "Adam"]) +) + +test("eligibleStudents2 function without eligible candidates", + arraysEqual(getEligibleStudents2(deltaStudentGroup), ["amy"]) +) + +test("eligibleStudents2 function with no candidates", + arraysEqual(getEligibleStudents2([]), []) +) diff --git a/week-3/Homework/mandatory/5-journey-planner.js b/week-3/Homework/mandatory/5-journey-planner.js index 53499c372..0ac48b8cd 100644 --- a/week-3/Homework/mandatory/5-journey-planner.js +++ b/week-3/Homework/mandatory/5-journey-planner.js @@ -1,24 +1,140 @@ +/* + 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) { + 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. + 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 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 + the 1st element says the name of the location, + and rest of them says the transport modes. + + 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"] + ] + + 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. + + 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.) +*/ + +/* + Implement the function getTransportModes that + - 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 + - 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 + 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 - Return an array of where I can go if I only want to use a specific mode of transport. + Hint: Use the corresponding array method to decide if an element is member of an array. +*/ +function isAccessibleByTransportMode() { } - NOTE: only the names should be returned, not the means of transport. +/* + Implement the function getLocationName that + - 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' and their transports + e.g: + [ + ["Angel", "tube", "bus"], + ["London Bridge", "tube", "river boat"] + ] + 2) A string containing a transport mode + e.g: "bus" -function journeyPlanner() { + - Returns an array of where I can go if I only want to use a specific mode of transport. + NOTE: only the location 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. + + Advanced challange: try to use arrow function when invoking an array method. +*/ +function journeyPlanner(locations, transportMode) { + // Implement the function body } /* ======= 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 +149,83 @@ 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( + "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"), [ + "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/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 +) 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..b68254e9a 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] - ) - ); diff --git a/week-4/Homework/extra/extra-homework.md b/week-4/Homework/extra/extra-homework.md index 4aa5066a0..516534a30 100644 --- a/week-4/Homework/extra/extra-homework.md +++ b/week-4/Homework/extra/extra-homework.md @@ -4,19 +4,12 @@ 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 -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) 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) diff --git a/week-4/Homework/mandatory/1-freecodecamp.md b/week-4/Homework/mandatory/1-freecodecamp.md index a05de7191..d95c80d21 100644 --- a/week-4/Homework/mandatory/1-freecodecamp.md +++ b/week-4/Homework/mandatory/1-freecodecamp.md @@ -1,20 +1,23 @@ ## 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)** + +## 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) + + +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 -- 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 diff --git a/week-4/Homework/mandatory/2-writers.js b/week-4/Homework/mandatory/2-writers.js index 974a173aa..b1f5d006c 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 a frequent combination. Just think about what benefits we can get from this construct. -Here is the array: +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). +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: let writers = [ { firstName: "Virginia", @@ -31,8 +39,8 @@ let writers = [ alive: false }, { - firstName: "bell", - lastName: "hooks", + firstName: "Bell", + lastName: "Hooks", occupation: "writer", age: 64, alive: true @@ -40,5 +48,25 @@ 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 below sentence and + 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}." +*/ + + + +/* +Exercise 2: + Only `console.log()` out the writers who are in their 40s (meaning between 40 and 49) + and not alive anymore. Use the below sentence format: + "Writer {firstName} {lastName} died at {age} years old." +*/ + + + +/* +Exercise 3: + Only `console.log()` out alive writers who are in their 40s (meaning between 40 and 49): + "Hi, my name is {firstName} {lastName}. I am {age} years old." */ diff --git a/week-4/Homework/mandatory/3-water-bottle.js b/week-4/Homework/mandatory/3-water-bottle.js index cb8041140..4ad72fdd9 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 already full water volume cannot go beyond.`); +else console.warn(`Whoops!!! Looks like you've changed your bottle to a bigger one, it went beyond its maximum capacity up to ${bottle.volume} unit.`); + +if (bottle.isFull()) console.log(`That's correct! Bottle is still full.`); +else console.warn(`Not quite right! Bottle should be still full but is not.`); + +// 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.`); + +if (bottle.volume === 0) console.log(`That's correct! Empty bottle volume is repesented as zero.`); +else console.warn(`Not quite right. Volume should be zero instead of ${bottle.volume}.`); + +// ACTIONS +bottle.drink(); + +// CHECKS +if (bottle.volume === 0) console.log(`That's correct! Water volume cannot go below zero.`); +else console.warn(`Whoops!!! Looks like your water volume went negative. Your water volume is ${bottle.volume} unit.`); + +if (bottle.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.`); diff --git a/week-4/Homework/mandatory/4-groceries.js b/week-4/Homework/mandatory/4-groceries.js index 2b34cdb53..09a69fee3 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 object +let numberOfItemsPerWeak = { + monday: 0, + tuesday: 0, + wednesday: 0, + thursday: 0, + fridray: 0, + saturday: 0, + sunday: 0 }; 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. 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() 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) { +} 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 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/2-exercises/exercises.js b/week-5/Homework/mandatory/2-exercises/exercises.js index 174c5db04..cb8c0f42d 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