From 78240d786486e21ff9277f64394c6bbdf1941396 Mon Sep 17 00:00:00 2001 From: loic242 Date: Mon, 5 Dec 2022 00:10:49 +0200 Subject: [PATCH 1/5] Trynna run the array --- .../01_day_starter/helloworld.js | 3 +- 02_Day_Data_types/02_day_starter/main.js | 13 ++++++++- 05_Day_Arrays/05_day_starter/scripts/main.js | 29 +++++++++++++++++-- 3 files changed, 40 insertions(+), 5 deletions(-) diff --git a/01_Day_Introduction/01_day_starter/helloworld.js b/01_Day_Introduction/01_day_starter/helloworld.js index 8c9e2c0..b3721cf 100644 --- a/01_Day_Introduction/01_day_starter/helloworld.js +++ b/01_Day_Introduction/01_day_starter/helloworld.js @@ -1 +1,2 @@ -console.log('Hello, World!') \ No newline at end of file +console.log('Hello, World!') +//Print something with JS code. diff --git a/02_Day_Data_types/02_day_starter/main.js b/02_Day_Data_types/02_day_starter/main.js index 7762908..3572615 100644 --- a/02_Day_Data_types/02_day_starter/main.js +++ b/02_Day_Data_types/02_day_starter/main.js @@ -1 +1,12 @@ -// this is your main.js script \ No newline at end of file +// this is your main.js script + +let string = 'JavaScript' +let firstLetter = string[0] +console.log(firstLetter) // J +let secondLetter = string[1] // a +let thirdLetter = string[2] +let lastLetter = string[9] +console.log(lastLetter) // t +let lastIndex = string.length - 1 +console.log(lastIndex) // 9 +console.log(string[lastIndex]) // t diff --git a/05_Day_Arrays/05_day_starter/scripts/main.js b/05_Day_Arrays/05_day_starter/scripts/main.js index 50cc07e..3c5fa30 100644 --- a/05_Day_Arrays/05_day_starter/scripts/main.js +++ b/05_Day_Arrays/05_day_starter/scripts/main.js @@ -1,3 +1,26 @@ -console.log(countries) -alert('Open the browser console whenever you work on JavaScript') -alert('Open the console and check if the countries has been loaded') \ No newline at end of file +const numbers = [0, 3.14, 9.81, 37, 98.6, 100] // array of numbers +const fruits = ['banana', 'orange', 'mango', 'lemon'] // array of strings, fruits +const vegetables = ['Tomato', 'Potato', 'Cabbage', 'Onion', 'Carrot'] // array of strings, vegetables +const animalProducts = ['milk', 'meat', 'butter', 'yoghurt'] // array of strings, products +const webTechs = ['HTML', 'CSS', 'JS', 'React', 'Redux', 'Node', 'MongDB'] // array of web technologies +const countrie = ['Finland', 'Denmark', 'Sweden', 'Norway', 'Iceland'] // array of strings, countries + +// Print the array and its length + +console.log('Numbers:', numbers) +console.log('Number of numbers:', numbers.length) + +console.log('Fruits:', fruits) +console.log('Number of fruits:', fruits.length) + +console.log('Vegetables:', vegetables) +console.log('Number of vegetables:', vegetables.length) + +console.log('Animal products:', animalProducts) +console.log('Number of animal products:', animalProducts.length) + +console.log('Web technologies:', webTechs) +console.log('Number of web technologies:', webTechs.length) + +console.log('Countries:', countrie) +console.log('Number of countries:', countrie.length) From 46a73e736942ff73087d01f8d70c47d196f9460a Mon Sep 17 00:00:00 2001 From: loic242 Date: Mon, 5 Dec 2022 00:49:20 +0200 Subject: [PATCH 2/5] Convert an Array to string --- 05_Day_Arrays/05_day_starter/scripts/main.js | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/05_Day_Arrays/05_day_starter/scripts/main.js b/05_Day_Arrays/05_day_starter/scripts/main.js index 3c5fa30..be55652 100644 --- a/05_Day_Arrays/05_day_starter/scripts/main.js +++ b/05_Day_Arrays/05_day_starter/scripts/main.js @@ -24,3 +24,16 @@ console.log('Number of web technologies:', webTechs.length) console.log('Countries:', countrie) console.log('Number of countries:', countrie.length) + +const arr = [ + 'Asabeneh', + 250, + true, + { country: 'Finland', city: 'Helsinki' }, + { skills: ['HTML', 'CSS', 'JS', 'React', 'Python'] } +] // arr containing different data types +console.log(arr) + +console.log(countries.includes('Congo')) +console.log(countries.indexOf('Congo')) +console.log(countries[39]) \ No newline at end of file From f79682437353579f9a289aadc1f90eaeb0e24a08 Mon Sep 17 00:00:00 2001 From: loic242 Date: Mon, 5 Dec 2022 01:04:45 +0200 Subject: [PATCH 3/5] Empty array --- 05_Day_Arrays/05_day_starter/scripts/main.js | 98 ++++++++++++-------- 1 file changed, 59 insertions(+), 39 deletions(-) diff --git a/05_Day_Arrays/05_day_starter/scripts/main.js b/05_Day_Arrays/05_day_starter/scripts/main.js index be55652..7846a1c 100644 --- a/05_Day_Arrays/05_day_starter/scripts/main.js +++ b/05_Day_Arrays/05_day_starter/scripts/main.js @@ -1,39 +1,59 @@ -const numbers = [0, 3.14, 9.81, 37, 98.6, 100] // array of numbers -const fruits = ['banana', 'orange', 'mango', 'lemon'] // array of strings, fruits -const vegetables = ['Tomato', 'Potato', 'Cabbage', 'Onion', 'Carrot'] // array of strings, vegetables -const animalProducts = ['milk', 'meat', 'butter', 'yoghurt'] // array of strings, products -const webTechs = ['HTML', 'CSS', 'JS', 'React', 'Redux', 'Node', 'MongDB'] // array of web technologies -const countrie = ['Finland', 'Denmark', 'Sweden', 'Norway', 'Iceland'] // array of strings, countries - -// Print the array and its length - -console.log('Numbers:', numbers) -console.log('Number of numbers:', numbers.length) - -console.log('Fruits:', fruits) -console.log('Number of fruits:', fruits.length) - -console.log('Vegetables:', vegetables) -console.log('Number of vegetables:', vegetables.length) - -console.log('Animal products:', animalProducts) -console.log('Number of animal products:', animalProducts.length) - -console.log('Web technologies:', webTechs) -console.log('Number of web technologies:', webTechs.length) - -console.log('Countries:', countrie) -console.log('Number of countries:', countrie.length) - -const arr = [ - 'Asabeneh', - 250, - true, - { country: 'Finland', city: 'Helsinki' }, - { skills: ['HTML', 'CSS', 'JS', 'React', 'Python'] } -] // arr containing different data types -console.log(arr) - -console.log(countries.includes('Congo')) -console.log(countries.indexOf('Congo')) -console.log(countries[39]) \ No newline at end of file +// //Exercise in Array +// Exercise Level 1 +/** + * + * ## 💻 Exercise + +### Exercise: Level 1 + +```js +const countries = [ + 'Albania', + 'Bolivia', + 'Canada', + 'Denmark', + 'Ethiopia', + 'Finland', + 'Germany', + 'Hungary', + 'Ireland', + 'Japan', + 'Kenya' +] + +const webTechs = [ + 'HTML', + 'CSS', + 'JavaScript', + 'React', + 'Redux', + 'Node', + 'MongoDB' +] +``` + +1. Declare an _empty_ array; +2. Declare an array with more than 5 number of elements +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 +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. +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 +15. Sort the array using _sort()_ method +16. Reverse the array using _reverse()_ method +17. Slice out the first 3 companies from the array +18. Slice out the last 3 companies from the array +19. Slice out the middle IT company or companies from the array +20. Remove the first IT company from the array +21. Remove the middle IT company or companies from the array +22. Remove the last IT company from the array +23. Remove all IT companies + */ +let myArr = Array(); //Empty array \ No newline at end of file From 434b18dfa9b6e84bfa4b31b6da191b894570076f Mon Sep 17 00:00:00 2001 From: loic242 Date: Mon, 5 Dec 2022 01:10:46 +0200 Subject: [PATCH 4/5] Question 3 of exercise --- 05_Day_Arrays/05_day_starter/scripts/main.js | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/05_Day_Arrays/05_day_starter/scripts/main.js b/05_Day_Arrays/05_day_starter/scripts/main.js index 7846a1c..094720c 100644 --- a/05_Day_Arrays/05_day_starter/scripts/main.js +++ b/05_Day_Arrays/05_day_starter/scripts/main.js @@ -56,4 +56,7 @@ const webTechs = [ 22. Remove the last IT company from the array 23. Remove all IT companies */ -let myArr = Array(); //Empty array \ No newline at end of file +let myArr = Array(); //Empty array +const animals = ['lion','dog','cat','pig','monkey']; +const myArrayLength = animals.length(); +console.log(myArrayLength) \ No newline at end of file From 3891df6485acda1b5728c3c508b3b211dfc4fa70 Mon Sep 17 00:00:00 2001 From: loic242 Date: Mon, 5 Dec 2022 23:04:44 +0200 Subject: [PATCH 5/5] code --- 05_Day_Arrays/05_day_starter/scripts/main.js | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/05_Day_Arrays/05_day_starter/scripts/main.js b/05_Day_Arrays/05_day_starter/scripts/main.js index 094720c..ee14bd8 100644 --- a/05_Day_Arrays/05_day_starter/scripts/main.js +++ b/05_Day_Arrays/05_day_starter/scripts/main.js @@ -56,7 +56,8 @@ const webTechs = [ 22. Remove the last IT company from the array 23. Remove all IT companies */ -let myArr = Array(); //Empty array + //Empty array const animals = ['lion','dog','cat','pig','monkey']; -const myArrayLength = animals.length(); -console.log(myArrayLength) \ No newline at end of file +console.log(`This is my array: ${animals}`) +const myArrayLength = animals.length; +console.log(`This array length is: ${myArrayLength}`);