diff --git a/02-Day/index.html b/02-Day/index.html new file mode 100644 index 00000000..b34fd010 --- /dev/null +++ b/02-Day/index.html @@ -0,0 +1,15 @@ + + + + + 30DaysOfJavaScript + + + + + + + + + + \ No newline at end of file diff --git a/02-Day/main.js b/02-Day/main.js new file mode 100644 index 00000000..77629084 --- /dev/null +++ b/02-Day/main.js @@ -0,0 +1 @@ +// this is your main.js script \ 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 9d33d16f..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) @@ -43,25 +43,13 @@ - [Concatenating using addition operator](#concatenating-using-addition-operator) - [Template Literals(Template Strings)](#template-literalstemplate-strings) - [String Methods](#string-methods) -- [Booleans](#booleans-1) - - [Undefined](#undefined-1) - - [Null](#null-1) -- [Operators](#operators) - - [Assignment operators](#assignment-operators) - - [Arithmetic Operators](#arithmetic-operators) - - [Comparison Operators](#comparison-operators) - - [Logical Operators](#logical-operators) -- [💻 Day 2: Exercises](#%f0%9f%92%bb-day-2-exercises) - - [String Part](#string-part) - - [Data types Part](#data-types-part) - - [Arithmetic Operators Part](#arithmetic-operators-part) - - [Booleans Part](#booleans-part) - - [Comparison Operators](#comparison-operators-1) - - [Logical Operators](#logical-operators-1) - - - -# 📔 Day 1 + - [Exercises: Booleans Part](#exercises-booleans-part) + - [Exercises: Comparison Operators](#exercises-comparison-operators) + - [Exercises: Logical Operators](#exercises-logical-operators) + + + +# 📔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). @@ -810,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 @@ -819,16 +807,16 @@ 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 console.log(country.substring(3)) // land ``` -7. *split(): The split method splits a string at a specified place. +7. *split()*: The split method splits a string at a specified place. ```js let string = '30 Days Of JavaScipt' @@ -926,7 +914,7 @@ console.log(string.indexOf('script')) // -1 ``` 14. *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 ```js -string.charCodeAt(index) +string.lastIndexOf(index) ``` ```js let string = 'I love JavaScript. If you do not love JavaScript what else can you love.' @@ -936,9 +924,9 @@ console.log(string.lastIndexOf('JavaScript')) // 38 ``` -15. *concat()*: it takes many substrings and creates concatenation. +15. *concat()*: it takes many substrings and creates concatenation. ```js -string.concate(substring, substring, substring) +string.concat(substring, substring, substring) ``` ```js let string = '30' @@ -948,7 +936,7 @@ console.log(country.concat("land")) // Finland ``` -16. *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). +16. *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). ```js string.startsWith(substring) ``` @@ -964,7 +952,7 @@ console.log(country.startsWith('fin')) // false console.log(country.startsWith('land')) // false ``` -17. *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). +17. *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). ```js string.endsWith(substring) ``` @@ -980,16 +968,16 @@ console.log(country.endsWith('fin')) // false console.log(country.endsWith('Fin')) // false ``` -18. *search*: it takes a substring as an argument and it returns the index of the first match. +18. *search*: it takes a substring as an argument and it returns the index of the first match. ```js -string.serch(substring) +string.search(substring) ``` ```js let string = 'I love JavaScript. If you do not love JavaScript what else can you love.' console.log(string.search('love')) // 2 ``` -1. *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 expresson pattern looks like. It starts with / sign and ends with / sign. +19. *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. ```js let string = 'love' let patternOne = /love/ // with out any flag @@ -1021,6 +1009,13 @@ 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"] ``` +20. *repeat()*: it takes a number argument and it returned the repeated version of the string. +```js +string.repeat(n) +``` +```js +let string = 'love' +console.log(string.repeat(10)) // lovelovelovelovelovelovelovelovelovelove # Booleans @@ -1030,7 +1025,7 @@ A boolean data type represents one of the two values:_true_ or _false_. Boolean ```js let isLightOn = true; let isRaining = false; -let hungery = false; +let isHungery = false; let isMarried = true; ``` @@ -1118,23 +1113,20 @@ console.log(2 < 3) // true, because 2 is less than 3 console.log(2 <= 3) // true, because 2 is less than 3 console.log(3 == 2) // false, because 3 is not equal to 2 console.log(3 != 2) // true, because 3 is not equal to 2 -console.log(len('mango') == len('avocado')) // false -console.log(len('mango') != len('avocado')) // true -console.log(len('mango') < len('avocado')) // true -console.log(len('milk') != len('meat')) // false -console.log(len('milk') == len('meat')) // true -console.log(len('tomato') == len('potato')) // true -console.log(len('python') > len('dragon')) // false - -4 > 3; -4 >= 4; -4 < 3; -4 <= 3; -4 != 3; -4 !== '4'; -4 == '4'; -4 === '4'; -4 === 4; +console.log(3 == '3') // true, compare only value +console.log(3 === '3') // false, compare both value and data type +console.log(3 !== '3') // true, compare both value and data type +console.log(3 !== '3') // true, compare both value and data type +console.log(3 != 3) // false, compare only value +console.log(3 !== 3) // false, compare both value and data type + +console.log('mango'.length == 'avocado'.length) // false +console.log('mango'.length != 'avocado'.length) // true +console.log('mango'.length < 'avocado'.length) // true +console.log('milk'.length != 'meat'.length) // false +console.log('milk'.length == 'meat'.length) // true +console.log('tomato'.length == 'potato'.length) // true +console.log('python'.length > 'dragon'.length) // false ``` ## Logical Operators @@ -1165,7 +1157,7 @@ let isMarried = !false; // -> true # 💻 Day 2: Exercises -## String Part +## Exercises: String Part 1. Declare a variable name challenge and assign it to an initial value **'30 Days Of JavaScript'**. 2. Print the string on the browser console using __console.log()__ @@ -1196,18 +1188,17 @@ let isMarried = !false; // -> true 27. Use __repeat()__ method to print 30 Days Of JavaScript 2 times 28. Love is the best thing in this world. Some found their love and some are still looking for their love. Count the number of word love in this sentence. 29. Calculate the total annual income of the person by extract the numbers from the following text. 'He earns 5000 euro from salary per month, 10000 euro annual bonus, 15000 euro online courses per month.' -30. Clean the following text(hint, use replace and regular express) +30. Clean the following text and find the most frequent word(hint, use replace and regular express). ```js - sentence = '%I $am@% a %tea@cher%, &and& I lo%#ve %tea@ching%;. There $is nothing; &as& mo@re rewarding as educa@ting &and& @emp%o@wering peo@ple. ;I found tea@ching m%o@re interesting tha@n any other %jo@bs. %Do@es thi%s mo@tivate yo@u to be a tea@cher!?' + const sentence = '%I $am@% a %tea@cher%, &and& I lo%#ve %tea@ching%;. There $is nothing; &as& mo@re rewarding as educa@ting &and& @emp%o@wering peo@ple. ;I found tea@ching m%o@re interesting tha@n any other %jo@bs. %Do@es thi%s mo@tivate yo@u to be a tea@cher!? %Th#is 30#Days&OfJavaScript &is also $the $result of &love& of tea&ching' ``` -## Data types Part - -String, number, boolean, null, undefined and symbol(ES6) are JavaScript primitive data types. +## Exercises: Data types Part +1. Declare firstName, lastName, country, city, age, isMarried, year variable and assign value to it 1. The JavaScript typeof operator uses to check different data types. Check the data type of each variables from question number 1. -2. + ## Arithmetic Operators Part -JavaScript arithmetic operators are addition(+), subtraction(-), multiplication(\*), division(/), modulus(%), increment(++) and decrement(--). +JavaScript arithmetic operators are addition(+), subtraction(-), multiplication(*), division(/), modulus(%), exponential(**), increment(++) and decrement(--). ```js let operandOne = 4; @@ -1215,31 +1206,16 @@ let operandTwo = 3; ``` Using the above operands apply different JavaScript arithmetic operations. -## Booleans Part +## Exercises: Booleans Part Boolean value is either true or false. 1. Write three JavaScript statement which provide truthy value. 1. Write three JavaScript statement which provide falsy value. -1. Use all the following comparison operators to compare the following values: >, < >=, <=, !=, !==,===. - Which are true or which are false ? - 1. 4 > 3 - 1. 4 >= 3 - 1. 4 < 3 - 1. 4 <= 3 - 1. 4 == 4 - 1. 4 === 4 - 1. 4 != 4 - 1. 4 !== 4 - 1. 4 != '4' - 1. 4 == '4' - 1. 4 === '4' -## Comparison Operators +## Exercises: Comparison Operators -Boolean value is either true or false. Any comparison return a boolean either true or false. -Use all the following comparison operators to compare the following values: >, < >=, <=, !=, !==,===. -Which are true or which are false ? +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 @@ -1253,10 +1229,8 @@ Which are true or which are false ? 1. 4 == '4' 1. 4 === '4' -## Logical Operators - -Which are true or which are false ? - +## Exercises: Logical Operators +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