diff --git a/02-Day/index.html b/02-Day/index.html new file mode 100644 index 00000000..2cdcc97a --- /dev/null +++ b/02-Day/index.html @@ -0,0 +1,17 @@ + + + + + 30DaysOfJavaScript + + + + + + + + + + + + \ No newline at end of file diff --git a/02-Day/math_object.js b/02-Day/math_object.js new file mode 100644 index 00000000..784b2ae8 --- /dev/null +++ b/02-Day/math_object.js @@ -0,0 +1,34 @@ +const PI = Math.PI +console.log(PI) // 3.141592653589793 +console.log(Math.round(PI)) // 3; to round values to the nearest number +console.log(Math.round(9.81)) // 10 +console.log(Math.floor(PI)) // 3; rounding down +console.log(Math.ceil(PI)) // 4; rounding up +console.log(Math.min(-5, 3, 20, 4, 5, 10)) // -5, returns the minimum value +console.log(Math.max(-5, 3, 20, 4, 5, 10)) // 20, returns the maximum value + +const randNum = Math.random() // creates random number between 0 to 0.999999 +console.log(randNum) +// Let create random number between 0 to 10 +const num = Math.floor(Math.random() * 11) // creates random number between 0 and 10 +console.log(num) + +//Absolute value +console.log(Math.abs(-10)) //10 +//Square root +console.log(Math.sqrt(100)) // 10 +console.log(Math.sqrt(2)) //1.4142135623730951 +// Power +console.log(Math.pow(3, 2)) // 9 +console.log(Math.E) // 2.718 + +// Logarithm +//Returns the natural logarithm of base E of x, Math.log(x) +console.log(Math.log(2)) // 0.6931471805599453 +console.log(Math.log(10)) // 2.302585092994046 + +// Trigonometry +console.log(Math.sin(0)) +console.log(Math.sin(60)) +console.log(Math.cos(0)) +console.log(Math.cos(60)) diff --git a/02-Day/non_primitive_data_types.js b/02-Day/non_primitive_data_types.js new file mode 100644 index 00000000..23d7fa28 --- /dev/null +++ b/02-Day/non_primitive_data_types.js @@ -0,0 +1,30 @@ +let nums = [1, 2, 3] +nums[0] = 10 +console.log(nums) // [10, 2, 3] + +let nums = [1, 2, 3] +let numbers = [1, 2, 3] +console.log(nums == numbers) // false + +let userOne = { + name: 'Asabeneh', + role: 'teaching', + country: 'Finland' +} +let userTwo = { + name: 'Asabeneh', + role: 'teaching', + country: 'Finland' +} +console.log(userOne == userTwo) // false + +let numbers = nums +console.log(nums == numbers) // true + +let userOne = { +name:'Asabeneh', +role:'teaching', +country:'Finland' +} +let userTwo = userOne +console.log(userOne == userTwo) // true \ No newline at end of file diff --git a/02-Day/number_data_types.js b/02-Day/number_data_types.js new file mode 100644 index 00000000..b850af92 --- /dev/null +++ b/02-Day/number_data_types.js @@ -0,0 +1,9 @@ +let age = 35 +const gravity = 9.81 //we use const for non-changing values, gravitational constant in m/s2 +let mass = 72 // mass in Kilogram +const PI = 3.14 // pi a geometrical constant + +//More Examples +const boilingPoint = 100 // temperature in oC, boiling point of water which is a constant +const bodyTemp = 37 // oC average human body temperature, which is a constant +console.log(age, gravity, mass, PI, boilingPoint, bodyTemp) diff --git a/02-Day/primitive_data_types.js b/02-Day/primitive_data_types.js new file mode 100644 index 00000000..d3c298c3 --- /dev/null +++ b/02-Day/primitive_data_types.js @@ -0,0 +1,14 @@ +let word = 'JavaScript' +// we dont' modify string +// we don't do like this, word[0] = 'Y' +let numOne = 3 +let numTwo = 3 +console.log(numOne == numTwo) // true + +let js = 'JavaScript' +let py = 'Python' +console.log(js == py) //false + +let lightOn = true +let lightOff = false +console.log(lightOn == lightOff) // false \ No newline at end of file diff --git a/02-Day/string_concatenation.js b/02-Day/string_concatenation.js new file mode 100644 index 00000000..516ca1a9 --- /dev/null +++ b/02-Day/string_concatenation.js @@ -0,0 +1,19 @@ +// Declaring different variables of different data types +let space = ' ' +let firstName = 'Asabeneh' +let lastName = 'Yetayeh' +let country = 'Finland' +let city = 'Helsinki' +let language = 'JavaScript' +let job = 'teacher' +// Concatenating using addition operator +let fullName = firstName + space + lastName // concatenation, merging two string together. +console.log(fullName) + +let personInfoOne = fullName + '. I am ' + age + '. I live in ' + country // ES5 +console.log(personInfoOne) +// Concatenation: Template Literals(Template Strings) +let personInfoTwo = `I am ${fullName}. I am ${age}. I live in ${country}.` //ES6 - String interpolation method +let personInfoThree = `I am ${fullName}. I live in ${city}, ${country}. I am a ${job}. I teach ${language}.` +console.log(personInfoTwo) +console.log(personInfoThree) \ No newline at end of file diff --git a/02-Day/string_data_types.js b/02-Day/string_data_types.js new file mode 100644 index 00000000..fd611502 --- /dev/null +++ b/02-Day/string_data_types.js @@ -0,0 +1,7 @@ +let space = ' ' // an empty space string +let firstName = 'Asabeneh' +let lastName = 'Yetayeh' +let country = 'Finland' +let city = 'Helsinki' +let language = 'JavaScript' +let job = 'teacher' diff --git a/02-Day/string_methods/accessing_character.js b/02-Day/string_methods/accessing_character.js new file mode 100644 index 00000000..32229fb6 --- /dev/null +++ b/02-Day/string_methods/accessing_character.js @@ -0,0 +1,12 @@ +// Let us access the first character in 'JavaScript' string. + +let string = 'JavaScript' +let firstLetter = string[0] +console.log(firstLetter) // J +let secondLetter = string[1] // a +let thirdLetter = string[2] +let lastLetter = string[9] +console.log(lastLetter) // t +let lastIndex = string.length - 1 +console.log(lastIndex) // 9 +console.log(string[lastIndex]) // t diff --git a/02-Day/string_methods/char_at.js b/02-Day/string_methods/char_at.js new file mode 100644 index 00000000..7daaf746 --- /dev/null +++ b/02-Day/string_methods/char_at.js @@ -0,0 +1,6 @@ +// charAt(): Takes index and it returns the value at that index +string.charAt(index) +let string = '30 Days Of JavaScript' +console.log(string.charAt(0)) // 3 +let lastIndex = string.length - 1 +console.log(string.charAt(lastIndex)) // t diff --git a/02-Day/string_methods/char_code_at.js b/02-Day/string_methods/char_code_at.js new file mode 100644 index 00000000..e58baaa7 --- /dev/null +++ b/02-Day/string_methods/char_code_at.js @@ -0,0 +1,7 @@ +// charCodeAt(): Takes index and it returns char code(ASCII number) of the value at that index + +string.charCodeAt(index) +let string = '30 Days Of JavaScript' +console.log(string.charCodeAt(3)) // D ASCII number is 51 +let lastIndex = string.length - 1 +console.log(string.charCodeAt(lastIndex)) // t ASCII is 116 diff --git a/02-Day/string_methods/concat.js b/02-Day/string_methods/concat.js new file mode 100644 index 00000000..8b8192ac --- /dev/null +++ b/02-Day/string_methods/concat.js @@ -0,0 +1,6 @@ +// concat(): it takes many substrings and creates concatenation. +// string.concat(substring, substring, substring) +let string = '30' +console.log(string.concat("Days", "Of", "JavaScript")) // 30DaysOfJavaScript +let country = 'Fin' +console.log(country.concat("land")) // Finland diff --git a/02-Day/string_methods/ends_with.js b/02-Day/string_methods/ends_with.js new file mode 100644 index 00000000..0ce5f1f0 --- /dev/null +++ b/02-Day/string_methods/ends_with.js @@ -0,0 +1,11 @@ +// endsWith: it takes a substring as an argument and it checks if the string starts with that specified substring. It returns a boolean(true or false). +// string.endsWith(substring) +let string = 'Love is the best to in this world' +console.log(string.endsWith('world')) // true +console.log(string.endsWith('love')) // false +console.log(string.endsWith('in this world')) // true + +let country = 'Finland' +console.log(country.endsWith('land')) // true +console.log(country.endsWith('fin')) // false +console.log(country.endsWith('Fin')) // false diff --git a/02-Day/string_methods/includes.js b/02-Day/string_methods/includes.js new file mode 100644 index 00000000..3fbe8e06 --- /dev/null +++ b/02-Day/string_methods/includes.js @@ -0,0 +1,14 @@ +// includes(): It takes a substring argument and it check if substring argument exists in the string. includes() returns a boolean. It checks if a substring exist in a string and it returns true if it exists and false if it doesn't exist. +let string = '30 Days Of JavaScript' +console.log(string.includes('Days')) // true +console.log(string.includes('days')) // false +console.log(string.includes('Script')) // true +console.log(string.includes('script')) // false +console.log(string.includes('java')) // false +console.log(string.includes('Java')) // true + +let country = 'Finland' +console.log(country.includes('fin')) // false +console.log(country.includes('Fin')) // true +console.log(country.includes('land')) // true +console.log(country.includes('Land')) // false \ No newline at end of file diff --git a/02-Day/string_methods/index_of.js b/02-Day/string_methods/index_of.js new file mode 100644 index 00000000..480db7c0 --- /dev/null +++ b/02-Day/string_methods/index_of.js @@ -0,0 +1,11 @@ +// indexOf(): Takes takes a substring and if the substring exists in a string it returns the first position of the substring if does not exist it returns -1 + +string.indexOf(substring) +let string = '30 Days Of JavaScript' +console.log(string.indexOf('D')) // 3 +console.log(string.indexOf('Days')) // 3 +console.log(string.indexOf('days')) // -1 +console.log(string.indexOf('a')) // 4 +console.log(string.indexOf('JavaScript')) // 11 +console.log(string.indexOf('Script')) //15 +console.log(string.indexOf('script')) // -1 diff --git a/02-Day/string_methods/last_index_of.js b/02-Day/string_methods/last_index_of.js new file mode 100644 index 00000000..2134d227 --- /dev/null +++ b/02-Day/string_methods/last_index_of.js @@ -0,0 +1,6 @@ +// lastIndexOf(): Takes takes a substring and if the substring exists in a string it returns the last position of the substring if it does not exist it returns -1 + +let string = 'I love JavaScript. If you do not love JavaScript what else can you love.' +console.log(string.lastIndexOf('love')) // 67 +console.log(string.lastIndexOf('you')) // 63 +console.log(string.lastIndexOf('JavaScript')) // 38 diff --git a/02-Day/string_methods/length.js b/02-Day/string_methods/length.js new file mode 100644 index 00000000..070476f5 --- /dev/null +++ b/02-Day/string_methods/length.js @@ -0,0 +1,6 @@ +// length: The string length method returns the number of characters in a string included empty space. Example: + +let js = 'JavaScript' +console.log(js.length) // 10 +let firstName = 'Asabeneh' +console.log(firstName.length) // 8 \ No newline at end of file diff --git a/02-Day/string_methods/match.js b/02-Day/string_methods/match.js new file mode 100644 index 00000000..6e281415 --- /dev/null +++ b/02-Day/string_methods/match.js @@ -0,0 +1,22 @@ +// match: it takes a substring or regular expression pattern as an argument and it returns an array if there is match if not it returns null. Let us see how a regular expression pattern looks like. It starts with / sign and ends with / sign. +let string = 'love' +let patternOne = /love/ // with out any flag +let patternTwo = /love/gi // g-means to search in the whole text, i - case insensitive +string.match(substring) +let string = 'I love JavaScript. If you do not love JavaScript what else can you love.' +console.log(string.match('love')) // +/* +output + +["love", index: 2, input: "I love JavaScript. If you do not love JavaScript what else can you love.", groups: undefined] +*/ +let pattern = /love/gi +console.log(string.match(pattern)) // ["love", "love", "love"] +// Let us extract numbers from text using regular expression. This is not regular expression section, no panic. + +let txt = 'In 2019, I run 30 Days of Pyhton. Now, in 2020 I super exited to start this challenge' +let regEx = /\d+/ // d with escape character means d not a normal d instead acts a digit +// + means one or more digit numbers, +// if there is g after that it means global, search everywhere. +console.log(text.match(regEx)) // ["2", "0", "1", "9", "3", "0", "2", "0", "2", "0"] +console.log(text.match(/\d+/g)) // ["2019", "30", "2020"] diff --git a/02-Day/string_methods/repeat.js b/02-Day/string_methods/repeat.js new file mode 100644 index 00000000..bf8e022d --- /dev/null +++ b/02-Day/string_methods/repeat.js @@ -0,0 +1,4 @@ +// repeat(): it takes a number argument and it returned the repeated version of the string. +// string.repeat(n) +let string = 'love' +console.log(string.repeat(10)) // lovelovelovelovelovelovelovelovelovelove \ No newline at end of file diff --git a/02-Day/string_methods/replace.js b/02-Day/string_methods/replace.js new file mode 100644 index 00000000..33f324cc --- /dev/null +++ b/02-Day/string_methods/replace.js @@ -0,0 +1,7 @@ +// replace(): takes to parameter the old substring and new substring. +// string.replace(oldsubstring, newsubstring) + +let string = '30 Days Of JavaScript' +console.log(string.replace('JavaScript', 'Python')) // 30 Days Of Python +let country = 'Finland' +console.log(country.replace('Fin', 'Noman')) // Nomanland \ No newline at end of file diff --git a/02-Day/string_methods/search.js b/02-Day/string_methods/search.js new file mode 100644 index 00000000..e1ea82e9 --- /dev/null +++ b/02-Day/string_methods/search.js @@ -0,0 +1,4 @@ +// search: it takes a substring as an argument and it returns the index of the first match. +// string.search(substring) +let string = 'I love JavaScript. If you do not love JavaScript what else can you love.' +console.log(string.search('love')) // 2 diff --git a/02-Day/string_methods/split.js b/02-Day/string_methods/split.js new file mode 100644 index 00000000..6b0ce6e7 --- /dev/null +++ b/02-Day/string_methods/split.js @@ -0,0 +1,10 @@ +// split(): The split method splits a string at a specified place. +let string = '30 Days Of JavaScipt' +console.log(string.split()) // ["30 Days Of JavaScript"] +console.log(string.split(' ')) // ["30", "Days", "Of", "JavaScript"] +let firstName = 'Asabeneh' +console.log(firstName.split()) // ["Asabeneh"] +console.log(firstName.split('')) // ["A", "s", "a", "b", "e", "n", "e", "h"] +let countries = 'Finland, Sweden, Norway, Denmark, and Iceland' +console.log(countries.split(',')) // ["Finland", " Sweden", " Norway", " Denmark", " and Iceland"] +console.log(countries.split(', ')) // ["Finland", "Sweden", "Norway", "Denmark", "and Iceland"] \ No newline at end of file diff --git a/02-Day/string_methods/starts_with.js b/02-Day/string_methods/starts_with.js new file mode 100644 index 00000000..a89ee3b7 --- /dev/null +++ b/02-Day/string_methods/starts_with.js @@ -0,0 +1,11 @@ +// startsWith: it takes a substring as an argument and it checks if the string starts with that specified substring. It returns a boolean(true or false). +// string.startsWith(substring) +let string = 'Love is the best to in this world' +console.log(string.startsWith('Love')) // true +console.log(string.startsWith('love')) // false +console.log(string.startsWith('world')) // false + +let country = 'Finland' +console.log(country.startsWith('Fin')) // true +console.log(country.startsWith('fin')) // false +console.log(country.startsWith('land')) // false diff --git a/02-Day/string_methods/substr.js b/02-Day/string_methods/substr.js new file mode 100644 index 00000000..0bea56d5 --- /dev/null +++ b/02-Day/string_methods/substr.js @@ -0,0 +1,5 @@ +//substr(): It takes two arguments,the starting index and number of characters to slice. +let string = 'JavaScript' +console.log(string.substr(4,6)) // Script +let country = 'Finland' +console.log(country.substr(3, 4)) // land \ No newline at end of file diff --git a/02-Day/string_methods/substring.js b/02-Day/string_methods/substring.js new file mode 100644 index 00000000..3fac3a16 --- /dev/null +++ b/02-Day/string_methods/substring.js @@ -0,0 +1,9 @@ +// substring(): It takes two arguments,the starting index and the stopping index but it doesn't include the stopping index. +let string = 'JavaScript' +console.log(string.substring(0,4)) // Java +console.log(string.substring(4,10)) // Script +console.log(string.substring(4)) // Script +let country = 'Finland' +console.log(country.substring(0, 3)) // Fin +console.log(country.substring(3, 7)) // land +console.log(country.substring(3)) // land \ No newline at end of file diff --git a/02-Day/string_methods/to_lowercase.js b/02-Day/string_methods/to_lowercase.js new file mode 100644 index 00000000..1a4ab531 --- /dev/null +++ b/02-Day/string_methods/to_lowercase.js @@ -0,0 +1,7 @@ +// toLowerCase(): this method changes the string to lowercase letters. +let string = 'JavasCript' +console.log(string.toLowerCase()) // javascript +let firstName = 'Asabeneh' +console.log(firstName.toLowerCase()) // asabeneh +let country = 'Finland' +console.log(country.toLowerCase()) // finland \ No newline at end of file diff --git a/02-Day/string_methods/to_uppercase.js b/02-Day/string_methods/to_uppercase.js new file mode 100644 index 00000000..112a6d07 --- /dev/null +++ b/02-Day/string_methods/to_uppercase.js @@ -0,0 +1,8 @@ +// toUpperCase(): this method changes the string to uppercase letters. + +let string = 'JavaScript' +console.log(string.toUpperCase()) // JAVASCRIPT +let firstName = 'Asabeneh' +console.log(firstName.toUpperCase()) // ASABENEH +let country = 'Finland' +console.log(country.toUpperCase()) // FINLAND \ No newline at end of file diff --git a/02-Day/string_methods/trim.js b/02-Day/string_methods/trim.js new file mode 100644 index 00000000..16785c43 --- /dev/null +++ b/02-Day/string_methods/trim.js @@ -0,0 +1,7 @@ +//trim(): Removes trailing space in the beginning or the end of a string. +let string = ' 30 Days Of JavaScript ' +console.log(string) // +console.log(string.trim(' ')) // +let firstName = ' Asabeneh ' +console.log(firstName) +console.log(firstName.trim()) // \ No newline at end of file diff --git a/readMe.md b/readMe.md index 512a4c5b..069069c2 100644 --- a/readMe.md +++ b/readMe.md @@ -1,7 +1,7 @@ ## Table of Contents ![Thirty Days Of JavaScript](./images/30DaysOfJavaScript.png) -- [📔 Day 1](#%f0%9f%93%94-day-1) +- [📔Day 1](#%f0%9f%93%94day-1) - [Introduction](#introduction) - [Requirements](#requirements) - [Setup](#setup) @@ -49,7 +49,7 @@ -# 📔 Day 1 +# 📔Day 1 # Introduction **Congratulations** for deciding to participate in a 30 days of JavaScript programming challenge . In this challenge you will learn everything you need to be a JavaScript programmer and in general the whole concepts of programming. In the end of the challenge you will get a 30DaysOfJavaScript programming challenge certificate. Join the [telegram group](https://t.me/ThirtyDaysOfJavaScript). @@ -798,7 +798,7 @@ console.log(country.toLowerCase()) // finland 5. *substr()*: It takes two arguments,the starting index and number of characters to slice. ```js let string = 'JavaScript' -console.log(string.substr(4,6) // Script +console.log(string.substr(4,6)) // Script let country = 'Finland' console.log(country.substr(3, 4)) // land @@ -807,9 +807,9 @@ console.log(country.substr(3, 4)) // land ```js let string = 'JavaScript' -console.log(string.substring(0,4) // Java -console.log(string.substring(4,10) // Script -console.log(string.substring(4) // Script +console.log(string.substring(0,4)) // Java +console.log(string.substring(4,10)) // Script +console.log(string.substring(4)) // Script let country = 'Finland' console.log(country.substring(0, 3)) // Fin console.log(country.substring(3, 7)) // land @@ -1009,7 +1009,7 @@ let regEx = /\d+/ // d with escape character means d not a normal d instead acts console.log(text.match(regEx)) // ["2", "0", "1", "9", "3", "0", "2", "0", "2", "0"] console.log(text.match(/\d+/g)) // ["2019", "30", "2020"] ``` -1. *repeat()*: it takes a number argument and it returned the repeated version of the string. +20. *repeat()*: it takes a number argument and it returned the repeated version of the string. ```js string.repeat(n) ``` @@ -1215,7 +1215,7 @@ Boolean value is either true or false. ## Exercises: Comparison Operators -Figure out the result of the following comparison expression first without using console.log(). After you decide the result confirm it by checking using console.log() +Figure out the result of the following comparison expression first without using console.log(). After you decide the result confirm it using console.log() 1. 4 > 3 1. 4 >= 3 @@ -1230,7 +1230,7 @@ Figure out the result of the following comparison expression first without using 1. 4 === '4' ## Exercises: Logical Operators -Figure out the result of the following expressions first without using console.log() After you decide the result confirm it by checking using console.log() +Figure out the result of the following expressions first without using console.log(). After you decide the result confirm it by using console.log() 1. 4 > 3 && 10 < 12 1. 4 > 3 && 10 > 12 1. 4 > 3 || 10 < 12