From de083fd5a17128b6f52ac974d44f3b9be85a6cc6 Mon Sep 17 00:00:00 2001 From: drixesxs Date: Thu, 4 Jan 2024 16:11:52 +0100 Subject: [PATCH 1/3] Trying --- solutions/DAY-01/ARRAYS/countries.js | 15 ++++++++++++++ solutions/DAY-01/ARRAYS/level1.js | 29 ++++++++++++++++++++++++++++ solutions/DAY-01/ARRAYS/main.js | 6 ++++++ solutions/DAY-01/ARRAYS/web_techs.js | 9 +++++++++ 4 files changed, 59 insertions(+) create mode 100644 solutions/DAY-01/ARRAYS/countries.js create mode 100644 solutions/DAY-01/ARRAYS/level1.js create mode 100644 solutions/DAY-01/ARRAYS/main.js create mode 100644 solutions/DAY-01/ARRAYS/web_techs.js diff --git a/solutions/DAY-01/ARRAYS/countries.js b/solutions/DAY-01/ARRAYS/countries.js new file mode 100644 index 0000000..6d35241 --- /dev/null +++ b/solutions/DAY-01/ARRAYS/countries.js @@ -0,0 +1,15 @@ +const countries = [ + 'Albania', + 'Bolivia', + 'Canada', + 'Denmark', + 'Ethiopia', + 'Finland', + 'Germany', + 'Hungary', + 'Ireland', + 'Japan', + 'Kenya', + ] + + \ No newline at end of file diff --git a/solutions/DAY-01/ARRAYS/level1.js b/solutions/DAY-01/ARRAYS/level1.js new file mode 100644 index 0000000..6feed3e --- /dev/null +++ b/solutions/DAY-01/ARRAYS/level1.js @@ -0,0 +1,29 @@ +const arr = [] +const arr5 = [1,2,3,4,5,6,7] + + +let mixedDataTypes = [1, 2, 3, "Man", [5,6], ['Man', 'Woman']] +console.log("Length of mixedDataType: " + mixedDataTypes.length) + +let itCompanies = ['Facebook', 'Google', 'Microsoft', 'Apple', 'IBM', 'Oracle', 'Amazon'] + +/*console.log("ITCompanies: " + itCompanies) +console.log("There are " + itCompanies.length + " companies") +console.log(itCompanies[0]) +console.log(itCompanies[3]) +console.log(itCompanies[itCompanies.length-1]) +*/ + +for(let i=0; i Date: Fri, 5 Jan 2024 17:03:22 +0100 Subject: [PATCH 2/3] Day 1 cont'd --- solutions/DAY-01/ARRAYS/countries.js | 1 + solutions/DAY-01/ARRAYS/level3.js | 41 +++++++++++++ solutions/DAY-01/ARRAYS/main.js | 47 +++++++++++++-- solutions/DAY-01/ARRAYS/web_techs.js | 4 +- .../DAY-01/CONDITIONALS/level1 copy.html | 30 ++++++++++ solutions/DAY-01/CONDITIONALS/level1.js | 41 +++++++++++++ solutions/DAY-01/CONDITIONALS/level2.js | 57 +++++++++++++++++++ solutions/DAY-01/CONDITIONALS/level3.js | 4 ++ 8 files changed, 220 insertions(+), 5 deletions(-) create mode 100644 solutions/DAY-01/ARRAYS/level3.js create mode 100644 solutions/DAY-01/CONDITIONALS/level1 copy.html create mode 100644 solutions/DAY-01/CONDITIONALS/level1.js create mode 100644 solutions/DAY-01/CONDITIONALS/level2.js create mode 100644 solutions/DAY-01/CONDITIONALS/level3.js diff --git a/solutions/DAY-01/ARRAYS/countries.js b/solutions/DAY-01/ARRAYS/countries.js index 6d35241..381a2c6 100644 --- a/solutions/DAY-01/ARRAYS/countries.js +++ b/solutions/DAY-01/ARRAYS/countries.js @@ -12,4 +12,5 @@ const countries = [ 'Kenya', ] + module.exports = countries \ No newline at end of file diff --git a/solutions/DAY-01/ARRAYS/level3.js b/solutions/DAY-01/ARRAYS/level3.js new file mode 100644 index 0000000..d0e85d5 --- /dev/null +++ b/solutions/DAY-01/ARRAYS/level3.js @@ -0,0 +1,41 @@ +const ages = [19, 22, 19, 24, 20, 25, 26, 24, 25, 24]; + +// Sort the array and find the min and max age +ages.sort((a, b) => a - b); +const minAge = ages[0]; +const maxAge = ages[ages.length - 1]; + +// Find the median age (one middle item or two middle items divided by two) +const middleIndex = Math.floor(ages.length / 2); +const medianAge = ages.length % 2 === 0 ? (ages[middleIndex - 1] + ages[middleIndex]) / 2 : ages[middleIndex]; + +// Find the average age (all items divided by number of items) +const sumOfAges = ages.reduce((total, age) => total + age, 0); +const averageAge = sumOfAges / ages.length; + +// Find the range of the ages (max minus min) +const ageRange = maxAge - minAge; + +// Compare the value of (min - average) and (max - average), use abs() method +const diffMinAverage = Math.abs(minAge - averageAge); +const diffMaxAverage = Math.abs(maxAge - averageAge); + +console.log(`Sorted array of ages: ${ages}`); +console.log(`Minimum age: ${minAge}`); +console.log(`Maximum age: ${maxAge}`); +console.log(`Median age: ${medianAge}`); +console.log(`Average age: ${averageAge}`); +console.log(`Age range: ${ageRange}`); +console.log(`Absolute difference between minimum age and average age: ${diffMinAverage}`); +console.log(`Absolute difference between maximum age and average age: ${diffMaxAverage}`); + + + +const firstTenCountries = countries.slice(0, 10); +const midd = Math.floor(countries.length / 2); +const middleCountry = countries[midd]; + + +const halfLength = Math.ceil(countries.length / 2); +const firstHalf = countries.slice(0, halfLength); +const secondHalf = countries.slice(halfLength); diff --git a/solutions/DAY-01/ARRAYS/main.js b/solutions/DAY-01/ARRAYS/main.js index 9b49a9e..4ad0d16 100644 --- a/solutions/DAY-01/ARRAYS/main.js +++ b/solutions/DAY-01/ARRAYS/main.js @@ -1,6 +1,45 @@ -import * as countries from './countries'; -import * as webtech from './web_techs'; +const countries = require('./countries') +const webTechs = require('./web_techs.js') -console.log(webTechs) -console.log(countries) +let text = 'I love teaching and empowering people I teach HTML CSS JS React Python' + +const text_arr = text.split(" ") +console.log(text_arr + "\n" + text_arr.length) + +let shoppingCart = ['Milk', 'Coffee', 'Tea', 'Honey'] +shoppingCart.unshift("Meat") +shoppingCart.pop() +shoppingCart[3] = "Green Tea" +shoppingCart.push("Sugar") + + +let num = countries.indexOf("Ethiopia") + +if (num = -1) { + countries.push("ethiopia") + console.log(countries) +} +else{ + console.log("ETHIOPIA") +} + + +let tech_num = webTechs.indexOf("Sass") + + +if (tech_num = -1){ + webTechs.push("Sass") + console.log(webTechs) +} +else{ + console.log("Sass is a css process") +} + + +const frontEnd = ['HTML', 'CSS', 'JS', 'React', 'Redux'] +const backEnd = ['Node', 'Express', 'MongoDB'] + +const fullStack = frontEnd.concat(backEnd) + +console.log(fullStack) \ No newline at end of file diff --git a/solutions/DAY-01/ARRAYS/web_techs.js b/solutions/DAY-01/ARRAYS/web_techs.js index a057439..53ac483 100644 --- a/solutions/DAY-01/ARRAYS/web_techs.js +++ b/solutions/DAY-01/ARRAYS/web_techs.js @@ -6,4 +6,6 @@ const webTechs = [ 'Redux', 'Node', 'MongoDB', - ] \ No newline at end of file + ] + + module.exports = webTechs \ No newline at end of file diff --git a/solutions/DAY-01/CONDITIONALS/level1 copy.html b/solutions/DAY-01/CONDITIONALS/level1 copy.html new file mode 100644 index 0000000..1be52ef --- /dev/null +++ b/solutions/DAY-01/CONDITIONALS/level1 copy.html @@ -0,0 +1,30 @@ + + + + + + Document + + + + + + + + + + + + + + + + diff --git a/solutions/DAY-01/CONDITIONALS/level1.js b/solutions/DAY-01/CONDITIONALS/level1.js new file mode 100644 index 0000000..7cf6e08 --- /dev/null +++ b/solutions/DAY-01/CONDITIONALS/level1.js @@ -0,0 +1,41 @@ +/*let age = prompt("Enter your age: ") + +if (age >= 18){ + console.log("you are old enough to drive") +}else { + let diff = 18 - age + console.log(`You are ${diff} years from driving`) +} + + +let myage = 20 + +if (myage > age){ + let agediff = myage - age + console.log(`I am ${agediff} older than you`) +}else{ + let agediff = age - myage + console.log(`You are ${agediff} older than me`) +} +*/ + +let a = 4 +let b = 3 + +if (a > b){ + console.log("a is greater than b\n") +}else{ + console.log("a is less than b") +} + + +a > b ? console.log("a is greater than b") : console.log("a is less than b") + + +let usrnum = prompt("Enter a number: ") + +if (usrnum/2 == 0) { + console.log("this is an even number") +}else{ + console.log("this is an odd number") +} \ No newline at end of file diff --git a/solutions/DAY-01/CONDITIONALS/level2.js b/solutions/DAY-01/CONDITIONALS/level2.js new file mode 100644 index 0000000..aa801ad --- /dev/null +++ b/solutions/DAY-01/CONDITIONALS/level2.js @@ -0,0 +1,57 @@ +function getGrade(score) { + var grade; + switch (true) { + case score >= 80: + grade = 'A'; + break; + case score >= 70: + grade = 'B'; + break; + case score >= 60: + grade = 'C'; + break; + case score >= 50: + grade = 'D'; + break; + default: + grade = 'F'; + } + return grade; + } + + + function getSeason(month) { + var season; + switch (month) { + case 'September': + case 'October': + case 'November': + season = 'Autumn'; + break; + case 'December': + case 'January': + case 'February': + season = 'Winter'; + break; + case 'March': + case 'April': + case 'May': + season = 'Spring'; + break; + case 'June': + case 'July': + case 'August': + season = 'Summer'; + break; + default: + season = 'Invalid month'; + } + return season; + } + + + function isWeekend(day) { + var weekend = ['Saturday', 'Sunday']; + return weekend.includes(day); + } + \ No newline at end of file diff --git a/solutions/DAY-01/CONDITIONALS/level3.js b/solutions/DAY-01/CONDITIONALS/level3.js new file mode 100644 index 0000000..937bc21 --- /dev/null +++ b/solutions/DAY-01/CONDITIONALS/level3.js @@ -0,0 +1,4 @@ +function daysInMonth(month, year) { + return new Date(year, month, 0).getDate(); + } + \ No newline at end of file From 04d45be2c6363971e938c6beac362f51eb9cf413 Mon Sep 17 00:00:00 2001 From: drixesxs Date: Fri, 5 Jan 2024 17:11:55 +0100 Subject: [PATCH 3/3] Day 1 cont --- solutions/DAY-01/OBJECTS/level1.js | 0 1 file changed, 0 insertions(+), 0 deletions(-) create mode 100644 solutions/DAY-01/OBJECTS/level1.js diff --git a/solutions/DAY-01/OBJECTS/level1.js b/solutions/DAY-01/OBJECTS/level1.js new file mode 100644 index 0000000..e69de29