diff --git a/solutions/DAY-01/ARRAYS/countries.js b/solutions/DAY-01/ARRAYS/countries.js new file mode 100644 index 0000000..381a2c6 --- /dev/null +++ b/solutions/DAY-01/ARRAYS/countries.js @@ -0,0 +1,16 @@ +const countries = [ + 'Albania', + 'Bolivia', + 'Canada', + 'Denmark', + 'Ethiopia', + 'Finland', + 'Germany', + 'Hungary', + 'Ireland', + 'Japan', + 'Kenya', + ] + + module.exports = countries + \ 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 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 new file mode 100644 index 0000000..4ad0d16 --- /dev/null +++ b/solutions/DAY-01/ARRAYS/main.js @@ -0,0 +1,45 @@ +const countries = require('./countries') +const webTechs = require('./web_techs.js') + + +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 new file mode 100644 index 0000000..53ac483 --- /dev/null +++ b/solutions/DAY-01/ARRAYS/web_techs.js @@ -0,0 +1,11 @@ +const webTechs = [ + 'HTML', + 'CSS', + 'JavaScript', + 'React', + 'Redux', + 'Node', + 'MongoDB', + ] + + 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 diff --git a/solutions/DAY-01/OBJECTS/level1.js b/solutions/DAY-01/OBJECTS/level1.js new file mode 100644 index 0000000..e69de29