pull/113/merge
Kamrul Islam Shahin 5 years ago committed by GitHub
commit 758d35726e
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

@ -231,12 +231,21 @@ console.log(Math.E) // 2.718
console.log(Math.log(2)) // 0.6931471805599453
console.log(Math.log(10)) // 2.302585092994046
// Returns the natural logarithm of 2 and 10 respectively
console.log(Math.LN2) // 0.6931471805599453
console.log(Math.LN10) // 2.302585092994046
// Returns the common logarithm with base 10 of x, Math.log10(x)
console.log(Math.log10(2)) // 0.3010299956639812
console.log(Math.log10(10)) // 1
// Trigonometry
Math.sin(0)
Math.sin(60)
// Returns the value in radians
Math.sin(0) // 0
Math.sin(60) // -0.3048106211
Math.cos(0)
Math.cos(60)
Math.cos(0) // 1
Math.cos(60) // -0.95241298041
```
#### Random Number Generator

@ -390,7 +390,7 @@ Check an element if it exist in an array.
const fruits = ['banana', 'orange', 'mango', 'lemon']
let index = fruits.indexOf('banana') // 0
if(index != -1){
if(index != -1) {
console.log('This fruit does exist in the array')
} else {
console.log('This fruit does not exist in the array')
@ -398,11 +398,13 @@ if(index != -1){
// This fruit does exist in the array
// we can use also ternary here
index != -1 ? console.log('This fruit does exist in the array'): console.log('This fruit does not exist in the array')
index != -1
? console.log('This fruit does exist in the array')
: console.log('This fruit does not exist in the array')
// let us check if a avocado exist in the array
let indexOfAvocado = fruits.indexOf('avocado') // -1, if the element not found index is -1
if(indexOfAvocado!= -1){
if(indexOfAvocado != -1) {
console.log('This fruit does exist in the array')
} else {
console.log('This fruit does not exist in the array')

@ -178,7 +178,7 @@ for (const num of numbers) {
// adding all the numbers in the array
let sum = 0
for (const num of numbers) {
sum += sum + num // can be also shorten like this, sum += num
sum = sum + num // can be also shorten like this, sum += num
}
console.log(sum) // 15

@ -239,7 +239,7 @@ function sumAllNums() {
console.log(arguments)
}
sumAllNums(1, 2, 3, 4))
sumAllNums(1, 2, 3, 4)
// Arguments(4) [1, 2, 3, 4, callee: ƒ, Symbol(Symbol.iterator): ƒ]
```
@ -269,11 +269,11 @@ console.log(sumAllNums(15, 20, 30, 25, 10, 33, 40)) // 173
const sumAllNums = (...args) => {
// console.log(arguments), arguments object not found in arrow function
// instead we use an a parameter followed by spread operator
// instead we use an a parameter followed by spread operator (...)
console.log(args)
}
sumAllNums(1, 2, 3, 4))
sumAllNums(1, 2, 3, 4)
// [1, 2, 3, 4]
```

@ -125,7 +125,6 @@ Now, you have an understanding of scope. A variable declared with *var* only sco
function letsLearnScope() {
var gravity = 9.81
console.log(gravity)
}
// console.log(gravity), Uncaught ReferenceError: gravity is not defined
@ -136,9 +135,9 @@ if (true){
console.log(gravity) // 9.81
for(var i = 0; i < 3; i++){
console.log(i) // 1, 2, 3
console.log(i) // 0, 1, 2
}
console.log(i)
console.log(i) // 3
```
@ -150,7 +149,6 @@ function letsLearnScope() {
// you can use let or const, but gravity is constant I prefer to use const
const gravity = 9.81
console.log(gravity)
}
// console.log(gravity), Uncaught ReferenceError: gravity is not defined
@ -161,13 +159,13 @@ if (true){
// console.log(gravity), Uncaught ReferenceError: gravity is not defined
for(let i = 0; i < 3; i++){
console.log(i) // 1, 2, 3
console.log(i) // 0, 1, 2
}
// console.log(i), Uncaught ReferenceError: gravity is not defined
```
The scope *let* and *const* is the same. The difference is only reassigning. We can not change or reassign the value of const variable. I would strongly suggest you to use *let* and *const*, by using *let* and *const* you will writ clean code and avoid hard to debug mistakes. As a rule of thumb, you can use *let* for any value which change, *const* for any constant value, and for array, object, arrow function and function expression.
The scope *let* and *const* are the same. The difference is only reassigning. We can not change or reassign the value of the const variable. I would strongly suggest you to use *let* and *const*, by using *let* and *const* you will write clean code and avoid hard to debug mistakes. As a rule of thumb, you can use *let* for any value which change, *const* for any constant value, and for an array, object, arrow function and function expression.
## 📔 Object
@ -250,14 +248,14 @@ const person = {
console.log(person.firstName)
console.log(person.lastName)
console.log(person.age)
console.log(person.location)
console.log(person.location) // undefined value
// value can be accessed using square bracket and key name
console.log(person['firstName'])
console.log(person['lastName'])
console.log(person['age'])
console.log(person['age'])
console.log(person['location'])
console.log(person['city'])
console.log(person['location']) // undefined value
// for instance to access the phone number we only use the square bracket method
console.log(person['phone number'])

@ -97,7 +97,7 @@ const sumArray = arr => {
const callBack = function(element) {
sum += element
}
numbers.forEach(callback)
arr.forEach(callBack)
return sum
}
@ -115,7 +115,7 @@ const numbers = [1, 2, 3, 4]
const sumArray = arr => {
let sum = 0
numbers.forEach(function(element) {
arr.forEach(function(element) {
sum += element
})
return sum
@ -196,7 +196,7 @@ arr.forEach((element, index, arr) => console.log(index, element, arr))
```js
let sum = 0;
const numbers = [1,2,3,4,5];
numbers.forEach(num => console.log(num)))
numbers.forEach(num => console.log(num))
console.log(sum)
```
@ -207,12 +207,13 @@ console.log(sum)
3
4
5
0
```
```js
let sum = 0;
const numbers = [1,2,3,4,5];
numbers.forEach(num => sum += num))
numbers.forEach(num => sum += num)
console.log(sum)
```
@ -355,8 +356,8 @@ const scores = [
{ name: 'John', score: 100 },
]
const scoresGreaterEight = scores.filter((score) => score.score > 80)
console.log(scoresGreaterEight)
const scoresGreaterEighty = scores.filter((score) => score.score > 80)
console.log(scoresGreaterEighty)
```
```sh

