diff --git a/02_Day_Data_types/02_day_data_types.md b/02_Day_Data_types/02_day_data_types.md index e27d43d..04e0228 100644 --- a/02_Day_Data_types/02_day_data_types.md +++ b/02_Day_Data_types/02_day_data_types.md @@ -514,6 +514,9 @@ let country = 'Finland' console.log(country.substr(3, 4)) // land ``` +**NOTE**: `substr()` is no longer recommended, although some browsers may support it for compatibility reasons, it is in the process of being dropped. + + 6. *substring()*: It takes two arguments, the starting index and the stopping index but it doesn't include the character at the stopping index. ```js diff --git a/03_Day_Booleans_operators_date/03_booleans_operators_date.md b/03_Day_Booleans_operators_date/03_booleans_operators_date.md index bb376ae..d346db2 100644 --- a/03_Day_Booleans_operators_date/03_booleans_operators_date.md +++ b/03_Day_Booleans_operators_date/03_booleans_operators_date.md @@ -218,7 +218,7 @@ console.log('python'.length > 'dragon'.length) // false ``` Try to understand the above comparisons with some logic. Remembering without any logic might be difficult. -JavaScript is somehow a wired kind of programming language. JavaScript code run and give you a result but unless you are good at it may not be the desired result. +JavaScript is somehow a wired kind of programming language. JavaScript code run and give you a result, but unless you are good at it, it may not be the desired result. As rule of thumb, if a value is not true with == it will not be equal with ===. Using === is safer than using ==. The following [link](https://dorey.github.io/JavaScript-Equality-Table/) has an exhaustive list of comparison of data types. @@ -489,10 +489,10 @@ Let us format these values to a human readable time format. ```js const now = new Date() const year = now.getFullYear() // return year -const month = now.getMonth() + 1 // return month(0 - 11) +const month = now.getMonth() + 1 // return month(1 - 12) const date = now.getDate() // return date (1 - 31) const hours = now.getHours() // return number (0 - 23) -const minutes = now.getMinutes() // return number (0 -59) +const minutes = now.getMinutes() // return number (0 - 59) console.log(`${date}/${month}/${year} ${hours}:${minutes}`) // 4/1/2020 0:56 ``` @@ -628,6 +628,6 @@ console.log(`${date}/${month}/${year} ${hours}:${minutes}`) // 4/1/2020 0:56 ### Exercises: Level 3 1. Create a human readable time format using the Date time object. The hour and the minute should be all the time two digits(7 hours should be 07 and 5 minutes should be 05 ) - 1. YYY-MM-DD HH:mm eg. 20120-01-02 07:05 + 1. YYYY-MM-DD HH:mm eg. 2012-01-02 07:05 [<< Day 2](../02_Day_Data_types/02_day_data_types.md) | [Day 4 >>](../04_Day_Conditionals/04_day_conditionals.md) diff --git a/04_Day_Conditionals/04_day_conditionals.md b/04_Day_Conditionals/04_day_conditionals.md index 0100844..e2420a3 100644 --- a/04_Day_Conditionals/04_day_conditionals.md +++ b/04_Day_Conditionals/04_day_conditionals.md @@ -177,7 +177,7 @@ if (weather === 'rainy') { ### Switch -Switch is an alternative for **if else if else else**. +Switch is an alternative for **if else if else**. The switch statement starts with a *switch* keyword followed by a parenthesis and code block. Inside the code block we will have different cases. Case block runs if the value in the switch statement parenthesis matches with the case value. The break statement is to terminate execution so the code execution does not go down after the condition is satisfied. The default block runs if all the cases don't satisfy the condition. ```js @@ -297,7 +297,7 @@ isRaining You are 5 years older than me. ``` -1. If a is greater than b return 'a is greater than b' else 'a is less than b'. Try to implement it in to ways +1. If a is greater than b return 'a is greater than b' else 'a is less than b'. Try to implement it in two ways - using if else - ternary operator. @@ -324,7 +324,7 @@ isRaining ### Exercises: Level 2 1. Write a code which can give grades to students according to theirs scores: - - 80-100, A + - 90-100, A - 70-89, B - 60-69, C - 50-59, D @@ -354,8 +354,7 @@ isRaining ### Exercises: Level 3 1. Write a program which tells the number of days in a month. - - ```sh + ```sh Enter a month: January January has 31 days. @@ -367,10 +366,8 @@ isRaining Enter a month: FEbruary February has 28 days. - ``` - -1. Write a program which tells the number of days in a month, now consider leap year. - + ``` +2. Write a program which tells the number of days in a month, now consider leap year. 🎉 CONGRATULATIONS ! 🎉 diff --git a/05_Day_Arrays/05_day_arrays.md b/05_Day_Arrays/05_day_arrays.md index 0dae635..458be64 100644 --- a/05_Day_Arrays/05_day_arrays.md +++ b/05_Day_Arrays/05_day_arrays.md @@ -59,7 +59,7 @@ An array is a collection of different data types which are ordered and changeabl ### How to create an empty array In JavaScript, we can create an array in different ways. Let us see different ways to create an array. -It is very common to use _const_ instead of _let_ to declare an array variable. If you ar using const it means you do not use that variable name again. +It is very common to use _const_ instead of _let_ to declare an array variable. If you are using _const_, it means you do not use that variable name again. - Using Array constructor @@ -302,11 +302,11 @@ console.log(countries) ### Methods to manipulate array -There are different methods to manipulate an array. These are some of the available methods to deal with arrays:_Array, length, concat, indexOf, slice, splice, join, toString, includes, lastIndexOf, isArray, fill, push, pop, shift, unshift_ +There are different methods to manipulate an array. These are some of the available methods to deal with arrays: _Array, length, concat, indexOf, slice, splice, join, toString, includes, lastIndexOf, isArray, fill, push, pop, shift, unshift_ #### Array Constructor -Array:To create an array. +Array: To create an array. ```js const arr = Array() // creates an an empty array @@ -336,7 +336,7 @@ console.log(four4values) // [4, 4, 4, 4] #### Concatenating array using concat -concat:To concatenate two arrays. +concat: To concatenate two arrays. ```js const firstList = [1, 2, 3] @@ -360,16 +360,16 @@ console.log(fruitsAndVegetables) #### Getting array length -Length:To know the size of the array +Length: To know the size of the array ```js const numbers = [1, 2, 3, 4, 5] console.log(numbers.length) // -> 5 is the size of the array ``` -#### Getting index an element in arr array +#### Getting index of an element in an array -indexOf:To check if an item exist in an array. If it exists it returns the index else it returns -1. +indexOf: To check if an item exist in an array. If it exists it returns the index else it returns -1. ```js const numbers = [1, 2, 3, 4, 5] @@ -450,7 +450,7 @@ console.log(webTechs.includes('C')) // false #### Checking array -Array.isArray:To check if the data type is an array +Array.isArray: To check if the data type is an array ```js const numbers = [1, 2, 3, 4, 5] @@ -462,7 +462,7 @@ console.log(Array.isArray(number)) // false #### Converting array to string -toString:Converts array to string +toString: Converts array to string ```js const numbers = [1, 2, 3, 4, 5] @@ -517,7 +517,7 @@ Slice: To cut out a multiple items in range. It takes two parameters:starting an #### Splice method in array -Splice: It takes three parameters:Starting position, number of times to be removed and number of items to be added. +Splice: It takes three parameters: Starting position, number of times to be removed and number of items to be added. ```js const numbers = [1, 2, 3, 4, 5] @@ -653,7 +653,7 @@ console.log(arrayOfArray[0]) // [1, 2, 3] console.log(fullStack[1]) // ["Node", "Express", "MongoDB"] ``` -🌕 You are diligent and you have already achieved quite a lot. You have just completed day 5 challenges and you are 5 steps a head in to your way to greatness. Now do some exercises for your brain and for your muscle. +🌕 You are diligent and you have already achieved quite a lot. You have just completed day 5 challenges and you are 5 steps ahead in to your way to greatness. Now do some exercises for your brain and for your muscle. ## 💻 Exercise @@ -690,15 +690,15 @@ const webTechs = [ 3. Find the length of your array 4. Get the first item, the middle item and the last item of the array 5. Declare an array called _mixedDataTypes_, put different data types in the array and find the length of the array. The array size should be greater than 5 -6. Declare an array variable name itCompanies and assign initial values Facebook, Google, Microsoft, Apple, IBM, Oracle and Amazon +6. Declare an array variable named itCompanies and assign initial values Facebook, Google, Microsoft, Apple, IBM, Oracle and Amazon 7. Print the array using _console.log()_ 8. Print the number of companies in the array 9. Print the first company, middle and last company 10. Print out each company -11. Change each company name to uppercase one by one and print them out -12. Print the array like as a sentence: Facebook, Google, Microsoft, Apple, IBM,Oracle and Amazon are big IT companies. +11. Change each company name to uppercase one by one and print them out +12. Print the array like a sentence: Facebook, Google, Microsoft, Apple, IBM, Oracle and Amazon are big IT companies. 13. Check if a certain company exists in the itCompanies array. If it exist return the company else return a company is _not found_ -14. Filter out companies which have more than one 'o' without the filter method +14. Filter out company names which have more than one 'o' without the filter method 15. Sort the array using _sort()_ method 16. Reverse the array using _reverse()_ method 17. Slice out the first 3 companies from the array @@ -712,7 +712,7 @@ const webTechs = [ ### Exercise: Level 2 1. Create a separate countries.js file and store the countries array in to this file, create a separate file web_techs.js and store the webTechs array in to this file. Access both file in main.js file -1. First remove all the punctuations and change the string to array and count the number of words in the array +2. First remove all the punctuations and change the string to array and count the number of words in the array ```js let text = @@ -738,12 +738,12 @@ const webTechs = [ - remove 'Honey' if you are allergic to honey - modify Tea to 'Green Tea' 1. In countries array check if 'Ethiopia' exists in the array if it exists print 'ETHIOPIA'. If it does not exist add to the countries list. -1. In the webTechs array check if Sass exists in the array and if it exists print 'Sass is a CSS preprocess'. If it does not exist add Sass to the array and print the array. -1. Concatenate the following two variables and store it in a fullStack variable. +1. In the webTechs array check if 'Sass' exists in the array and if it exists print 'Sass is a CSS preprocess'. If it does not exist add 'Sass' to the array and print the array. +2. Concatenate the following two arrays and store it in a fullStack variable. ```js const frontEnd = ['HTML', 'CSS', 'JS', 'React', 'Redux'] - const backEnd = ['Node','Express', 'MongoDB'] + const backEnd = ['Node', 'Express', 'MongoDB'] console.log(fullStack) ``` @@ -765,10 +765,10 @@ const webTechs = [ - Find the average age(all items divided by number of items) - Find the range of the ages(max minus min) - Compare the value of (min - average) and (max - average), use _abs()_ method -1.Slice the first ten countries from the [countries array](https://github.com/Asabeneh/30DaysOfJavaScript/tree/master/data/countries.js) +1. Slice the first ten countries from the [countries array](https://github.com/Asabeneh/30DaysOfJavaScript/tree/master/data/countries.js) 1. Find the middle country(ies) in the [countries array](https://github.com/Asabeneh/30DaysOfJavaScript/tree/master/data/countries.js) -2. Divide the countries array into two equal arrays if it is even. If countries array is not even , one more country for the first half. +2. Divide the countries array into two equal arrays if it is even. If countries array is not even, one more country for the first half. 🎉 CONGRATULATIONS ! 🎉 -[<< Day 4](../04_Day_Conditionals/04_day_Conditionals.md) | [Day 6 >>](../06_Day_Loops/06_day_loops.md) +[<< Day 4](../04_Day_Conditionals/04_day_conditionals.md)| [Day 6 >>](../06_Day_Loops/06_day_loops.md) diff --git a/06_Day_Loops/06_day_loops.md b/06_Day_Loops/06_day_loops.md index c093495..71a5287 100644 --- a/06_Day_Loops/06_day_loops.md +++ b/06_Day_Loops/06_day_loops.md @@ -248,7 +248,7 @@ for(let i = 0; i <= 5; i++){ // 0 1 2 4 5 ``` -🌕 You are so brave, you made it to this far. Now, you have gained the power to automate repetitive and tedious tasks. You have just completed day 6 challenges and you are 6 steps a head in to your way to greatness. Now do some exercises for your brain and for your muscle. +🌕 You are so brave, you made it to this far. Now, you have gained the power to automate repetitive and tedious tasks. You have just completed day 6 challenges and you are 6 steps ahead in to your way to greatness. Now do some exercises for your brain and for your muscle. ## 💻 Exercises:Day 6 @@ -287,7 +287,7 @@ for(let i = 0; i <= 5; i++){ 3. Iterate 0 to n using for loop 4. Write a loop that makes the following pattern using console.log(): - ```js + ```sh # ## ### @@ -408,19 +408,18 @@ for(let i = 0; i <= 5; i++){ ['Germany', 'GER', 7], ['Hungary', 'HUN', 7], ['Ireland', 'IRE', 7], - ['Iceland', 'ICE', 7], ['Japan', 'JAP', 5], ['Kenya', 'KEN', 5] ] ``` -2. In above countries array, check if there is a country or countries containing the word 'land'. If there are countries containing 'land', print it as array. If there is no country containing the word 'land', print 'All these countries are without land'. +2. In above countries array, check if there is a country or countries containing the word 'land'. If there are countries containing 'land', print it as array. If there is no country containing the word 'land', print `All these countries are without 'land'`. ```sh - ['Finland','Ireland', 'Iceland'] + ['Finland','Ireland'] ``` -3. In above countries array, check if there is a country or countries end with a substring 'ia'. If there are countries end with, print it as array. If there is no country containing the word 'ai', print 'These are countries ends without ia'. +3. In above countries array, check if there is a country or countries ending with a substring 'ia'. If there are countries ending with 'ia', print it as array. If there is no country containing the substring 'ia', print `These are no countries end with 'ia'`. ```sh ['Albania', 'Bolivia','Ethiopia'] diff --git a/07_Day_Functions/07_day_functions.md b/07_Day_Functions/07_day_functions.md index 17d9087..020c65d 100644 --- a/07_Day_Functions/07_day_functions.md +++ b/07_Day_Functions/07_day_functions.md @@ -43,10 +43,10 @@ ## Functions -So far we have seen many builtin JavaScript functions. In this section, we will focus on custom functions. What is a function? Before we start making functions, lets understand what function is and why we need function? +So far we have seen many built-in JavaScript functions. In this section, we will focus on custom functions. What is a function? Before we start making functions, lets understand what a function is and why we need function? A function is a reusable block of code or programming statements designed to perform a certain task. -A function is declared by a function key word followed by a name, followed by parentheses (). A parentheses can take a parameter. If a function take a parameter it will be called with argument. A function can also take a default parameter. To store a data to a function, a function has to return certain data types. To get the value we call or invoke a function. +A function is declared by a function keyword followed by a name, followed by parentheses (). A parentheses can take a parameter. If a function take a parameter(s), it will be called with argument(s). A function can also take a default parameter. To store a data to a function, a function has to return certain data types. To get the value we call or invoke a function. Function makes code: - clean and easy to read @@ -179,7 +179,7 @@ function sumTwoNumbers(numOne, numTwo) { console.log(sum) } sumTwoNumbers(10, 20) // calling functions -// If a function doesn't return it doesn't store data, so it should return +// If a function doesn't return a value, it doesn't store data, so it should return function sumTwoNumbers(numOne, numTwo) { let sum = numOne + numTwo @@ -416,8 +416,8 @@ function greetings(name = 'Peter') { return message } -console.log(greetings()) -console.log(greetings('Asabeneh')) +console.log(greetings()) // 'Peter, welcome to 30 Days of JavaScript!' +console.log(greetings('Asabeneh')) // 'Asabeneh, welcome to 30 Days of JavaScript!' ``` ```js @@ -427,8 +427,8 @@ function generateFullName(firstName = 'Asabeneh', lastName = 'Yetayeh') { return fullName } -console.log(generateFullName()) -console.log(generateFullName('David', 'Smith')) +console.log(generateFullName()) // 'Asabeneh Yetayeh' +console.log(generateFullName('David', 'Smith')) // 'David Smith' ``` ```js @@ -437,7 +437,7 @@ function calculateAge(birthYear, currentYear = 2019) { return age } -console.log('Age: ', calculateAge(1819)) +console.log('Age: ', calculateAge(1819)) // Age: 200 ``` ```js @@ -446,8 +446,10 @@ function weightOfObject(mass, gravity = 9.81) { return weight } -console.log('Weight of an object in Newton: ', weightOfObject(100)) // 9.81 gravity at the surface of Earth -console.log('Weight of an object in Newton: ', weightOfObject(100, 1.62)) // gravity at surface of Moon +console.log('Weight of an object in Newton: ', weightOfObject(100)) // 981 +// 9.81 gravity at the surface of Earth +console.log('Weight of an object in Newton: ', weightOfObject(100, 1.62)) // 162 +// gravity at surface of Moon ``` Let us see how we write the above functions with arrow functions @@ -472,8 +474,8 @@ const greetings = (name = 'Peter') => { return message } -console.log(greetings()) -console.log(greetings('Asabeneh')) +console.log(greetings()) // 'Peter, welcome to 30 Days of JavaScript!' +console.log(greetings('Asabeneh')) // 'Asabeneh, welcome to 30 Days of JavaScript!' ``` ```js @@ -483,28 +485,30 @@ const generateFullName = (firstName = 'Asabeneh', lastName = 'Yetayeh') => { return fullName } -console.log(generateFullName()) -console.log(generateFullName('David', 'Smith')) +console.log(generateFullName()) // 'Asabeneh Yetayeh' +console.log(generateFullName('David', 'Smith')) // 'David Smith' ``` ```js const calculateAge = (birthYear, currentYear = 2019) => currentYear - birthYear -console.log('Age: ', calculateAge(1819)) +console.log('Age: ', calculateAge(1819)) // 200 ``` ```js const weightOfObject = (mass, gravity = 9.81) => mass * gravity + ' N' -console.log('Weight of an object in Newton: ', weightOfObject(100)) // 9.81 gravity at the surface of Earth -console.log('Weight of an object in Newton: ', weightOfObject(100, 1.62)) // gravity at surface of Moon +console.log('Weight of an object in Newton: ', weightOfObject(100)) // 981 +// 9.81 gravity at the surface of Earth +console.log('Weight of an object in Newton: ', weightOfObject(100, 1.62)) // 162 +// gravity at surface of Moon ``` ### Function declaration versus Arrow function It Will be covered in other section. -🌕 You are a rising star, now you knew function . Now, you are super charged with the power of functions. You have just completed day 7 challenges and you are 7 steps a head in to your way to greatness. Now do some exercises for your brain and for your muscle. +🌕 You are a rising star, now you knew function . Now, you are super charged with the power of functions. You have just completed day 7 challenges and you are 7 steps ahead in to your way to greatness. Now do some exercises for your brain and for your muscle. @@ -521,10 +525,10 @@ It Will be covered in other section. 7. Area of a circle is calculated as follows: _area = Ï€ x r x r_. Write a function which calculates _areaOfCircle_ 8. Circumference of a circle is calculated as follows: _circumference = 2Ï€r_. Write a function which calculates _circumOfCircle_ 9. Density of a substance is calculated as follows:_density= mass/volume_. Write a function which calculates _density_. -10. Speed is calculated by dividing the total distance covered by a moving object divided by the total amount of time taken. Write a function which calculates a speed of a moving object, _speed_. +10. Speed is calculated by dividing the total distance covered by a moving object divided by the total amount of time taken. Write a function which calculates speed of a moving object, _speed_. 11. Weight of a substance is calculated as follows: _weight = mass x gravity_. Write a function which calculates _weight_. -12. Temperature in oC can be converted to oF using this formula: _oF = (oC x 9/5) + 32_. Write a function which convert oC to oF _convertCelsiusToFahrenheit_. -13. Body mass index(BMI) is calculated as follows: _bmi = weight in Kg / (height x height) in m2_. Write a function which calculates _bmi_. BMI is used to broadly define different weight groups in adults 20 years old or older.Check if a person is _underweight, normal, overweight_ or _obese_ based the information given below. +12. Temperature in °C can be converted to °F using this formula: _°F = (°C x 9/5) + 32_. Write a function which convert °C to °F _convertCelsiusToFahrenheit_. +13. Body mass index(BMI) is calculated as follows: _bmi = weight in kg / (height x height) in_ $` m^2 `$. Write a function which calculates _bmi_. BMI is used to broadly define different weight groups in adults, 20 years old or older. Check if a person is _underweight, normal, overweight_ or _obese_ based the information given below. - The same groups apply to both men and women. - _Underweight_: BMI is less than 18.5 @@ -532,8 +536,8 @@ It Will be covered in other section. - _Overweight_: BMI is 25 to 29.9 - _Obese_: BMI is 30 or more -14. Write a function called _checkSeason_, it takes a month parameter and returns the season:Autumn, Winter, Spring or Summer. -15. Math.max returns its largest argument. Write a function findMax that takes three arguments and returns their maximum with out using Math.max method. +14. Write a function called _checkSeason_, it takes a month parameter and returns the season: Autumn, Winter, Spring or Summer. +15. Math.max returns its largest argument. Write a function findMax that takes three arguments and returns their maximum without using Math.max() method. ```js console.log(findMax(0, 10, 5)) @@ -545,7 +549,7 @@ It Will be covered in other section. ### Exercises: Level 2 1. Linear equation is calculated as follows: _ax + by + c = 0_. Write a function which calculates value of a linear equation, _solveLinEquation_. -1. Quadratic equation is calculated as follows: _ax2 + bx + c = 0_. Write a function which calculates value or values of a quadratic equation, _solveQuadEquation_. +1. Quadratic equation is calculated as follows: $` a{x^2} + bx + c = 0 `$. Write a function which calculates value or values of a quadratic equation, _solveQuadEquation_. ```js console.log(solveQuadratic()) // {0} @@ -571,7 +575,7 @@ It Will be covered in other section. swapValues(4, 5) // x = 5, y = 4 ``` -1. Declare a function name _reverseArray_. It takes array as a parameter and it returns the reverse of the array (don't use method). +1. Declare a function name _reverseArray_. It takes array as a parameter and it returns the reverse of the array (don't use _Array.reverse()_ method). ```js console.log(reverseArray([1, 2, 3, 4, 5])) @@ -580,13 +584,13 @@ It Will be covered in other section. //['C', 'B', 'A'] ``` -1. Declare a function name _capitalizeArray_. It takes array as a parameter and it returns the - capitalizedarray. +1. Declare a function name _capitalizeArray_. It takes array as a parameter and it returns the capitalized array. 1. Declare a function name _addItem_. It takes an item parameter and it returns an array after adding the item 1. Declare a function name _removeItem_. It takes an index parameter and it returns an array after removing an item 1. Declare a function name _sumOfNumbers_. It takes a number parameter and it adds all the numbers in that range. 1. Declare a function name _sumOfOdds_. It takes a number parameter and it adds all the odd numbers in that - range. 1. Declare a function name _sumOfEven_. It takes a number parameter and it adds all the even numbers in that - range. -1. Declare a function name evensAndOdds . It takes a positive integer as parameter and it counts number of evens and odds in the number. +1. Declare a function name evensAndOdds . It takes a positive integer as parameter and it counts number of evens and odds between zero and the number. ```sh evensAndOdds(100); @@ -601,7 +605,7 @@ It Will be covered in other section. sum(1, 2, 3, 4) // -> 10 ``` -1. Writ a function which generates a _randomUserIp_. +1. Write a function which generates a _randomUserIp_. 1. Write a function which generates a _randomMacAddress_ 1. Declare a function name _randomHexaNumberGenerator_. When this function is called it generates a random hexadecimal number. The function return the hexadecimal number. @@ -638,7 +642,7 @@ It Will be covered in other section. ' ``` -1. Write a function name _rgbColorGenerator_ and it generates rgb colors. +1. Write a function called _rgbColorGenerator_ and it generates rgb colors. ```sh rgbColorGenerator() @@ -664,10 +668,10 @@ It Will be covered in other section. 1. Call your function _sum_, it takes any number of arguments and it returns the sum. 1. Write a function called _sumOfArrayItems_, it takes an array parameter and return the sum of all the items. Check if all the array items are number types. If not give return reasonable feedback. 1. Write a function called _average_, it takes an array parameter and returns the average of the items. Check if all the array items are number types. If not give return reasonable feedback. -1. Write a function called _modifyArray_ takes array as parameter and modifies the fifth item of the array and return the array. If the array length is less than five it return 'item not found'. +1. Write a function called _modifyArray_ takes array as parameter and modifies(capitalize) the fifth item of the array and return the array. If the array length is less than five it return 'item not found'. ```js - console.log(modifyArray(['Avocado', 'Tomato', 'Potato','Mango', 'Lemon','Carrot']); + console.log(modifyArray(['Avocado', 'Tomato', 'Potato','Mango', 'Lemon','Carrot'])); ``` ```sh @@ -701,8 +705,8 @@ It Will be covered in other section. [(1, 4, 5, 7, 9, 8, 0)] ``` -1. Write a function called reverseCountries, it takes countries array and first it copy the array and returns the reverse of the original array +1. Write a function called _reverseCountries_, it takes countries array and first it copy the array and returns the reverse of the original array 🎉 CONGRATULATIONS ! 🎉 -[<< Day 6](../06_Day_Loops/06_day_loops.md) | [Day 8 >>](../08_Day_Objects/08_day_objects.md) \ No newline at end of file +[<< Day 6](../06_Day_Loops/06_day_loops.md) | [Day 8 >>](../08_Day_Objects/08_day_objects.md) diff --git a/08_Day_Objects/08_day_objects.md b/08_Day_Objects/08_day_objects.md index 69f5dc4..2524332 100644 --- a/08_Day_Objects/08_day_objects.md +++ b/08_Day_Objects/08_day_objects.md @@ -42,7 +42,7 @@ ## Scope -Variable is the fundamental part in programming. We declare variable to store different data types. To declare a variable we use the key word _var_, _let_ and _const_. A variable can be declared at different scope. In this section, we will see the scope variables, scope of variables when we use var or let. +Variable is the fundamental part in programming. We declare variable to store different data types. To declare a variable we use the keywords _var_, _let_ and _const_. A variable can be declared at different scope. In this section, we will see the scope of variables. Scope of variables when we use var or let. Variables scopes can be: - Global @@ -72,7 +72,7 @@ console.log(a, b) // accessible ### Global scope -A globally declared variable can be accessed every where in the same file. But the term global is relative. It can be global to the file or it can be global relative to some block of codes. +A globally declared variable can be accessed everywhere in the same file. But the term global is relative. It can be global to the file or it can be global relative to some block of codes. ```js //scope.js @@ -131,9 +131,8 @@ Now, you have an understanding of scope. A variable declared with *var* only sco function letsLearnScope() { var gravity = 9.81 console.log(gravity) - } -// console.log(gravity), Uncaught ReferenceError: gravity is not defined +console.log(gravity) // Uncaught ReferenceError: gravity is not defined if (true){ var gravity = 9.81 @@ -158,22 +157,22 @@ function letsLearnScope() { console.log(gravity) } -// console.log(gravity), Uncaught ReferenceError: gravity is not defined +console.log(gravity) // Uncaught ReferenceError: gravity is not defined if (true){ const gravity = 9.81 console.log(gravity) // 9.81 } -// console.log(gravity), Uncaught ReferenceError: gravity is not defined +console.log(gravity) // Uncaught ReferenceError: gravity is not defined for(let i = 0; i < 3; i++){ console.log(i) // 0, 1, 2 } -// console.log(i), Uncaught ReferenceError: i is not defined +console.log(i) // Uncaught ReferenceError: i is not defined ``` -The scope *let* and *const* are the same. The difference is only reassigning. We can not change or reassign the value of the `const` variable. I would strongly suggest you to use *let* and *const*, by using *let* and *const* you will write clean code and avoid hard to debug mistakes. As a rule of thumb, you can use *let* for any value which change, *const* for any constant value, and for an array, object, arrow function and function expression. +The scope of *let* and *const* are the same. The difference is only reassigning. We can not change or reassign the value of the `const` variable. I would strongly suggest you to use *let* and *const*, by using *let* and *const* you will write clean code and avoid hard to debug mistakes. As a rule of thumb, you can use *let* for any value which change, *const* for any constant value, and for an array, object, arrow function and function expression. ## 📔 Object @@ -437,7 +436,7 @@ console.log(copyPerson.hasOwnProperty('score')) ### Exercises: Level 2 -1. Find the person who has many skills in the users object. +1. Find the person who has the most skills in the users object. 1. Count logged in users, count users having greater than equal to 50 points from the following object. ````js @@ -491,20 +490,22 @@ console.log(copyPerson.hasOwnProperty('score')) isLoggedIn: false, points: 40 } - }``` + } + ```` 1. Find people who are MERN stack developer from the users object 1. Set your name in the users object without modifying the original users object 1. Get all keys or properties of users object 1. Get all the values of users object -1. Use the countries object to print a country name, capital, populations and languages. +1. Use the [countries object](../08_Day_Objects/08_day_starter/data/countries_data.js) to print a country name, capital, populations and languages. ### Exercises: Level 3 1. Create an object literal called _personAccount_. It has _firstName, lastName, incomes, expenses_ properties and it has _totalIncome, totalExpense, accountInfo,addIncome, addExpense_ and _accountBalance_ methods. Incomes is a set of incomes and its description and expenses is a set of incomes and its description. -2. **** Questions:2, 3 and 4 are based on the following two arrays:users and products () - ```js +** Questions:2, 3 and 4 are based on the following two arrays: `users` and `products` + +```js const users = [ { _id: 'ab12ex', @@ -579,7 +580,7 @@ console.log(copyPerson.hasOwnProperty('score')) ] ``` - Imagine you are getting the above users collection from a MongoDB database. +2. Imagine you are getting the above users collection from a MongoDB database. a. Create a function called signUp which allows user to add to the collection. If user exists, inform the user that he has already an account. b. Create a function called signIn which allows user to sign in to the application diff --git a/09_Day_Higher_order_functions/09_day_higher_order_functions.md b/09_Day_Higher_order_functions/09_day_higher_order_functions.md old mode 100644 new mode 100755 index 9aa6871..843d6fd --- a/09_Day_Higher_order_functions/09_day_higher_order_functions.md +++ b/09_Day_Higher_order_functions/09_day_higher_order_functions.md @@ -72,7 +72,7 @@ console.log(cube(callback, 3)) Higher order functions return function as a value ​ ```js -// Higher order function returning an other function +// Higher order function returning another function const higherOrder = n => { const doSomething = m => { const doWhatEver = t => { @@ -85,7 +85,7 @@ const higherOrder = n => { console.log(higherOrder(2)(3)(10)) ``` -Let us see were we use call back functions. For instance the _forEach_ method uses call back. +Let us see where we use callback functions. For instance the _forEach_ method uses callback. ```js const numbers = [1, 2, 3, 4, 5] @@ -96,8 +96,8 @@ const sumArray = arr => { } arr.forEach(callback) return sum - } + console.log(sumArray(numbers)) ``` @@ -108,7 +108,7 @@ console.log(sumArray(numbers)) The above example can be simplified as follows: ```js -const numbers = [1, 2, 3, 4] +const numbers = [1, 2, 3, 4, 5] ​ const sumArray = arr => { let sum = 0 @@ -116,8 +116,8 @@ const sumArray = arr => { sum += element }) return sum - } + console.log(sumArray(numbers)) ``` @@ -127,7 +127,7 @@ console.log(sumArray(numbers)) ### Setting time -In JavaScript we can execute some activities in a certain interval of time or we can schedule(wait) for some time to execute some activities. +In JavaScript we can execute some activities in a certain interval of time or we can schedule(wait) to execute some activities for some other time. - setInterval - setTimeout @@ -172,11 +172,11 @@ setTimeout(sayHello, 2000) // it prints hello after it waits for 2 seconds. ## Functional Programming -Instead of writing regular loop, latest version of JavaScript introduced lots of built in methods which can help us to solve complicated problems. All builtin methods take callback function. In this section, we will see _forEach_, _map_, _filter_, _reduce_, _find_, _every_, _some_, and _sort_. +Instead of writing regular loops, the latest version of JavaScript introduces lots of built-in methods which can help us solve complicated problems. All built-in methods take callback function. In this section, we will see _forEach_, _map_, _filter_, _reduce_, _find_, _every_, _some_, and _sort_. ### forEach -_forEach_: Iterate an array elements. We use _forEach_ only with arrays. It takes a callback function with elements, index parameter and array itself. The index and the array optional. +_forEach_: Iterate an array of elements. We use _forEach_ only with arrays. It takes a callback function with elements, index parameter and array itself. The index and the array being optional. ```js arr.forEach(function (element, index, arr) { @@ -232,7 +232,7 @@ ICELAND ### map -_map_: Iterate an array elements and modify the array elements. It takes a callback function with elements, index , array parameter and return a new array. +_map_: Iterate an array of elements and modify the array elements. It takes a callback function with elements, index , array parameter and return a new array. ```js const modifiedArray = arr.map(function (element, index, arr) { @@ -308,7 +308,7 @@ const countriesFirstThreeLetters = countries.map((country) => ### filter -_Filter_: Filter out items which full fill filtering conditions and return a new array. +_Filter_: Filter out items which fullfill filtering conditions and return a new array. ```js //Filter countries containing land @@ -550,14 +550,14 @@ console.log(users) // sorted ascending // [{…}, {…}, {…}, {…}] ``` -🌕 You are doing great.Never give up because great things take time. You have just completed day 9 challenges and you are 9 steps a head in to your way to greatness. Now do some exercises for your brain and for your muscle. +🌕 You are doing great.Never give up because great things take time. You have just completed day 9 challenges and you are 9 steps ahead into your way to greatness. Now do some exercises for your brain and for your muscle. ## 💻 Exercises ### Exercises: Level 1 ```js -const countries = ['Finland', 'Sweden', 'Denmark', 'Norway', 'IceLand'] +const countries = ['Estonia', 'Finland', 'Sweden', 'Denmark', 'Norway', 'Iceland'] const names = ['Asabeneh', 'Mathias', 'Elias', 'Brook'] const numbers = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10] const products = [ @@ -577,34 +577,34 @@ const products = [ 5. Use **_forEach_** to console.log each number in the numbers array. 6. Use **_map_** to create a new array by changing each country to uppercase in the countries array. 7. Use **_map_** to create an array of countries length from countries array. -8. Use **_map_** to create a new array by changing each number to square in the numbers array -9. Use **_map_** to change to each name to uppercase in the names array +8. Use **_map_** to create a new array by changing each number to its square in the numbers array +9. Use **_map_** to change each name to uppercase in the names array 10. Use **_map_** to map the products array to its corresponding prices. 11. Use **_filter_** to filter out countries containing **_land_**. 12. Use **_filter_** to filter out countries having six character. 13. Use **_filter_** to filter out countries containing six letters and more in the country array. -14. Use **_filter_** to filter out country start with 'E'; +14. Use **_filter_** to filter out countries starting with 'E'; 15. Use **_filter_** to filter out only prices with values. 16. Declare a function called getStringLists which takes an array as a parameter and then returns an array only with string items. 17. Use **_reduce_** to sum all the numbers in the numbers array. -18. Use **_reduce_** to concatenate all the countries and to produce this sentence: **_Estonia, Finland, Sweden, Denmark, Norway, and IceLand are north European countries_** +18. Use **_reduce_** to concatenate all the countries and to produce this sentence: **_Estonia, Finland, Sweden, Denmark, Norway, and Iceland are north European countries_** 19. Explain the difference between **_some_** and **_every_** 20. Use **_some_** to check if some names' length greater than seven in names array 21. Use **_every_** to check if all the countries contain the word land 22. Explain the difference between **_find_** and **_findIndex_**. 23. Use **_find_** to find the first country containing only six letters in the countries array 24. Use **_findIndex_** to find the position of the first country containing only six letters in the countries array -25. Use **_findIndex_** to find the position of **_Norway_** if it doesn't exist in the array you will get -1. -26. Use **_findIndex_** to find the position of **_Russia_** if it doesn't exist in the array you will get -1. +25. Use **_findIndex_** to find the position of **_Norway_**, if it doesn't exist in the array you will get -1. +26. Use **_findIndex_** to find the position of **_Russia_**, if it doesn't exist in the array you will get -1. ### Exercises: Level 2 1. Find the total price of products by chaining two or more array iterators(eg. arr.map(callback).filter(callback).reduce(callback)) -1. Find the sum of price of products using only reduce reduce(callback)) -1. Declare a function called **_categorizeCountries_** which returns an array of countries which have some common pattern(you find the countries array in this repository as countries.js(eg 'land', 'ia', 'island','stan')). -1. Create a function which return an array of objects, which is the letter and the number of times the letter use to start with a name of a country. +1. Find the sum of price of products using only reduce reduce(callback) +1. Declare a function called **_categorizeCountries_** which returns an array of countries which have some common pattern(you find the countries array in this repository as [countries.js](../09_Day_Higher_order_functions/09_day_starter/data/countries_data.js) (eg 'land', 'ia', 'island','stan')). +1. Create a function which return an array of objects, which is the letter and the number of times the letter is used to start with a name of a country. 1. Declare a **_getFirstTenCountries_** function and return an array of ten countries. Use different functional programming to work on the countries.js array -1. Declare a **_getLastTenCountries_** function which which returns the last ten countries in the countries array. +1. Declare a **_getLastTenCountries_** function which returns the last ten countries in the countries array. 1. Find out which _letter_ is used many _times_ as initial for a country name from the countries array (eg. Finland, Fiji, France etc) ### Exercises: Level 3 @@ -638,7 +638,7 @@ const products = [ ```` -2. \*\*\* Use countries_data.js file create a function which create the ten most populated countries +2. \*\*\* Use countries_data.js file to create a function which create the ten most populated countries ````js console.log(mostPopulatedCountries(countries, 10)) diff --git a/14_Day_Error_handling/14_day_error_handling.md b/14_Day_Error_handling/14_day_error_handling.md new file mode 100644 index 0000000..d9fba8d --- /dev/null +++ b/14_Day_Error_handling/14_day_error_handling.md @@ -0,0 +1,164 @@ +