diff --git a/02_Day_Data_types/02_day_starter/index.html b/02_Day_Data_types/02_day_starter/index.html index 8fbbe0d1b..7c7d57b9b 100644 --- a/02_Day_Data_types/02_day_starter/index.html +++ b/02_Day_Data_types/02_day_starter/index.html @@ -1,17 +1,14 @@ - - - 30DaysOfJavaScript - - - -

30DaysOfJavaScript:02 Day

-

Data types

- - - - - - - \ No newline at end of file + + 30DaysOfJavaScript + + + +

30DaysOfJavaScript:02 Day

+

Data types

+ + + + + diff --git a/02_Day_Data_types/02_day_starter/main.js b/02_Day_Data_types/02_day_starter/main.js index 77629084e..f415e3a90 100644 --- a/02_Day_Data_types/02_day_starter/main.js +++ b/02_Day_Data_types/02_day_starter/main.js @@ -1 +1,63 @@ -// this is your main.js script \ No newline at end of file +//Task1-medium +console.log( + "The quote 'There is no exercise better for the heart than reaching down and lifting people up.' by John Holmes teaches us to help one another." +) + +//Task2-medium +console.log( + '"Love is not patronizing and charity isn\'t about pity, it is about love. Charity and love are the same -- with charity you give love, so don\'t just give money but reach out your hand instead." is a quote by Mother Teresa' +) + +//Task3-medium +console.log(typeof '10' == typeof 10) +console.log(typeof '10' == typeof '10') + +//Task4-medium +console.log(parseFloat('9.8') == 10) +console.log(Math.round(parseFloat('9.8')) == 10) + +//Task5-medium +console.log('python'.includes('on')) +console.log('jargon'.includes('on')) + +//Task6-medium +console.log('I hope this course is not full of jargon.'.includes('jargon')) + +//Task7-medium +console.log(Math.floor(Math.random() * 101)) + +//Task8-medium +console.log(Math.floor(Math.random() * 51) + 50) + +//Task9-medium +console.log(Math.floor(Math.random() * 256)) + +//Task10-medium +let string = 'JavaScript' +let num = [] +let characters = [] +let rand + +while (num.length < string.length) { + rand = parseInt(Math.random() * (string.length - 2)) + if (!num.includes(rand)) { + num.push(rand) + } +} + +for (const i of num) { + characters.push(string[i]) +} + +console.log(characters) + +//Task11-medium +console.log('1 1 1 1 1 \n2 1 2 4 8 \n3 1 3 9 27 \n4 1 4 16 64 \n5 1 5 25 125') + +//Task12-medium +console.log( + 'You cannot end a sentence with because because because is a conjunction'.substr( + 31, + 24 + ) +) diff --git a/03_Day_Booleans_operators_date/03_day_starter/index.html b/03_Day_Booleans_operators_date/03_day_starter/index.html index 2a8e6a80f..84aca9238 100644 --- a/03_Day_Booleans_operators_date/03_day_starter/index.html +++ b/03_Day_Booleans_operators_date/03_day_starter/index.html @@ -1,17 +1,14 @@ - - - 30DaysOfJavaScript: 03 Day - - - -

30DaysOfJavaScript:03 Day

-

Booleans, undefined, null, date object

- - - - - - - \ No newline at end of file + + 30DaysOfJavaScript: 03 Day + + + +

30DaysOfJavaScript:03 Day

+

Booleans, undefined, null, date object