@ -246,7 +246,7 @@ Set(6) {1, 2, 3, 4, 5,6}
### Intersection of sets
To find an intersection of two sets can be achieved using filter. Lets find the union of set A and set B (A ∩ B)
To find an intersection of two sets can be achieved using filter. Lets find the intersection of set A and set B (A ∩ B)
```js
let a = [1, 2, 3, 4, 5]
@ -417,7 +417,8 @@ const countries = ['Finland', 'Sweden', 'Norway']
```js
// Your output should look like this
console.log(mostSpokenLanguages(countries, 10))[
console.log(mostSpokenLanguages(countries, 10))
[
({ English: 91 },
{ French: 45 },
{ Arabic: 25 },
@ -433,19 +434,13 @@ const countries = ['Finland', 'Sweden', 'Norway']
// Your output should look like this
console.log(mostSpokenLanguages(countries, 3))
[
{'English':91},
{'French':45},
{'Arabic':25}
]
```
[
{'English':91},
{'French':45},
{'Arabic':25}
]
```
🎉 CONGRATULATIONS ! 🎉
[<< Day 9](../09_Day_Higher_order_functions/09_day_higher_order_functions.md) | [Day 11>>](../11_Day_Destructuring_and_spreading/11_day_destructuring_and_spreading.md)
```

@ -258,7 +258,6 @@ const calculatePerimeter = rectangle => {
}
console.log(calculatePerimeter(rect)) // 60
//with destructuring
```
```js
@ -305,7 +304,7 @@ console.log(getPersonInfo(person))
### Object parameter with destructuring
```js
//with destructuring
const calculatePerimeter = ({ width, height }) => {
return 2 * (width + height)
}

@ -348,7 +348,7 @@ Zero or many times. The pattern could may not occur or it can occur many times.
```js
const pattern = /[a].*/g //. any character, + any character one or more times
const pattern = /[a].*/g //. any character, * any character zero or more times
const txt = 'Apple and banana are fruits'
const matches = txt.match(pattern)
@ -429,12 +429,11 @@ console.log(result) // true
1. Calculate the total annual income of the person from the following text. He earns 4000 euro from salary per month, 10000 euro annual bonus, 5500 euro online courses per month.
1. The position of some particles on the horizontal x-axis -12, -4, -3 and -1 in the negative direction, 0 at origin, 4 and 8 in the positive direction. Extract these numbers and find the distance between the two furthest particles.
```js
points = ['-1', '2', '-4', '-3', '-1', '0', '4', '8']
sortedPoints = [-4, -3, -1, -1, 0, 2, 4, 8]
distance = 12
```
```js
points = ['-1', '2', '-4', '-3', '-1', '0', '4', '8']
sortedPoints = [-4, -3, -1, -1, 0, 2, 4, 8]
distance = 12
```
1. Write a pattern which identify if a string is a valid JavaScript variable
```sh
@ -484,7 +483,8 @@ distance = 12
```
```sh
[{word:'love', count:6},
[
{word:'love', count:6},
{word:'you', count:5},
{word:'can', count:3},
{word:'what', count:2},
@ -499,7 +499,7 @@ distance = 12
### Exercises: Level 3
1. Writ a function which cleans text. Clean the following text. After cleaning, count three most frequent words in the string.
1. Write a function which cleans text. Clean the following text. After cleaning, count three most frequent words in the string.
```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!?`
@ -514,11 +514,12 @@ distance = 12
```js
console.log(mostFrequentWords(cleanedText))
[{word:'I', count:3}, {word:'teaching', count:2}, {word:'teacher', count:2}]
```
```sh
[{word:'I', count:3}, {word:'teaching', count:2}, {word:'teacher', count:2}]
```
🎉 CONGRATULATIONS ! 🎉
[<< Day 11](../11_Day_Destructuring_and_spreading/11_day_destructuring_and_spreading.md) | [Day 13>>](../13_Day_Console_object_methods/13_day_console_object_methods.md)

@ -66,13 +66,13 @@ class Person {
}
```
We have created an Person class but it does not have any thing inside.
We have created a Person class but it does not have anything inside.
### Class Instantiation
Instantiation class means creating an object from a class. We need the keyword _new_ and we call the name of the class after the word new.
Let us create a dog object from our Person class.
Let us create a person object from our Person class.
```js
class Person {
@ -92,7 +92,7 @@ Let use the class constructor to pass different properties for the class.
### Class Constructor
The constructor is a builtin function which allows as to create a blueprint for our object. The constructor function starts with a keyword constructor followed by a parenthesis. Inside the parenthesis we pass the properties of the object as parameter. We use the _this_ keyword to attach the constructor parameters with the class.
The constructor is a builtin function which allows us to create a blueprint for our object. The constructor function starts with a keyword constructor followed by a parenthesis. Inside the parenthesis we pass the properties of the object as parameter. We use the _this_ keyword to attach the constructor parameters with the class.
The following Person class constructor has firstName and lastName property. These properties are attached to the Person class using _this_ keyword. _This_ refers to the class itself.
@ -111,7 +111,7 @@ console.log(person)
```
```sh
Person {firstName: undefined, lastName}
Person {firstName: undefined, lastName: undefined}
```
All the keys of the object are undefined. When ever we instantiate we should pass the value of the properties. Let us pass value at this time when we instantiate the class.
@ -243,12 +243,12 @@ console.log(person2.getFullName())
```sh
Asabeneh Yetayeh
test.js:19 Lidiya Tekle
Lidiya Tekle
```
### Properties with initial value
When we create a class for some properties we may have an initial value. For instance if you are playing a game, you starting score will be zero. So, we may have a starting score or score which is zero. In other way, we may have an initial skill and we will acquire some skill after some time.
When we create a class for some properties we may have an initial value. For instance if you are playing a game, your starting score will be zero. So, we may have a starting score or score which is zero. In other way, we may have an initial skill and we will acquire some skill after some time.
```js
class Person {
@ -551,11 +551,11 @@ The static methods are methods which can be used as utility functions.
## Inheritance
Using inheritance we can access all the properties and the methods of the parent class. This reduces repetition of code. If you remember, we have a Person parent class and we will create children from it. Our children class could be student, teach etc.
Using inheritance we can access all the properties and the methods of the parent class. This reduces repetition of code. If you remember, we have a Person parent class and we will create children from it. Our children class could be student, teacher etc.
```js
// syntax
class ChildClassName extends {
class ChildClassName extends ParentClassName {
// code goes here
}
```
@ -569,7 +569,7 @@ class Student extends Person {
}
}
const s1 = new Student('Asabeneh', 'Yetayeh', 'Finland', 250, 'Helsinki')
const s1 = new Student('Asabeneh', 'Yetayeh', 250, 'Finland', 'Helsinki')
console.log(s1)
console.log(s1.saySomething())
console.log(s1.getFullName())
@ -577,11 +577,10 @@ console.log(s1.getPersonInfo())
```
```sh
Student {firstName: "Asabeneh", lastName: "Yetayeh", age: "Finland", country: 250, city: "Helsinki", …}
Student {firstName: "Asabeneh", lastName: "Yetayeh", age: 250, country: "Finland", city: "Helsinki", …}
I am a child of the person class
Asabeneh Yetayeh
Student {firstName: "Asabeneh", lastName: "Yetayeh", age: "Finland", country: 250, city: "Helsinki", …}
Asabeneh Yetayeh is Finland. He lives Helsinki, 250.
Asabeneh Yetayeh is 250. He lives Helsinki, Finland.
```
### Overriding methods
@ -605,8 +604,8 @@ class Student extends Person {
this.skills.slice(0, this.skills.length - 1).join(', ') +
` and ${this.skills[this.skills.length - 1]}`
let formattedSkills = skills ? `He knows ${skills}` : ''
let pronoun = this.gender == 'Male' ? 'He' : 'She'
let formattedSkills = skills ? `${pronoun} knows ${skills}` : ''
let info = `${fullName} is ${this.age}. ${pronoun} lives in ${this.city}, ${this.country}. ${formattedSkills}`
return info
@ -633,6 +632,7 @@ s2.setSkill = 'Managing'
s2.setSkill = 'Organizing'
console.log(s1)
console.log(s2)
console.log(s1.saySomething())
console.log(s1.getFullName())
@ -648,12 +648,10 @@ Student {firstName: "Asabeneh", lastName: "Yetayeh", age: 250, country: "Finlan
Student {firstName: "Lidiya", lastName: "Tekle", age: 28, country: "Finland", city: "Helsinki", …}
I am a child of the person class
Asabeneh Yetayeh
Student {firstName: "Asabeneh", lastName: "Yetayeh", age: 250, country: "Finland", city: "Helsinki", …}
Asabeneh Yetayeh is 250. He lives in Helsinki, Finland. He knows HTML, CSS and JavaScript
I am a child of the person class
Lidiya Tekle
Student {firstName: "Lidiya", lastName: "Tekle", age: 28, country: "Finland", city: "Helsinki", …}
Lidiya Tekle is 28. She lives in Helsinki, Finland. He knows Planning, Managing and Organizing
Lidiya Tekle is 28. She lives in Helsinki, Finland. She knows Planning, Managing and Organizing
```
Now, the getPersonInfo method has been overridden and it identifies if the person is male or female.
@ -675,38 +673,38 @@ Now, the getPersonInfo method has been overridden and it identifies if the perso
1. Let's try to develop a program which calculate measure of central tendency of a sample(mean, median, mode) and measure of variability(range, variance, standard deviation). In addition to those measures find the min, max, count, percentile, and frequency distribution of the sample. You can create a class called Statistics and create all the functions which do statistical calculations as method for the Statistics class. Check the output below.
```JS
ages = [31, 26, 34, 37, 27, 26, 32, 32, 26, 27, 27, 24, 32, 33, 27, 25, 26, 38, 37, 31, 34, 24, 33, 29, 26]
console.log('Count:', statistics.count()) // 25
console.log('Sum: ', statistics.sum()) // 744
console.log('Min: ', statistics.min()) // 24
console.log('Max: ', statistics.max()) // 38
console.log('Range: ', statistics.range() // 14
console.log('Mean: ', statistics.mean()) // 30
console.log('Median: ',statistics.median()) // 29
console.log('Mode: ', statistics.mode()) // {'mode': 26, 'count': 5}
console.log('Variance: ',statistics.var()) // 17.5
console.log('Standard Deviation: ', statistics.std()) // 4.2
console.log('Variance: ',statistics.var()) // 17.5
console.log('Frequency Distribution: ',statistics.freqDist()) // [(20.0, 26), (16.0, 27), (12.0, 32), (8.0, 37), (8.0, 34), (8.0, 33), (8.0, 31), (8.0, 24), (4.0, 38), (4.0, 29), (4.0, 25)]
```
```sh
// you output should look like this
console.log(statistics.describe())
Count: 25
Sum: 744
Min: 24
Max: 38
Range: 14
Mean: 30
Median: 29
Mode: (26, 5)
Variance: 17.5
Standard Deviation: 4.2
Frequency Distribution: [(20.0, 26), (16.0, 27), (12.0, 32), (8.0, 37), (8.0, 34), (8.0, 33), (8.0, 31), (8.0, 24), (4.0, 38), (4.0, 29), (4.0, 25)]
```
```JS
ages = [31, 26, 34, 37, 27, 26, 32, 32, 26, 27, 27, 24, 32, 33, 27, 25, 26, 38, 37, 31, 34, 24, 33, 29, 26]
console.log('Count:', statistics.count()) // 25
console.log('Sum: ', statistics.sum()) // 744
console.log('Min: ', statistics.min()) // 24
console.log('Max: ', statistics.max()) // 38
console.log('Range: ', statistics.range() // 14
console.log('Mean: ', statistics.mean()) // 30
console.log('Median: ',statistics.median()) // 29
console.log('Mode: ', statistics.mode()) // {'mode': 26, 'count': 5}
console.log('Variance: ',statistics.var()) // 17.5
console.log('Standard Deviation: ', statistics.std()) // 4.2
console.log('Variance: ',statistics.var()) // 17.5
console.log('Frequency Distribution: ',statistics.freqDist()) // [(20.0, 26), (16.0, 27), (12.0, 32), (8.0, 37), (8.0, 34), (8.0, 33), (8.0, 31), (8.0, 24), (4.0, 38), (4.0, 29), (4.0, 25)]
```
```sh
// you output should look like this
console.log(statistics.describe())
Count: 25
Sum: 744
Min: 24
Max: 38
Range: 14
Mean: 30
Median: 29
Mode: (26, 5)
Variance: 17.5
Standard Deviation: 4.2
Frequency Distribution: [(20.0, 26), (16.0, 27), (12.0, 32), (8.0, 37), (8.0, 34), (8.0, 33), (8.0, 31), (8.0, 24), (4.0, 38), (4.0, 29), (4.0, 25)]
```
1. Create a class called PersonAccount. It has firstname, lastname, incomes, expenses properties and it has totalIncome, totalExpense, accountInfo,addIncome, addExpense and accountBalance methods. Incomes is a set of incomes and its description and expenses is also a set of expenses and its description.

@ -63,7 +63,7 @@ JSON stands for JavaScript Object Notation. The JSON syntax is derived from Java
}
```
The above JSON example is not much different for a normal object. Then, what is the difference ? The difference is the key of a JSON object should be with double quotes or it should be a string. JavaScript Object and JSON are very similar that we can change JSON to Object and Object to JSON.
The above JSON example is not much different from a normal object. Then, what is the difference ? The difference is the key of a JSON object should be with double quotes or it should be a string. JavaScript Object and JSON are very similar that we can change JSON to Object and Object to JSON.
Let us see the above example in more detail, it starts with a curly bracket. Inside the curly bracket, there is "users" key which has a value array. Inside the array we have different objects and each objects has keys, each keys has to have double quotes. For instance, we use "firstNaMe" instead of just firstName, however in object we use keys without double quotes. This is the major difference between an object and a JSON. Let's see more examples about JSON.
@ -590,7 +590,7 @@ const txt = `{
### Exercises Level 3
1. Parse the *txt* JSON to object.
2. Find the the user who has many skills from the variable stored in *txt*.
2. Find the user who has many skills from the variable stored in *txt*.
🎉 CONGRATULATIONS ! 🎉

@ -77,7 +77,7 @@ For the examples mentioned above, it makes sense to use localStorage. You may be
In cases, we want to to get rid of the data as soon as the window is closed. Or, perhaps, if we do not want the application to interfere with the same application thats open in another window. These scenarios are served best with sessionStorage.
Now, let use how use make use of these Web Storage APIs.
Now, let us how users make use of these Web Storage APIs.
## HTML5 Web Storage Objects
@ -90,7 +90,7 @@ Web Storage objects:
- _localStorage_ - to display the localStorage object
- _localStorage.clear()_ - to remove everything in the local storage
- _localStorage.setItem()_ - to storage data in the localStorage. It takes a key and a value parameters.
- _localStorage.setItem()_ - to store data in the localStorage. It takes a key and a value parameters.
- _localStorage.getItem()_ - to display data stored in the localStorage. It takes a key as a parameter.
- _localStorage.removeItem()_ - to remove stored item form a localStorage. It takes key as a parameter.
- _localStorage.key()_ - to display a data stored in a localStorage. It takes index as a parameter.

@ -106,7 +106,7 @@ doSomething((err, result) => {
### Promise constructor
We can create a promise using the Promise constructor. We can create a new promise using the key word new followed by the word Promise and followed by a parenthesis. Inside the parenthesis it it takes a callback function. The promise callback function has two parameters which are the *resolve* and *reject* functions.
We can create a promise using the Promise constructor. We can create a new promise using the key word *new* followed by the word Promise and followed by a parenthesis. Inside the parenthesis it takes a callback function. The promise callback function has two parameters which are the *resolve* and *reject* functions.
```js
// syntax
@ -169,7 +169,7 @@ doPromise
## Fetch API
The Fetch API provides an interface for fetching resources (including across the network). It will seem familiar to anyone who has used XMLHttpRequest, but the new API provides a more powerful and flexible feature set. In this challenge we will use fetch to request url and APIS. In addition to that let us see demonstrate use case of promises in accessing network resources using the fetch API.
The Fetch API provides an interface for fetching resources (including across the network). It will seem familiar to anyone who has used XMLHttpRequest, but the new API provides a more powerful and flexible feature set. In this challenge we will use fetch to request url and APIs. In addition to that let us see demonstrate use case of promises in accessing network resources using the fetch API.
```js
const url = 'https://restcountries.eu/rest/v2/all' // countries api
@ -244,7 +244,7 @@ console.log('===== async and await')
fetchData()
```
🌕 You are real and you kept your promise and your reached to day 18. Keep your promise and settle the challenge with resolve. You are 18 steps a head to your way to greatness. Now do some exercises for your brain and for your muscle.
🌕 You are real and you kept your promise and your reached to day 18. Keep your promise and settle the challenge with resolve. You are 18 steps ahead to your way to greatness. Now do some exercises for your brain and for your muscle.
## Exercises

@ -80,7 +80,7 @@ console.log(innerFuncs.minusOne)
```sh
1
1
0
```
🌕 You are making progress. Maintain your momentum, keep the good work. Now do some exercises for your brain and for your muscle.

@ -196,7 +196,7 @@ const names = ['Asabeneh', 'Mathias', 'Elias', 'Brook']
// iterating an array using regular for loop
let len = names.length;
for(let i = 0; i < len; i++){
console.log(names[i].toUpperCas())
console.log(names[i].toUpperCase())
}
@ -218,7 +218,7 @@ const person = {
skills: ['HTML','CSS','JavaScript','React','Node','MongoDB','Python','D3.js'],
isMarried: true
}
for(const key in user) {
for(const key in person) {
console.log(key)
}

@ -74,7 +74,7 @@ We can access already created element or elements using JavaScript. To access or
#### Getting elements by tag name
**_getElementsByTagName()_**:takes a take name as a string parameter and this method returns an HTMLCollection object. An HTMLCollection is an array like object of HTML elements. The length property provides the size of the collection. Whenever we use this method we access the individual elements using index or after loop through each individual items. An HTMLCollection does not support all array methods therefore we should use regular for loop instead of forEach.
**_getElementsByTagName()_**:takes a tag name as a string parameter and this method returns an HTMLCollection object. An HTMLCollection is an array like object of HTML elements. The length property provides the size of the collection. Whenever we use this method we access the individual elements using index or after loop through each individual items. An HTMLCollection does not support all array methods therefore we should use regular for loop instead of forEach.
```js
// syntax
@ -84,7 +84,7 @@ document.getElementsByTagName('tagname')
```js
const allTitles = document.getElementsByTagName('h1')
console.log(allTitles) //HTMCollections
console.log(allTitles) //HTMLCollections
console.log(allTitles.length) // 4
for (let i = 0; i < allTitles.length; i++) {
@ -104,7 +104,7 @@ document.getElementsByClassName('classname')
```js
const allTitles = document.getElementsByClassName('title')
console.log(allTitles) //HTMCollections
console.log(allTitles) //HTMLCollections
console.log(allTitles.length) // 4
for (let i = 0; i < allTitles.length; i++) {
@ -133,9 +133,9 @@ The _document.querySelector_ method can select an HTML or HTML elements by tag n
**_querySelector_**: can be used to select HTML element by its tag name, id or class. If the tag name is used it selects only the first element.
```js
let firstTitle = document.querySelector('h1') // select the first available h2 element
let firstTitle = document.querySelector('h1') // select the first available h1 element
let firstTitle = document.querySelector('#first-title') // select id with first-title
let firstTitle = document.querySelector('.title') // select the first available h2 element with class title
let firstTitle = document.querySelector('.title') // select the first available h1 element with class title
```
**_querySelectorAll_**: can be used to select html element by its tag name or class. It return a nodeList which is an array like object which support array methods. We can use **_for loop_** or **_forEach_** to loop through each nodeList elements.
@ -158,7 +158,7 @@ An attribute is added in the opening tag of HTML which gives additional informat
```js
const titles = document.querySelectorAll('h1')
titles[3].class = 'title'
titles[3].className = 'title'
titles[3].id = 'fourth-title'
```
@ -214,7 +214,7 @@ const titles = document.querySelectorAll('h1')
titles[3].textContent = 'Fourth Title'
```
#### Adding Text Content using innHTML
#### Adding Text Content using innerHTML
Most people get confused between _textContent_ and _innerHTML_. _textContent_ is meant to add text to an HTML element, however innerHTML can add a text or HTML element or elements as a child.

@ -174,7 +174,7 @@ By now you are familiar with addEventListen method and how to attach event liste
List of events:
- click - when the element clicked
- dbclick - when the element double clicked
- dblclick - when the element double clicked
- mouseenter - when the mouse point enter to the element
- mouseleave - when the mouse pointer leave the element
- mousemove - when the mouse pointer move on the element

@ -255,7 +255,7 @@ So far, we saw how to display text using the _console.log()_. If we are printing
```js
console.log('Hello, World!')
console.log('Hello, World!')
console.log("Hello, World!")
console.log(`Hello, World!`)
```
@ -463,8 +463,9 @@ A collection of one or more characters between two single quotes, double quotes,
'Finland'
'JavaScript is a beautiful programming language'
'I love teaching'
'I hope you are enjoying the first day'`We can also create a string using a backtick`
;('A string could be just as small as one character as big as many pages')
"I hope you are enjoying the first day"
`We can also create a string using a backtick`
('A string could be just as small as one character as big as many pages')
```
### Booleans

Loading…
Cancel
Save