content restructured

pull/16/head
Asabeneh 6 years ago
parent 0e8a4aa3be
commit d8e0fe2fe9

@ -74,14 +74,17 @@ Primitive data types are compared by its values. Let us compare different data v
```js ```js
let numOne = 3 let numOne = 3
let numTwo = 3 let numTwo = 3
console.log(numOne == numTwo) // true console.log(numOne == numTwo) // true
let js = 'JavaScript' let js = 'JavaScript'
let py = 'Python' let py = 'Python'
console.log(js == py) //false console.log(js == py) //false
let lightOn = true let lightOn = true
let lightOff = false let lightOff = false
console.log(lightOn == lightOff) // false console.log(lightOn == lightOff) // false
``` ```
@ -93,6 +96,7 @@ Let us see by creating an array. An array is a list of data values in a square b
```js ```js
let nums = [1, 2, 3] let nums = [1, 2, 3]
nums[0] = 10 nums[0] = 10
console.log(nums) // [10, 2, 3] console.log(nums) // [10, 2, 3]
``` ```
@ -101,6 +105,7 @@ As you can see, an array in which a non-primitive data type is mutable. Non-prim
```js ```js
let nums = [1, 2, 3] let nums = [1, 2, 3]
let numbers = [1, 2, 3] let numbers = [1, 2, 3]
console.log(nums == numbers) // false console.log(nums == numbers) // false
let userOne = { let userOne = {
@ -108,11 +113,13 @@ name:'Asabeneh',
role:'teaching', role:'teaching',
country:'Finland' country:'Finland'
} }
let userTwo = { let userTwo = {
name:'Asabeneh', name:'Asabeneh',
role:'teaching', role:'teaching',
country:'Finland' country:'Finland'
} }
console.log(userOne == userTwo) console.log(userOne == userTwo)
``` ```
@ -122,6 +129,7 @@ Non-primitive values are referred to as reference types because they are being c
```js ```js
let nums = [1, 2, 3] let nums = [1, 2, 3]
let numbers = nums let numbers = nums
console.log(nums == numbers) // true console.log(nums == numbers) // true
let userOne = { let userOne = {
@ -129,7 +137,9 @@ name:'Asabeneh',
role:'teaching', role:'teaching',
country:'Finland' country:'Finland'
} }
let userTwo = userOne let userTwo = userOne
console.log(userOne == userTwo) // true console.log(userOne == userTwo) // true
``` ```
@ -151,6 +161,7 @@ const PI = 3.14 // pi a geometrical constant
//More Examples //More Examples
const boilingPoint = 100 // temperature in oC, boiling point of water which is a constant 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 const bodyTemp = 37 // oC average human body temperature, which is a constant
console.log(age, gravity, mass, PI, boilingPoint, bodyTemp) console.log(age, gravity, mass, PI, boilingPoint, bodyTemp)
``` ```
@ -177,7 +188,8 @@ 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 const randNum = Math.random() // creates random number between 0 to 0.999999
console.log(randNum) console.log(randNum)
// Let create random number between 0 to 10
// Let us create random number between 0 to 10
const num = Math.floor(Math.random () * 11) // creates random number between 0 and 10 const num = Math.floor(Math.random () * 11) // creates random number between 0 and 10
console.log(num) console.log(num)
@ -278,7 +290,9 @@ let language = 'JavaScript'
let job = 'teacher' let job = 'teacher'
let age = 250 let age = 250
let fullName = firstName + space + lastName let fullName = firstName + space + lastName
let personInfoOne = fullName + '. I am ' + age + '. I live in ' + country; // ES5 let personInfoOne = fullName + '. I am ' + age + '. I live in ' + country; // ES5
console.log(personInfoOne) console.log(personInfoOne)
``` ```
@ -339,10 +353,10 @@ To create a template string, we use two backticks. We can inject data as express
**Example: 1** **Example: 1**
```js ```js
console.log(`The sum of 2 and 3 is 5`) console.log(`The sum of 2 and 3 is 5`) // statically writing the data
let a = 2 let a = 2
let b = 3 let b = 3
console.log(`The sum of ${a} and ${b} is ${a + b}`) console.log(`The sum of ${a} and ${b} is ${a + b}`) // injecting the data dynamically
``` ```
**Example:2** **Example:2**

