diff --git a/.DS_Store b/.DS_Store new file mode 100644 index 0000000..ff3a867 Binary files /dev/null and b/.DS_Store differ diff --git a/03_Day_Setting_Up/.DS_Store b/03_Day_Setting_Up/.DS_Store new file mode 100644 index 0000000..1d95ef9 Binary files /dev/null and b/03_Day_Setting_Up/.DS_Store differ diff --git a/04_Day_Components/.DS_Store b/04_Day_Components/.DS_Store new file mode 100644 index 0000000..626320e Binary files /dev/null and b/04_Day_Components/.DS_Store differ diff --git a/exercise-solutions/.DS_Store b/exercise-solutions/.DS_Store new file mode 100644 index 0000000..1e53ccd Binary files /dev/null and b/exercise-solutions/.DS_Store differ diff --git a/exercise-solutions/day1/.gitignore b/exercise-solutions/day1/.gitignore new file mode 100644 index 0000000..6d0ee45 --- /dev/null +++ b/exercise-solutions/day1/.gitignore @@ -0,0 +1,2 @@ +.vscode +.DS_Store \ No newline at end of file diff --git a/exercise-solutions/day1/1.array.html b/exercise-solutions/day1/1.array.html new file mode 100644 index 0000000..5741a89 --- /dev/null +++ b/exercise-solutions/day1/1.array.html @@ -0,0 +1,101 @@ + + + + + + + Day 1 : JS refresher + + + +

Hello