+ + + + + diff --git a/03_Day_Booleans_operators_date/03_day_starter/scripts/main.js b/03_Day_Booleans_operators_date/03_day_starter/scripts/main.js index 77629084e..b1a102740 100644 --- a/03_Day_Booleans_operators_date/03_day_starter/scripts/main.js +++ b/03_Day_Booleans_operators_date/03_day_starter/scripts/main.js @@ -1 +1,150 @@ -// this is your main.js script \ No newline at end of file +// //Task1-medium +let base = prompt('Enter base: ') +let height = prompt('Enter height: ') + +let area = 0.5 * base * height + +console.log(`The area of the triangle is ${area}`) + +// //Task2-medium +let a = parseFloat(prompt('Enter side a: ')) +let b = parseFloat(prompt('Enter side b: ')) +let c = parseFloat(prompt('Enter side c: ')) + +let P = a + b + c + +console.log(`The area of the triangle is ${P}`) + +// //Task3-medium +let length = prompt('Enter length: ') +let width = prompt('Enter width: ') + +area = length * width +P = 2 * (length + width) + +console.log(`The area of the rectangle is ${area}.`) +console.log(`The perimeter of the rectangle is ${P}.`) + +// //Task4-medium +let radius = prompt('Enter radius: ') +pi = 3.14 + +area = pi * radius * radius +let C = 2 * pi * radius + +console.log(`The area of the circle is ${area}`) +console.log(`The circumference of the circle is ${C}`) + +//Task5-mediums +//y = 2x - 2 +let slope = 2 +let xIntercept = [slope / 2, 0] +let yIntercept = [0, 2] + +console.log(slope, xIntercept, yIntercept) + +//Task6-medium +let point1 = '(2, 2)' +let point2 = '(6, 10)' + +let comma1 = point1.indexOf(',') +let comma2 = point2.indexOf(',') + +let x1 = parseFloat(point1.substring(1, comma1)) +let y1 = parseFloat(point1.substring(comma1 + 1)) +let x2 = parseFloat(point2.substring(1, comma2)) +let y2 = parseFloat(point2.substring(comma2 + 1)) + +let m = (y2 - y1) / (x2 - x1) + +console.log(m) + +//Task7-medium +point1 = prompt('Enter the first point: ') +point2 = prompt('Enter the second point: ') + +x1 = parseFloat(point1.substring(1, comma1)) +y1 = parseFloat(point1.substring(comma1 + 1)) +x2 = parseFloat(point2.substring(1, comma2)) +y2 = parseFloat(point2.substring(comma2 + 1)) + +m = (y2 - y1) / (x2 - x1) + +console.log(m) + +// //Task8-medium +x = 2 +y = x * x + 6 * x + 9 +let y0 = 0 + +x = -6 / 2 + +console.log(y) +console.log(x) + +// //Task9-medium +let hours = prompt('Enter hours: ') +let rate = prompt('Enter rate per hour: ') + +let earning = hours * rate + +console.log(`Your weekly earning is ${earning}`) + +//Task10-medium +let name = 'Arina' +let isLong = name.length > 7 + +isLong ? console.log('My name is long') : console.log('My name is short') + +//Task11-medium +firstName = 'Asabeneh' +lastName = 'Yetayeh' + +let isLonger = firstName.length > lastName + +isLonger + ? console.log( + `Your first name, ${firstName} is longer than your family name, ${lastName}` + ) + : console.log( + `Your first name, ${firstName} is shorter than your family name, ${lastName}` + ) + +//Task12-medium +let myAge = 250 +let yourAge = 25 + +myAge > yourAge + ? console.log(`I am ${myAge - yourAge} yeats older than you.`) + : console.log(`You are ${yourAge - myAge} yeats older than me.`) + +// //Task13-medium +let birthYear = parseInt(prompt('Enter your birth year: ')) +let currentYear = new Date().getFullYear() +age = currentYear - birthYear + +age > 18 + ? console.log(`You are ${age}. You are old enough to drive.`) + : console.log( + `You are ${age}. You will be allowed to drive after ${18 - age} years.` + ) + +//Task14-medium +age = prompt('Enter number of years you live: ') + +let ageSeconds = age * 365 * 24 * 60 * 60 + +console.log(ageSeconds) + +//Task15-medium +const now = new Date() + +const year = now.getFullYear() +const month = now.getMonth() +const nowDate = now.getDate() +const nowHours = now.getHours() +const minutes = now.getMinutes() + +console.log(`${year}-${month}-${nowDate} ${nowHours}:${minutes}`) +console.log(`${nowDate}-${month}-${year} ${nowHours}:${minutes}`) +console.log(`${nowDate}/${month}/${year} ${nowHours}:${minutes}`) diff --git a/09_Day_Higher_order_functions/09_day_starter/index.html b/09_Day_Higher_order_functions/09_day_starter/index.html index cbf51280e..aef0a372f 100644 --- a/09_Day_Higher_order_functions/09_day_starter/index.html +++ b/09_Day_Higher_order_functions/09_day_starter/index.html @@ -1,17 +1,14 @@ - - - 30DaysOfJavaScript:09 Day - - - -

30DaysOfJavaScript:09 Day

-

Functional Programming

- - - - - - - \ No newline at end of file + + 30DaysOfJavaScript:09 Day + + + +

30DaysOfJavaScript:09 Day

+

Functional Programming

