From 416564be38f57ae25ace40404b12b6365b9a0f45 Mon Sep 17 00:00:00 2001 From: Yiorgos Bagakis Date: Sun, 11 Oct 2020 22:05:20 +0200 Subject: [PATCH 1/7] arrays: exercise level1 complete --- solutions/day-01/.DS_Store | Bin 0 -> 6148 bytes solutions/day-01/level1.js | 92 +++++++++++++++++++++++++++++++++++++ 2 files changed, 92 insertions(+) create mode 100644 solutions/day-01/.DS_Store create mode 100644 solutions/day-01/level1.js diff --git a/solutions/day-01/.DS_Store b/solutions/day-01/.DS_Store new file mode 100644 index 0000000000000000000000000000000000000000..5008ddfcf53c02e82d7eee2e57c38e5672ef89f6 GIT binary patch literal 6148 zcmeH~Jr2S!425mzP>H1@V-^m;4Wg<&0T*E43hX&L&p$$qDprKhvt+--jT7}7np#A3 zem<@ulZcFPQ@L2!n>{z**++&mCkOWA81W14cNZlEfg7;MkzE(HCqgga^y>{tEnwC%0;vJ&^%eQ zLs35+`xjp>T0 Date: Mon, 12 Oct 2020 21:54:32 +0200 Subject: [PATCH 2/7] day 1 level 2 exercise solutions --- solutions/day-01/countries.js | 13 +++++++++++ solutions/day-01/main.js | 43 +++++++++++++++++++++++++++++++++++ solutions/day-01/webTechs.js | 9 ++++++++ 3 files changed, 65 insertions(+) create mode 100644 solutions/day-01/countries.js create mode 100644 solutions/day-01/main.js create mode 100644 solutions/day-01/webTechs.js diff --git a/solutions/day-01/countries.js b/solutions/day-01/countries.js new file mode 100644 index 0000000..1fba8f5 --- /dev/null +++ b/solutions/day-01/countries.js @@ -0,0 +1,13 @@ +const countries = [ + 'Albania', + 'Bolivia', + 'Canada', + 'Denmark', + 'Ethiopia', + 'Finland', + 'Germany', + 'Hungary', + 'Ireland', + 'Japan', + 'Kenya', +] diff --git a/solutions/day-01/main.js b/solutions/day-01/main.js new file mode 100644 index 0000000..db26851 --- /dev/null +++ b/solutions/day-01/main.js @@ -0,0 +1,43 @@ +//1. Create a separate countries.js file and store the countries array into this file, create a separate file web_techs.js and store the webTechs array into this file. Access both file in main.js file +import { countries } from './countries.js'; +import { webTechs } from './webTechs.js'; + +//2. First remove all the punctuations and change the string to array and count the number of words in the array +let text = + 'I love teaching and empowering people. I teach HTML, CSS, JS, React, Python.' + +const words = text.split(" "); + +console.log(words); +console.log(words.length); + +//3. In the following shopping cart add, remove, edit items +const shoppingCart = ['Milk', 'Coffee', 'Tea', 'Honey'] + + //add 'Meat' in the beginning of your shopping cart if it has not been already added + shoppingCart.shift(); + shoppingCart.unshift('Meat'); + + //add Sugar at the end of you shopping cart if it has not been already added + shoppingCart.push('Sugar'); + + //remove 'Honey' if you are allergic to honey + shoppingCart.splice(3,1); + + //modify Tea to 'Green Tea' + shoppingCart[2] = 'Green Tea'; + +//4. 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. +let ETH = countries.includes('Ethiopia') +ETH ? (console.log('ETHIOPIA')) : countries.push('Ethiopia') + +//5. 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); + + +//6. 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); diff --git a/solutions/day-01/webTechs.js b/solutions/day-01/webTechs.js new file mode 100644 index 0000000..093a0ec --- /dev/null +++ b/solutions/day-01/webTechs.js @@ -0,0 +1,9 @@ +const webTechs = [ + 'HTML', + 'CSS', + 'JavaScript', + 'React', + 'Redux', + 'Node', + 'MongoDB', +] From a60138499165818e3452cbe4a3efd836444d5c78 Mon Sep 17 00:00:00 2001 From: bagaski Date: Mon, 12 Oct 2020 22:13:49 +0200 Subject: [PATCH 3/7] day 01 - Level 1 & 2 Solutions --- solutions/day-01/countries.js | 3 +++ solutions/day-01/level1.js | 2 ++ solutions/day-01/main.js | 2 ++ solutions/day-01/webTechs.js | 2 ++ 4 files changed, 9 insertions(+) diff --git a/solutions/day-01/countries.js b/solutions/day-01/countries.js index 1fba8f5..666fbeb 100644 --- a/solutions/day-01/countries.js +++ b/solutions/day-01/countries.js @@ -11,3 +11,6 @@ const countries = [ 'Japan', 'Kenya', ] + + +//by bagaski diff --git a/solutions/day-01/level1.js b/solutions/day-01/level1.js index 133a9b9..54c7dee 100644 --- a/solutions/day-01/level1.js +++ b/solutions/day-01/level1.js @@ -90,3 +90,5 @@ itCompanies.pop(); //22. Remove all IT companies itCompanies.splice(); + +//by bagaski diff --git a/solutions/day-01/main.js b/solutions/day-01/main.js index db26851..80949e7 100644 --- a/solutions/day-01/main.js +++ b/solutions/day-01/main.js @@ -41,3 +41,5 @@ const backEnd = ['Node', 'Express', 'MongoDB']; const fullStack = frontEnd.concat(backEnd); console.log(fullStack); + +//by bagaski diff --git a/solutions/day-01/webTechs.js b/solutions/day-01/webTechs.js index 093a0ec..2025b82 100644 --- a/solutions/day-01/webTechs.js +++ b/solutions/day-01/webTechs.js @@ -7,3 +7,5 @@ const webTechs = [ 'Node', 'MongoDB', ] + +//by bagaski From 67dcc7f684512762cfce3f55485627377829a309 Mon Sep 17 00:00:00 2001 From: bagaski Date: Tue, 13 Oct 2020 09:08:30 +0200 Subject: [PATCH 4/7] Arrays exercises Level 3 --- solutions/day-01/level3.js | 32 ++++++++++++++++++++++++++++++++ 1 file changed, 32 insertions(+) create mode 100644 solutions/day-01/level3.js diff --git a/solutions/day-01/level3.js b/solutions/day-01/level3.js new file mode 100644 index 0000000..ed99be2 --- /dev/null +++ b/solutions/day-01/level3.js @@ -0,0 +1,32 @@ +import { countries } from './countries.js'; + + +//1. The following is an array of 10 students ages: +const ages = [19, 22, 19, 24, 20, 25, 26, 24, 25, 24] + +//Sort the array and find the min and max age +const agesOrder = ages.sort(); +const minAge = agesOrder[0]; +const maxAge = agesOrder[agesOrder.length - 1]; + +//Find the median age(one middle item or two middle items divided by two) +const medianAge = agesOrder[agesOrder.length * 0.5]; + +//Find the average age(all items divided by number of items) +const averageAge; //do i need 'for' loop? + +//Find the range of the ages(max minus min) +const rangeOfAges = maxAge - minAge; + +//Compare the value of (min - average) and (max - average), use abs() method + + +//2. Slice the first ten countries from the countries array +let sliceFirstTenCuuntries = countries.slice(0, 11); + +//3. Find the middle country(ies) in the countries array +const middleCountries = countries[countries.length * 0.5]; + +//4. 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. +const firstCountries = countries.slice(0, countries.length * 0.5 + 1); +const secondCountries = countries.slice(countries.length * 0.5 - 1 , countries.length - 1) From 3d66c60977fc2a4777865b6d6f61d73a0bc1ab5e Mon Sep 17 00:00:00 2001 From: bagaski Date: Tue, 13 Oct 2020 22:31:08 +0200 Subject: [PATCH 5/7] day 01 - condirionals-1 excersise --- solutions/day-01/conditionals-1.js | 37 ++++++++++++++++++++++++++++++ 1 file changed, 37 insertions(+) create mode 100644 solutions/day-01/conditionals-1.js diff --git a/solutions/day-01/conditionals-1.js b/solutions/day-01/conditionals-1.js new file mode 100644 index 0000000..f8aa953 --- /dev/null +++ b/solutions/day-01/conditionals-1.js @@ -0,0 +1,37 @@ + + + //1. Get user input using prompt(“Enter your age:”). If user is 18 or older , give feedback:'You are old enough to drive' but if not 18 give another feedback stating to wait for the number of years he needs to turn 18. + let age = prompt('Enter your age: '); + + if (age >= 18) { + alert('You are old enough to drive.') + } else { + alert(`You are left with ${18 - age} years to drive`) + }; + + + + + //2. Compare the values of myAge and yourAge using if … else. Based on the comparison and log the result to console stating who is older (me or you). Use prompt(“Enter your age:”) to get the age as input. + let myAge = 42; + let yourAge = prompt('Enter your age: '); + + if (yourAge > myAge) { alert(`you are ${yourAge - myAge} years older than me`) } + else if (yourAge < myAge) { alert(`you are ${myAge - yourAge} years younger than me`) } + else { alert('we have the same age!') + }; + + + + //3. 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" and "ternary operator". + let a = 4; + let b = 3; + + a > b ? console.log('a is greater than b') : console.log('a is less than b'); + + if (a>b) {console.log('a is greater than b')} else {console.log('a is less than b')}; + + //4. Even numbers are divisible by 2 and the remainder is zero. How do you check, if a number is even or not using JavaScript? + let evenOrOddNumber = prompt('Enter a number: ') + if (evenOrOddNumber % 2 == 0 ) {`${evenOrOddNumber} is an even number`} + else {`${evenOrOddNumber} is an odd number`} From 51d1e298b34f30e2fa654a5c8d496935838615dd Mon Sep 17 00:00:00 2001 From: bagaski Date: Wed, 14 Oct 2020 23:51:35 +0200 Subject: [PATCH 6/7] conditionals level2 --- solutions/day-01/conditionals-2.js | 32 ++++++++++++++++++++++++++++++ 1 file changed, 32 insertions(+) create mode 100644 solutions/day-01/conditionals-2.js diff --git a/solutions/day-01/conditionals-2.js b/solutions/day-01/conditionals-2.js new file mode 100644 index 0000000..2cf7408 --- /dev/null +++ b/solutions/day-01/conditionals-2.js @@ -0,0 +1,32 @@ +//1. Write a code which can give grades to students according to theirs scores: + + //90-100, A + //70-89, B + //60-69, C + //50-59, D + //0-49, F + + + function gradeGenerator() { + let grade = Math.floor(Math.random() * 100) + + switch(true) { + + case (grade > 89) : + document.getElementById("result").innerHTML = "Your grade is: " + grade + "% (A)" + break; + + case (grade > 69 && grade < 90) : document.getElementById("result").innerHTML = "Your grade is: " + grade + "% (B)" + break; + + case (grade > 59 && grade < 70) : document.getElementById("result").innerHTML = "Your grade is: " + grade + "% (C)" + break; + + case (grade > 49 && grade < 60) : document.getElementById("result").innerHTML = "Your grade is: " + grade + "% (D)" + break; + + case (grade < 50) : document.getElementById("result").innerHTML = "Your grade is: " + grade + "% (F)" + break; + + } + } From 9d4415e83b4a4bb3a5d60c372e92af5d8a414acf Mon Sep 17 00:00:00 2001 From: bagaski Date: Fri, 16 Oct 2020 15:33:38 +0200 Subject: [PATCH 7/7] day01 exercises conditionals level 3 --- solutions/day-01/conditionals-3.js | 26 ++++++++++++++++++++++++++ 1 file changed, 26 insertions(+) create mode 100644 solutions/day-01/conditionals-3.js diff --git a/solutions/day-01/conditionals-3.js b/solutions/day-01/conditionals-3.js new file mode 100644 index 0000000..dae2fad --- /dev/null +++ b/solutions/day-01/conditionals-3.js @@ -0,0 +1,26 @@ + + //1. Write a program which tells the number of days in a month. + + //Enter a month: January + //January has 31 days. + + //Enter a month: JANUARY + //January has 31 day + + //Enter a month: February + //February has 28 days. + + //Enter a month: FEbruary + //February has 28 days. + + let month = prompt('Enter a month: '); + let monthCap = month.toUpperCase(); + + if ((monthCap == 'JANUARY') || (monthCap =='MARCH') || (monthCap =='MAY') || (monthCap =='JULY') || (monthCap =='AUGUST') || (monthCap =='OCTOBER') || (monthCap =='DECEMBER')) {alert(`${monthCap} has 31 days`)} + + else if (monthCap == 'FEBRUARY') {alert(`FEBRUARY has 28 days and every four years 29 days`)} + + else if ((monthCap == 'APRIL') || (monthCap =='JUNE') || (monthCap =='SEPTEMBER') || (monthCap =='NOVEMBER')){alert(`${monthCap} has 30 days`)} + + else {alert(`${monthCap} is either not a month or you misspelled + the month`)}