+ + + + + + + \ No newline at end of file diff --git a/exercise-solutions/day1/1.array.js b/exercise-solutions/day1/1.array.js new file mode 100644 index 0000000..a88f16d --- /dev/null +++ b/exercise-solutions/day1/1.array.js @@ -0,0 +1,120 @@ +//Exercise 1 +let myArr = ['Nam', 17, true, { country: 'Vietnam', city: 'Ho chi minh' }, { skills: ['html,css,js'] }]; +console.log('my Array: '+myArr); +console.log('my Array length: ' + myArr.length); +console.log("First item: " + myArr[0]); +console.log("Middle item: " + myArr[Math.floor(myArr.length / 2)]); +console.log("Last item: " + myArr[myArr.length - 1]); + +const itCompany = ['Facebook', 'Google', 'Microsoft', 'Apple', 'IBM', 'Oracle', 'Amazon']; +console.log(itCompany); +console.log(itCompany.length); +console.log(itCompany[0], itCompany[Math.floor(itCompany.length / 2)], itCompany[itCompany.length - 1]); +itCompany.forEach(com => { + console.log(com.toUpperCase()); +}); + +itCompany.includes('Nam') ? 1 : 0; +// Filter out companies which have more than one 'o' without the filter method +itCompany.forEach(com => { + const temp = com.split(''); + let count = 0; + for (let i = 0; i < temp.length; i++) { + if (temp[i] == 'o') count++; + } + if (count > 1) console.log(com); +}); +/** + * Sort the array using sort() method +Reverse the array using reverse() method + */ +console.log(itCompany.sort()); +console.log(itCompany.reverse()); + +/** + * Slice out the first 3 companies from the array +Slice out the last 3 companies from the array +Slice out the middle IT company or companies from the array + */ +console.log(itCompany.slice(0, 2)); +console.log(itCompany.slice(itCompany.length - 3, itCompany.length - 1)); +console.log(itCompany.slice(Math.floor(itCompany.length / 2), Math.floor(itCompany.length / 2) + 1)); +/* +Remove the first IT company from the array +Remove the middle IT company or companies from the array +Remove the last IT company from the array +Remove all IT companies +*/ +console.log(itCompany.shift()); +console.log(itCompany.splice(Math.floor(itCompany.length / 2), 1)); +console.log(itCompany.pop()); +console.log(itCompany.splice()); + + +//exercise 2 +let text ='I love teaching and empowering people. I teach HTML, CSS, JS, React, Python.'; +let words = text.split('.').join('').split(' '); +console.log(words); +console.log(words.length); + +const shoppingCart = ['Milk', 'Coffee', 'Tea', 'Honey']; +/** + * add 'Meat' in the beginning of your shopping cart if it has not been already added +add Sugar at the end of you shopping cart if it has not been already added +remove 'Honey' if you are allergic to honey +modify Tea to 'Green Tea' + */ + +if (!shoppingCart.includes('Meat')) shoppingCart.unshift('Meat'); +if (!shoppingCart.includes('Sugar')) shoppingCart.push('Sugar'); +const indexOfHoney = shoppingCart.indexOf('Honey'); +shoppingCart.splice(indexOfHoney, 1); +const indexOfTea = shoppingCart.indexOf('Tea'); +shoppingCart[indexOfTea] = 'Green Tea'; + + +//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. +countries.includes('Ethiopia') ? console.log('Ethiopia') : countries.push('Ethiopia'); + +//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. +webtechs.includes('Sass') ? console.log('Sass is a CSS preprocess') : webtechs.push('Sass'); console.log(webtechs); +// Concatenate the following two variables and store it in a fullStack variable. +const frontEnd = ['HTML', 'CSS', 'JS', 'React', 'Redux']; +const backEnd = ['Node', 'Express', 'MongoDB']; +const fullStack = frontEnd.concat(backEnd); +console.log('Fullstack: ' + fullStack); +//Excersie 3 +// The following is an array of 10 students ages: js const ages = [19, 22, 19, 24, 20, 25, 26, 24, 25, 24] - Sort the array and find the min and max age - Find the median age(one middle item or two middle items divided by two) - 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 +const ages = [19, 22, 19, 24, 20, 25, 26, 24, 25, 24]; +console.log(ages.sort()); +agesMedianIdx = (ages.length - 1) / 2; +console.log("median age: " + ages[Math.floor(agesMedianIdx)]); +let totalAge = 0; +ages.forEach(age => { + totalAge += age; +}); +const avgAge = totalAge / ages.length; +console.log("Average age: " + avgAge); +const minAge = Math.min(...ages); +console.log("Min age: " + minAge); +const maxAge = Math.max(...ages); +console.log("Max age: " + maxAge); +console.log("Range of the ages: " + (maxAge - minAge)); +console.log("Compare min vs avg: " + Math.abs(minAge - avgAge)); +console.log("Compare max vs avg: " + Math.abs(maxAge - avgAge)); +// 1.Slice the first ten countries from the countries array +console.log("first ten countries: " + countries.slice(0, 10)); +// Find the middle country(ies) in the countries array +const countryMid = countries.length/2; +console.log("middle country: " + countries.slice(countryMid, countryMid + 1)); +// 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. +let firstHalfCountries = []; +let secondHalfCountries = []; +for (let i = 0; i < countries.length; i++) { + const con = countries[i]; + if (i <= countryMid) { firstHalfCountries.push(con);} + else { secondHalfCountries.push(con); } + +} +console.log("first half: " + firstHalfCountries); +console.log("second half: " + secondHalfCountries); \ No newline at end of file diff --git a/exercise-solutions/day1/1.countries.js b/exercise-solutions/day1/1.countries.js new file mode 100644 index 0000000..2a653a1 --- /dev/null +++ b/exercise-solutions/day1/1.countries.js @@ -0,0 +1,13 @@ + let countries = [ + 'Albania', + 'Bolivia', + 'Canada', + 'Denmark', + 'Ethiopia', + 'Finland', + 'Germany', + 'Hungary', + 'Ireland', + 'Japan', + 'Kenya', +] diff --git a/exercise-solutions/day1/1.web_techs.js b/exercise-solutions/day1/1.web_techs.js new file mode 100644 index 0000000..52bf291 --- /dev/null +++ b/exercise-solutions/day1/1.web_techs.js @@ -0,0 +1,9 @@ + var webtechs = [ + 'HTML', + 'CSS', + 'JavaScript', + 'React', + 'Redux', + 'Node', + 'MongoDB', +]; \ No newline at end of file diff --git a/exercise-solutions/day1/2.conditionalStatement.html b/exercise-solutions/day1/2.conditionalStatement.html new file mode 100644 index 0000000..3b7e9c1 --- /dev/null +++ b/exercise-solutions/day1/2.conditionalStatement.html @@ -0,0 +1,42 @@ + + + + + + + If-else conditional statement + + + + + + + + \ No newline at end of file diff --git a/exercise-solutions/day1/3.object.html b/exercise-solutions/day1/3.object.html new file mode 100644 index 0000000..56fcc11 --- /dev/null +++ b/exercise-solutions/day1/3.object.html @@ -0,0 +1,211 @@ + + + + + + + Object + + + + + + + + \ No newline at end of file diff --git a/exercise-solutions/day1/4.function.html b/exercise-solutions/day1/4.function.html new file mode 100644 index 0000000..ed7128e --- /dev/null +++ b/exercise-solutions/day1/4.function.html @@ -0,0 +1,81 @@ + + + + + + + Function + + + + + + + + \ No newline at end of file diff --git a/exercise-solutions/day1/5.destructuring.html b/exercise-solutions/day1/5.destructuring.html new file mode 100644 index 0000000..fd50c91 --- /dev/null +++ b/exercise-solutions/day1/5.destructuring.html @@ -0,0 +1,45 @@ + + + + + + + Destructuring + + + + + + + + \ No newline at end of file diff --git a/exercise-solutions/day1/6.programmingFunction.html b/exercise-solutions/day1/6.programmingFunction.html new file mode 100644 index 0000000..73a9852 --- /dev/null +++ b/exercise-solutions/day1/6.programmingFunction.html @@ -0,0 +1,86 @@ + + + + + + + Programming function + + + + + + + + \ No newline at end of file diff --git a/exercise-solutions/day1/7.class.html b/exercise-solutions/day1/7.class.html new file mode 100644 index 0000000..3ee73a6 --- /dev/null +++ b/exercise-solutions/day1/7.class.html @@ -0,0 +1,151 @@ + + + + + + + Class + + + + + + + + + + \ No newline at end of file