+ + + + + diff --git a/09_Day_Higher_order_functions/09_day_starter/scripts/main.js b/09_Day_Higher_order_functions/09_day_starter/scripts/main.js index c6045c836..a8c396797 100644 --- a/09_Day_Higher_order_functions/09_day_starter/scripts/main.js +++ b/09_Day_Higher_order_functions/09_day_starter/scripts/main.js @@ -1,2 +1,122 @@ -console.log(countries) -alert('Open the console and check if the countries has been loaded') \ No newline at end of file +const countries2 = ['Finland', 'Sweden', 'Denmark', 'Norway', 'Iceland'] +const names = ['Asabeneh', 'Mathias', 'Elias', 'Brook'] +const numbers = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10] +const products = [ + { product: 'banana', price: 3 }, + { product: 'mango', price: 6 }, + { product: 'potato', price: ' ' }, + { product: 'avocado', price: 8 }, + { product: 'coffee', price: 10 }, + { product: 'tea', price: '' }, +] + +//Task1-easy +//Task2-easy +//Task3-easy +function callbackCountries(element) { + console.log(element) +} + +countries2.forEach(callbackCountries) + +//Task4-easy +names.forEach(elem => { + console.log(elem) +}) + +//Task5-easy +numbers.forEach(elem => { + console.log(elem) +}) + +//Task6-easy +const newCountries2 = countries2.map(country => country.toLocaleUpperCase()) +console.log(newCountries2) + +//Task7-easy +const lengthCountries2 = countries2.map(elem => elem.length) +console.log(lengthCountries2) + +//Task8-easy +const numbersSqr = numbers.map(num => num * num) +console.log(numbersSqr) + +//Task9easy +const namesUpperCase = names.map(name => name.toUpperCase) +console.log(namesUpperCase) + +//Task10-easy +const price = products.map( + product => `Price of ${product.product} = ${product.price}` +) +console.log(price) + +//Task11-easy +const countriesWithLand = countries2.filter(country => country.includes('land')) +console.log(countriesWithLand) + +//Task12-easy +const countriesSix = countries2.filter(country => country.length == 6) +console.log(countriesSix) + +//Task13-easy +const countriesSixAndMore = countries2.filter(country => country.length >= 6) +console.log(countriesSixAndMore) + +//Task14-easy +const countriesStartsWithE = countries2.filter(country => country[0] == 'E') +console.log(countriesStartsWithE) + +//Task15-easy +const priceWithValue = products.filter( + product => typeof product.price == 'number' +) +console.log(priceWithValue) + +//Task16-easy +const arr = [1, 'string', 'lntlns', 'lekj', 590] + +function getStringLists(array) { + const newArray = array.filter(elem => typeof elem == 'string') + + return newArray +} +console.log(getStringLists(arr)) + +//Task17-easy +const sum = numbers.reduce((acc, cur) => acc + cur) +console.log(sum) + +//Task18-easy +const countriesToString = countries2.reduce((acc, cur, index) => index != countries2.length - 1 ? acc.concat(`, ${cur}`) : acc.concat(`, and ${cur} are north European countries`)) +console.log(countriesToString) + +//Task19-easy +//Task20-easy +const namesLength = names.some(name => name.length > 7) +console.log(namesLength) + +//Task21-easy +const countriesContainsLand = countries2.every(country => + country.includes('land') +) +console.log(countriesContainsLand) + +//Task22-easy +//Task23-easy +const countryWithSixLetters = countries2.find(country => country.length == 6) +console.log(countryWithSixLetters) + +//Task24-easy +const countryWithSixLetters2 = countries2.findIndex( + country => country.length == 6 +) +console.log(countryWithSixLetters2) + +//Task25-easy +const norwayPosition = countries2.findIndex(country => country == 'Norway') +console.log(norwayPosition) + +//Task26-easy +const russiaPosition = countries2.findIndex(country => country == 'Russia') +console.log(russiaPosition) diff --git a/10_Day_Sets_and_Maps/10_day_starter/data/countries_data.js b/10_Day_Sets_and_Maps/10_day_starter/data/countries_data.js index 92acddd21..848f14bca 100644 --- a/10_Day_Sets_and_Maps/10_day_starter/data/countries_data.js +++ b/10_Day_Sets_and_Maps/10_day_starter/data/countries_data.js @@ -265,7 +265,7 @@ const countries = [ }, { name: 'United States Minor Outlying Islands', - capital: '', + capital: '',f languages: ['English'], population: 300, flag: 'https://restcountries.eu/data/umi.svg', diff --git a/10_Day_Sets_and_Maps/10_day_starter/scripts/main.js b/10_Day_Sets_and_Maps/10_day_starter/scripts/main.js index c6045c836..125dce06d 100644 --- a/10_Day_Sets_and_Maps/10_day_starter/scripts/main.js +++ b/10_Day_Sets_and_Maps/10_day_starter/scripts/main.js @@ -1,2 +1,63 @@ -console.log(countries) -alert('Open the console and check if the countries has been loaded') \ No newline at end of file +//Task1-easy +const empty = new Set() +console.log(empty) + +//Task2-easy +const numbers = new Set() + +for (let i = 0; i <= 10; i++) { + numbers.add(i) +} + +console.log(numbers) + +//Task3-easy +numbers.delete(1) +console.log(numbers) + +//Task4-easy +numbers.clear() +console.log(numbers) + +//Task5-easy +const words = ['hello', 'text', 'hello', 'plant', 'tree'] + +const wordsSet = new Set(words) + +console.log(wordsSet) + +//Task6-easy +const countries3 = ['Finland', 'Sweden', 'Norway'] + +const countriesMap = new Map() + +for (let i = 0; i <= countries3.length - 1; i++) { + countriesMap.set(countries3[i], countries3[i].length) +} + +//Task1-medium +const a = [4, 5, 8, 9] +const b = [3, 4, 5, 7] + +const A = new Set(a) +const B = new Set(b) + +let c = new Set([...a, ...b]) + +console.log(c) + +//Task2-medium +c = new Set(a.filter(num => B.has(num))) +console.log(c) + +//Task3-medium +c = new Set(a.filter(num => !B.has(num))) +console.log(c) + +console.log(countriesMap) + +//Task1-hard +console.log(countries.length) + +//Task2-hard +function mostSpokenLanguages(countries, n) {} diff --git a/11_Day_Destructuring_and_spreading/11_day_starter/index.html b/11_Day_Destructuring_and_spreading/11_day_starter/index.html index 1c2ed8db9..a0747d3a1 100644 --- a/11_Day_Destructuring_and_spreading/11_day_starter/index.html +++ b/11_Day_Destructuring_and_spreading/11_day_starter/index.html @@ -1,17 +1,14 @@ - - - 30DaysOfJavaScript:11 Day - - - -

