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