From f8eaa5db1a496d4f83cd002032851874e2d51e30 Mon Sep 17 00:00:00 2001 From: catsAndIvy Date: Tue, 4 Jul 2023 17:52:18 +0100 Subject: [PATCH] add day01 solutions --- _30-days-of-react-project/index.html | 10 +++++ _30-days-of-react-project/introduction.js | 1 + _solutions/day-01/exercise1/ web_techs.js | 11 +++++ _solutions/day-01/exercise1/countries.js | 15 +++++++ _solutions/day-01/exercise1/level1.js | 55 +++++++++++++++++++++++ _solutions/day-01/exercise1/level2.js | 47 +++++++++++++++++++ _solutions/day-01/exercise1/level3.js | 29 ++++++++++++ _solutions/day-01/exercise2/level1.js | 42 +++++++++++++++++ _solutions/day-01/exercise2/level2.js | 48 ++++++++++++++++++++ _solutions/day-01/exercise2/level3.js | 16 +++++++ solutions/day-01/level1.js | 0 11 files changed, 274 insertions(+) create mode 100644 _30-days-of-react-project/index.html create mode 100644 _30-days-of-react-project/introduction.js create mode 100644 _solutions/day-01/exercise1/ web_techs.js create mode 100644 _solutions/day-01/exercise1/countries.js create mode 100644 _solutions/day-01/exercise1/level1.js create mode 100644 _solutions/day-01/exercise1/level2.js create mode 100644 _solutions/day-01/exercise1/level3.js create mode 100644 _solutions/day-01/exercise2/level1.js create mode 100644 _solutions/day-01/exercise2/level2.js create mode 100644 _solutions/day-01/exercise2/level3.js delete mode 100644 solutions/day-01/level1.js diff --git a/_30-days-of-react-project/index.html b/_30-days-of-react-project/index.html new file mode 100644 index 0000000..6a5811a --- /dev/null +++ b/_30-days-of-react-project/index.html @@ -0,0 +1,10 @@ + + + + 30DaysOfScript:Internal Script + + + + + + \ No newline at end of file diff --git a/_30-days-of-react-project/introduction.js b/_30-days-of-react-project/introduction.js new file mode 100644 index 0000000..316199c --- /dev/null +++ b/_30-days-of-react-project/introduction.js @@ -0,0 +1 @@ +console.log('Welcome to 30DaysOfJavaScript') \ No newline at end of file diff --git a/_solutions/day-01/exercise1/ web_techs.js b/_solutions/day-01/exercise1/ web_techs.js new file mode 100644 index 0000000..53ac483 --- /dev/null +++ b/_solutions/day-01/exercise1/ 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/exercise1/countries.js b/_solutions/day-01/exercise1/countries.js new file mode 100644 index 0000000..21b2295 --- /dev/null +++ b/_solutions/day-01/exercise1/countries.js @@ -0,0 +1,15 @@ +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/exercise1/level1.js b/_solutions/day-01/exercise1/level1.js new file mode 100644 index 0000000..f244852 --- /dev/null +++ b/_solutions/day-01/exercise1/level1.js @@ -0,0 +1,55 @@ +// Exercise 1 - Level 1 + +const webTechs = [ + 'HTML', + 'CSS', + 'JavaScript', + 'React', + 'Redux', + 'Node', + 'MongoDB', + ] + +const newArray = Array(6).fill('cats'); +newArray.push(7) + +const itCompanies = Array('Facebook', 'Google', 'Microsoft', 'Apple', 'IBM', 'Oracle', 'Amazon') + +for (let i = 0; i 1) { + return itCompanies[i] + } + } +} + +const sliced = itCompanies.slice(itCompanies.length-3, itCompanies.length) + +const middle = itCompanies[Math.floor((itCompanies.length)/2)] + +const middleIndex = Math.floor((itCompanies.length)/2) + +itCompanies.splice(middleIndex,1) + +itCompanies.length = 0 + + + diff --git a/_solutions/day-01/exercise1/level2.js b/_solutions/day-01/exercise1/level2.js new file mode 100644 index 0000000..5a43c2b --- /dev/null +++ b/_solutions/day-01/exercise1/level2.js @@ -0,0 +1,47 @@ +// Exercise 1 - Level 2 + +const countries = require('./countries.js'); +const webTechs = require('./ web_techs.js'); + +const str = countries.toString() + +const modifiedStr = str.replace(/[^\w]/g, ' ') + +const newArray = modifiedStr.split(' ') + +const numOfWords = newArray.length + + +const shoppingCart = ['Milk', 'Coffee', 'Tea', 'Honey'] + +if (!shoppingCart.includes('Meat')) { + shoppingCart.unshift('Meat') +} + +if (!shoppingCart.includes('Sugar')) { + shoppingCart.push('Sugar') +} + +shoppingCart[3] = 'Green Tea' + + + +if (!countries.includes('Ethiopia')) { + countries.push('Ethiopia') +} else { + console.log('Ethiopia') +} + + + +if (!webTechs.includes('Sass')) { + webTechs.push('Sass') + console.log(webTechs) +} else { + console.log('Sass is a CSS preprocess') +} + +const frontEnd = ['HTML', 'CSS', 'JS', 'React', 'Redux'] +const backEnd = ['Node', 'Express', 'MongoDB'] + +const fullStack = frontEnd.concat(backEnd) \ No newline at end of file diff --git a/_solutions/day-01/exercise1/level3.js b/_solutions/day-01/exercise1/level3.js new file mode 100644 index 0000000..b34942a --- /dev/null +++ b/_solutions/day-01/exercise1/level3.js @@ -0,0 +1,29 @@ +// Exercise 1 - Level 3 + +const countries = require('./countries.js'); +const ages = [19, 22, 19, 24, 20, 25, 26, 24, 25, 24] + +const sortedArray = ages.sort() + +const minAge = sortedArray[0] +const maxAge = sortedArray[sortedArray.length-1] + +const medianAge = (sortedArray[4] + sortedArray[5])/2 + +const averageAge = (sortedArray.reduce((number, a) => number + a, 0))/sortedArray.length + +const rangeAge = maxAge - minAge + +const compareAge = (maxAge - averageAge)-(minAge - averageAge) + + + + +const slicedCountries = countries.slice(0,10) + +const middleCountry = countries[5] + +const firstHalf = countries.slice(0,6) + +const secondHalf = countries.slice(6,11) + diff --git a/_solutions/day-01/exercise2/level1.js b/_solutions/day-01/exercise2/level1.js new file mode 100644 index 0000000..367d071 --- /dev/null +++ b/_solutions/day-01/exercise2/level1.js @@ -0,0 +1,42 @@ +// Exercise 2 - Level 1 + +let age = 34 + +if (age <18) { + let years = 18 - age + console.log(`You have ${years} years left until you can drive.`) +} else { + console.log(`You are old enough to drive.`) +} + + +if (age > 29) { + let years = age - 29 + console.log(`You are ${years} years older than me.`) +} else if (age === 29) { + console.log(`You are the same age as me.`) +} else { + let years = 29 - age + console.log(`I am ${years} years older than you.`) +} + + +let a = 2 +let b = 2 + +if (a > b) { + console.log(`${a} is greater than ${b}`) +} else if (a === b) { + console.log(`${a} is equal to ${b}`) +} else { + console.log(`${b} is greater than ${a}`) +} + + +let number = 10 + +if (number%2 === 0) { + console.log(`${number} is even.`) +} else { + console.log(`${number} is odd.`) +} \ No newline at end of file diff --git a/_solutions/day-01/exercise2/level2.js b/_solutions/day-01/exercise2/level2.js new file mode 100644 index 0000000..02ee6dd --- /dev/null +++ b/_solutions/day-01/exercise2/level2.js @@ -0,0 +1,48 @@ +// Exercise 2 - Level 2 + +let score = 75; + +if (score >= 90 && score <= 100) { + console.log('A'); +} else if (score >= 70 && score < 90) { + console.log('B'); +} else if (score >= 60 && score < 70) { + console.log('C'); +} else if (score >= 50 && score < 60) { + console.log('D'); +} else if (score >= 0 && score < 50) { + console.log('E'); +} else { + console.log('Invalid score'); +} + + +let month = 'September' + +if (month === 'September' || month === 'October' || month === 'November') { + console.log('The season is Autumn') +} else if (month === 'December' || month === 'January' || month === 'February') { + console.log('The season is Winter') +} else if (month === 'March' || month === 'April' || month === 'May') { + console.log('The season is Spring') +} else if (month === 'June' || month === 'July' || month === 'August') { + console.log('The season is Summer') } + + +let day = 'FriDAY' + +let lowered = day.toLowerCase() + +switch(lowered){ + case 'saturday': + console.log('Saturday is a weekend') + break + case 'sunday': + console.log('Sunday is a weekend.') + break + default: + const capital = lowered.slice(0,1).toUpperCase() + const capitalised = capital + lowered.slice(1) + console.log(`${capitalised} is a week day.`) +} + diff --git a/_solutions/day-01/exercise2/level3.js b/_solutions/day-01/exercise2/level3.js new file mode 100644 index 0000000..a237bfa --- /dev/null +++ b/_solutions/day-01/exercise2/level3.js @@ -0,0 +1,16 @@ +// Exercise 2 - Level 3 + +const currentDate = new Date(); +const currentYear = currentDate.getFullYear(); + +let month = 'February' + +if (month === 'April' || month === 'June' || month === 'September'|| month === 'November') { + console.log(`${month} has 30 days.`) +} else if (month === 'February' && currentYear%4 === 0) { + console.log(`February has 29 days.`) +} else if (month === 'February' && !currentYear%4 === 0) { + console.log(`February has 28 days.`) +} else {console.log(`${month} has 31 days.`)} + + diff --git a/solutions/day-01/level1.js b/solutions/day-01/level1.js deleted file mode 100644 index e69de29..0000000