30DaysOfJavaScript:11 Day

-

Destructuring and Spread

- - - - - - - \ No newline at end of file + + 30DaysOfJavaScript:11 Day + + + +

30DaysOfJavaScript:11 Day

+

Destructuring and Spread

+ + + + + diff --git a/11_Day_Destructuring_and_spreading/11_day_starter/scripts/main.js b/11_Day_Destructuring_and_spreading/11_day_starter/scripts/main.js index c6045c836..7872aaacf 100644 --- a/11_Day_Destructuring_and_spreading/11_day_starter/scripts/main.js +++ b/11_Day_Destructuring_and_spreading/11_day_starter/scripts/main.js @@ -1,2 +1,79 @@ -console.log(countries) -alert('Open the console and check if the countries has been loaded') \ No newline at end of file +//Task1-easy +const constants = [2.72, 3.14, 9.81, 37, 100] +let [e, pi, gravity, humanBodyTemp, waterBoilingTemp] = constants + +console.log(e, pi, gravity, humanBodyTemp, waterBoilingTemp) + +//Task2-easy +const countries2 = ['Finland', 'Estonia', 'Sweden', 'Denmark', 'Norway'] +let [fin, est, sw, den, nor] = countries2 + +console.log(fin, est, sw, den, nor) + +//Task3-easy +const rectangle = { + width: 20, + height: 10, + area: 200, + perimeter: 60, +} + +let { width, height, area, perimeter } = rectangle +console.log(width, height, area, perimeter) + +//Task1-medium +const users = [ + { + name: 'Brook', + scores: 75, + skills: ['HTM', 'CSS', 'JS'], + age: 16, + }, + { + name: 'Alex', + scores: 80, + skills: ['HTM', 'CSS', 'JS'], + age: 18, + }, + { + name: 'David', + scores: 75, + skills: ['HTM', 'CSS'], + age: 22, + }, + { + name: 'John', + scores: 85, + skills: ['HTML'], + age: 25, + }, + { + name: 'Sara', + scores: 95, + skills: ['HTM', 'CSS', 'JS'], + age: 26, + }, + { + name: 'Martha', + scores: 80, + skills: ['HTM', 'CSS', 'JS'], + age: 18, + }, + { + name: 'Thomas', + scores: 90, + skills: ['HTM', 'CSS', 'JS'], + age: 20, + }, +] + +for (let { name, scores, skills, age } of users) { + console.log(name, scores, skills, age) +} + +//Task2-medium +for (let { name, skills } of users) { + if (skills.length < 2) { + console.log(name, skills) + } +}