@ -1,7 +1,6 @@
## Table of Contents ## Table of Contents
[<< Day 2](https://github.com/Asabeneh/30DaysOfJavaScript/blob/master/02_Day/02_day_data_types.md) | [Day 4 >>](https://github.com/Asabeneh/30DaysOfJavaScript/blob/master/04_Day/04_day_conditionals.md) [<< Day 2](https://github.com/Asabeneh/30DaysOfJavaScript/blob/master/02_Day/02_day_data_types.md) | [Day 4 >>](https://github.com/Asabeneh/30DaysOfJavaScript/blob/master/04_Day/04_day_conditionals.md)
--
![Thirty Days Of JavaScript](./day_1_3.png) ![Thirty Days Of JavaScript](./day_1_3.png)
@ -52,10 +51,10 @@ A boolean data type represents one of the two values:_true_ or _false_. Boolean
**Example: Boolean Values** **Example: Boolean Values**
```js ```js
let isLightOn = true; let isLightOn = true
let isRaining = false; let isRaining = false
let isHungry = false; let isHungry = false
let isMarried = true; let isMarried = true
let truValue = 4 > 3 // true let truValue = 4 > 3 // true
let falseValue = 3 < 4 // false let falseValue = 3 < 4 // false
``` ```
@ -85,15 +84,15 @@ It is good to remember those truthy values and falsy values. In later section, w
If we declare a variable and if we do not assign a value, the value will be undefined. In addition to this, if a function is not returning the value will be undefined. If we declare a variable and if we do not assign a value, the value will be undefined. In addition to this, if a function is not returning the value will be undefined.
```js ```js
let firstName; let firstName
console.log(firstName); //not defined, because it is not assigned to a value yet console.log(firstName) //not defined, because it is not assigned to a value yet
``` ```
## Null ## Null
```js ```js
let empty = null; let empty = null
console.log(empty); // -> null , means no value console.log(empty) // -> null , means no value
``` ```
## Operators ## Operators
@ -117,36 +116,38 @@ Arithmetic operators are mathematical operators.
- Addition(+): a + b - Addition(+): a + b
- Subtraction(-): a - b - Subtraction(-): a - b
- Multiplication(*): a * b - Multiplication(_): a _ b
- Division(/): a / b - Division(/): a / b
- Modulus(%):a % b - Modulus(%):a % b
- Exponential(**):a ** b - Exponential(**):a ** b
```js ```js
let numOne = 4; let numOne = 4
let numTwo = 3; let numTwo = 3
let sum = numOne + numTwo; let sum = numOne + numTwo
let diff = numOne - numTwo; let diff = numOne - numTwo
let mult = numOne * numTwo; let mult = numOne * numTwo
let div = numOne / numTwo; let div = numOne / numTwo
let remainder = numOne % numTwo; let remainder = numOne % numTwo
let powerOf = numOne ** numTwo let powerOf = numOne ** numTwo
console.log(sum, diff, mult, div, remainder, powerOf); // ->7,1,12,1.33,1, 64
let PI = 3.14; console.log(sum, diff, mult, div, remainder, powerOf) // 7,1,12,1.33,1, 64
let radius = 100; // length in meter
let PI = 3.14
let radius = 100 // length in meter
const gravity = 9.81; // in m/s2 const gravity = 9.81 // in m/s2
let mass = 72; // in Kilogram let mass = 72 // in Kilogram
const boilingPoint = 100; // temperature in oC, boiling point of water const boilingPoint = 100 // temperature in oC, boiling point of water
const bodyTemp = 37; // body temperature in oC const bodyTemp = 37 // body temperature in oC
//Let us calculate area of a circle //Let us calculate area of a circle
const areaOfCircle = PI * radius * radius; const areaOfCircle = PI * radius * radius
console.log(areaOfCircle); // -> 314 m console.log(areaOfCircle) // 314 m
// Let us calculate weight of an object // Let us calculate weight of an object
const weight = mass * gravity; const weight = mass * gravity
console.log(weight); // -> 706.32 N(Newton) console.log(weight) // 706.32 N(Newton)
//Concatenating string with numbers using string interpolation //Concatenating string with numbers using string interpolation
/* /*
@ -156,7 +157,7 @@ console.log(weight); // -> 706.32 N(Newton)
*/ */
console.log( console.log(
`The boiling point of water is ${boilingPoint} oC.\nHuman body temperature is ${bodyTemp} oC.\nThe gravity of earth is ${gravity} m / s2.` `The boiling point of water is ${boilingPoint} oC.\nHuman body temperature is ${bodyTemp} oC.\nThe gravity of earth is ${gravity} m / s2.`
); )
``` ```
### Comparison Operators ### Comparison Operators
@ -193,7 +194,6 @@ console.log(NaN == NaN) // false, not equal
console.log(NaN === NaN) // false console.log(NaN === NaN) // false
console.log(typeof NaN) // number console.log(typeof NaN) // number
console.log('mango'.length == 'avocado'.length) // false console.log('mango'.length == 'avocado'.length) // false
console.log('mango'.length != 'avocado'.length) // true console.log('mango'.length != 'avocado'.length) // true
console.log('mango'.length < 'avocado'.length) // true console.log('mango'.length < 'avocado'.length) // true
@ -215,7 +215,6 @@ The following symbols are the common logical operators:
! negates true to false, false to true. ! negates true to false, false to true.
```js ```js
//&& ampersand operator example //&& ampersand operator example
const check = 4 > 3 && 10 > 5 // true and true -> true const check = 4 > 3 && 10 > 5 // true and true -> true
@ -450,14 +449,14 @@ console.log(now.getSeconds()) // 41, because the time is 00:56:41
This method give time in milliseconds starting from January 1, 1970. It is also know as Unix time. We can get the unix time in two ways: This method give time in milliseconds starting from January 1, 1970. It is also know as Unix time. We can get the unix time in two ways:
1. Using *getTime()* 1. Using _getTime()_
```js ```js
const now = new Date() // const now = new Date() //
console.log(now.getTime()) // 1578092201341, this is the number of seconds passed from January 1, 1970 to January 4, 2020 00:56:41 console.log(now.getTime()) // 1578092201341, this is the number of seconds passed from January 1, 1970 to January 4, 2020 00:56:41
``` ```
1. Using *Date.now()* 1. Using _Date.now()_
```js ```js
const allSeconds = Date.now() // const allSeconds = Date.now() //
@ -470,12 +469,12 @@ Let us format these values to a human readable time format.
**Example:** **Example:**
```js ```js
const now = new Date (); const now = new Date()
const year = now.getFullYear(); // return year const year = now.getFullYear() // return year
const month = now.getMonth() + 1; // return month(0 - 11) const month = now.getMonth() + 1 // return month(0 - 11)
const date = now.getDate(); // return date (1 - 31) const date = now.getDate() // return date (1 - 31)
const hours = now.getHours(); // return number (0 - 23) const hours = now.getHours() // return number (0 - 23)
const minutes = now.getMinutes();// return number (0 -59) const minutes = now.getMinutes() // return number (0 -59)
console.log(`${date}/${month}/${year} ${hours}:${minutes}`) // 4/1/2020 0:56 console.log(`${date}/${month}/${year} ${hours}:${minutes}`) // 4/1/2020 0:56
``` ```
@ -509,13 +508,13 @@ console.log(`${date}/${month}/${year} ${hours}:${minutes}`) // 4/1/2020 0:56
The perimeter of the triangle is 12 The perimeter of the triangle is 12
``` ```
2. Get length and width using prompt and calculate an area of rectangle (area = length x width and the perimeter of rectangle (perimeter = 2 x (length + width)) 1. Get length and width using prompt and calculate an area of rectangle (area = length x width and the perimeter of rectangle (perimeter = 2 x (length + width))
3. Get radius using prompt and calculate the area of a circle (area = pi x r x r) and circumference of a circle(c = 2 x pi x r) where pi = 3.14. 1. Get radius using prompt and calculate the area of a circle (area = pi x r x r) and circumference of a circle(c = 2 x pi x r) where pi = 3.14.
4. Calculate the slope, x-intercept and y-intercept of y = 2x -2 1. Calculate the slope, x-intercept and y-intercept of y = 2x -2
5. Slope is (m = y2-y1/x2-x1). Find the slope between point (2, 2) and point(6,10) 1. Slope is (m = y2-y1/x2-x1). Find the slope between point (2, 2) and point(6,10)
6. Compare the slope of above two questions. 1. Compare the slope of above two questions.
7. Calculate the value of y (y = x^2 + 6x + 9). Try to use different x values and figure out at what x value y is 0. 1. Calculate the value of y (y = x^2 + 6x + 9). Try to use different x values and figure out at what x value y is 0.
8. Writ a script that prompt a user to enters hours and rate per hour. Calculate pay of the person? 1. Writ a script that prompt a user to enters hours and rate per hour. Calculate pay of the person?
```sh ```sh
Enter hours: 40 Enter hours: 40
@ -523,7 +522,7 @@ console.log(`${date}/${month}/${year} ${hours}:${minutes}`) // 4/1/2020 0:56
Your weekly earning is 1120 Your weekly earning is 1120
``` ```
9. Write a script that prompt the user to enter number of years. Calculate the number of seconds a person can live. Assume some one lives just hundred years 1. Write a script that prompt the user to enter number of years. Calculate the number of seconds a person can live. Assume some one lives just hundred years
```sh ```sh
Enter number of yours you live: 100 Enter number of yours you live: 100

Loading…
Cancel
Save