fix images path and format

pull/999/head
Zanderlan 2 years ago
parent 17473fcafb
commit c1f97f3e1b

File diff suppressed because it is too large Load Diff

@ -61,12 +61,12 @@ 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 = 4 < 3 // false let falseValue = 4 < 3; // false
``` ```
We agreed that boolean values are either true or false. We agreed that boolean values are either true or false.
@ -94,15 +94,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, it 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, it 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
@ -112,13 +112,13 @@ console.log(empty) // -> null , means no value
An equal sign in JavaScript is an assignment operator. It uses to assign a variable. An equal sign in JavaScript is an assignment operator. It uses to assign a variable.
```js ```js
let firstName = 'Asabeneh' let firstName = 'Asabeneh';
let country = 'Finland' let country = 'Finland';
``` ```
Assignment Operators Assignment Operators
![Assignment operators](../images/assignment_operators.png) ![Assignment operators](../../images/assignment_operators.png)
### Arithmetic Operators ### Arithmetic Operators
@ -126,44 +126,41 @@ 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
console.log(sum, diff, mult, div, remainder, powerOf); // 7,1,12,1.33,1, 64
``` ```
```js ```js
const PI = 3.14 const PI = 3.14;
let radius = 100 // length in meter let radius = 100; // length in meter
//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
const gravity = 9.81 // in m/s2 const gravity = 9.81; // in m/s2
let mass = 72 // in Kilogram let mass = 72; // in Kilogram
// 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)
const boilingPoint = 100 // temperature in oC, boiling point of water
const bodyTemp = 37 // body temperature in oC
const boilingPoint = 100; // temperature in oC, boiling point of water
const bodyTemp = 37; // body temperature in oC
// Concatenating string with numbers using string interpolation // Concatenating string with numbers using string interpolation
/* /*
@ -173,49 +170,49 @@ const bodyTemp = 37 // body temperature in oC
*/ */
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
In programming we compare values, we use comparison operators to compare two values. We check if a value is greater or less or equal to other value. In programming we compare values, we use comparison operators to compare two values. We check if a value is greater or less or equal to other value.
![Comparison Operators](../images/comparison_operators.png) ![Comparison Operators](../../images/comparison_operators.png)
**Example: Comparison Operators** **Example: Comparison Operators**
```js ```js
console.log(3 > 2) // true, because 3 is greater than 2 console.log(3 > 2); // true, because 3 is greater than 2
console.log(3 >= 2) // true, because 3 is greater than 2 console.log(3 >= 2); // true, because 3 is greater than 2
console.log(3 < 2) // false, because 3 is greater than 2 console.log(3 < 2); // false, because 3 is greater than 2
console.log(2 < 3) // true, because 2 is less than 3 console.log(2 < 3); // true, because 2 is less than 3
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); // false, because 3 is not equal to 2
console.log(3 != 2) // true, because 3 is not equal to 2 console.log(3 != 2); // true, because 3 is not equal to 2
console.log(3 == '3') // true, compare only value console.log(3 == '3'); // true, compare only value
console.log(3 === '3') // false, compare both value and data type 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 only value
console.log(3 !== 3) // false, compare both value and data type console.log(3 !== 3); // false, compare both value and data type
console.log(0 == false) // true, equivalent console.log(0 == false); // true, equivalent
console.log(0 === false) // false, not exactly the same console.log(0 === false); // false, not exactly the same
console.log(0 == '') // true, equivalent console.log(0 == ''); // true, equivalent
console.log(0 == ' ') // true, equivalent console.log(0 == ' '); // true, equivalent
console.log(0 === '') // false, not exactly the same console.log(0 === ''); // false, not exactly the same
console.log(1 == true) // true, equivalent console.log(1 == true); // true, equivalent
console.log(1 === true) // false, not exactly the same console.log(1 === true); // false, not exactly the same
console.log(undefined == null) // true console.log(undefined == null); // true
console.log(undefined === null) // false console.log(undefined === null); // false
console.log(NaN == NaN) // false, not equal 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
console.log('milk'.length == 'meat'.length) // true console.log('milk'.length == 'meat'.length); // true
console.log('milk'.length != 'meat'.length) // false console.log('milk'.length != 'meat'.length); // false
console.log('tomato'.length == 'potato'.length) // true console.log('tomato'.length == 'potato'.length); // true
console.log('python'.length > 'dragon'.length) // false console.log('python'.length > 'dragon'.length); // false
``` ```
Try to understand the above comparisons with some logic. Remembering without any logic might be difficult. Try to understand the above comparisons with some logic. Remembering without any logic might be difficult.
@ -234,23 +231,23 @@ The ! operator negates true to false and false to true.
```js ```js
// && ampersand operator example // && ampersand operator example
const check = 4 > 3 && 10 > 5 // true && true -> true const check = 4 > 3 && 10 > 5; // true && true -> true
const check = 4 > 3 && 10 < 5 // true && false -> false const check = 4 > 3 && 10 < 5; // true && false -> false
const check = 4 < 3 && 10 < 5 // false && false -> false const check = 4 < 3 && 10 < 5; // false && false -> false
// || pipe or operator, example // || pipe or operator, example
const check = 4 > 3 || 10 > 5 // true || true -> true const check = 4 > 3 || 10 > 5; // true || true -> true
const check = 4 > 3 || 10 < 5 // true || false -> true const check = 4 > 3 || 10 < 5; // true || false -> true
const check = 4 < 3 || 10 < 5 // false || false -> false const check = 4 < 3 || 10 < 5; // false || false -> false
//! Negation examples //! Negation examples
let check = 4 > 3 // true let check = 4 > 3; // true
let check = !(4 > 3) // false let check = !(4 > 3); // false
let isLightOn = true let isLightOn = true;
let isLightOff = !isLightOn // false let isLightOff = !isLightOn; // false
let isMarried = !false // true let isMarried = !false; // true
``` ```
### Increment Operator ### Increment Operator
@ -260,17 +257,17 @@ In JavaScript we use the increment operator to increase a value stored in a vari
1. Pre-increment 1. Pre-increment
```js ```js
let count = 0 let count = 0;
console.log(++count) // 1 console.log(++count); // 1
console.log(count) // 1 console.log(count); // 1
``` ```
1. Post-increment 1. Post-increment
```js ```js
let count = 0 let count = 0;
console.log(count++) // 0 console.log(count++); // 0
console.log(count) // 1 console.log(count); // 1
``` ```
We use most of the time post-increment. At least you should remember how to use post-increment operator. We use most of the time post-increment. At least you should remember how to use post-increment operator.
@ -282,17 +279,17 @@ In JavaScript we use the decrement operator to decrease a value stored in a vari
1. Pre-decrement 1. Pre-decrement
```js ```js
let count = 0 let count = 0;
console.log(--count) // -1 console.log(--count); // -1
console.log(count) // -1 console.log(count); // -1
``` ```
2. Post-decrement 2. Post-decrement
```js ```js
let count = 0 let count = 0;
console.log(count--) // 0 console.log(count--); // 0
console.log(count) // -1 console.log(count); // -1
``` ```
### Ternary Operators ### Ternary Operators
@ -301,15 +298,15 @@ Ternary operator allows to write a condition.
Another way to write conditionals is using ternary operators. Look at the following examples: Another way to write conditionals is using ternary operators. Look at the following examples:
```js ```js
let isRaining = true let isRaining = true;
isRaining isRaining
? console.log('You need a rain coat.') ? console.log('You need a rain coat.')
: console.log('No need for a rain coat.') : console.log('No need for a rain coat.');
isRaining = false isRaining = false;
isRaining isRaining
? console.log('You need a rain coat.') ? console.log('You need a rain coat.')
: console.log('No need for a rain coat.') : console.log('No need for a rain coat.');
``` ```
```sh ```sh
@ -318,15 +315,15 @@ No need for a rain coat.
``` ```
```js ```js
let number = 5 let number = 5;
number > 0 number > 0
? console.log(`${number} is a positive number`) ? console.log(`${number} is a positive number`)
: console.log(`${number} is a negative number`) : console.log(`${number} is a negative number`);
number = -5 number = -5;
number > 0 number > 0
? console.log(`${number} is a positive number`) ? console.log(`${number} is a positive number`)
: console.log(`${number} is a negative number`) : console.log(`${number} is a negative number`);
``` ```
```sh ```sh
@ -345,11 +342,11 @@ I would like to recommend you to read about operator precedence from this [link]
As you have seen at very beginning alert() method displays an alert box with a specified message and an OK button. It is a builtin method and it takes on argument. As you have seen at very beginning alert() method displays an alert box with a specified message and an OK button. It is a builtin method and it takes on argument.
```js ```js
alert(message) alert(message);
``` ```
```js ```js
alert('Welcome to 30DaysOfJavaScript') alert('Welcome to 30DaysOfJavaScript');
``` ```
Do not use too much alert because it is destructing and annoying, use it just to test. Do not use too much alert because it is destructing and annoying, use it just to test.
@ -359,12 +356,12 @@ Do not use too much alert because it is destructing and annoying, use it just to
The window prompt methods display a prompt box with an input on your browser to take input values and the input data can be stored in a variable. The prompt() method takes two arguments. The second argument is optional. The window prompt methods display a prompt box with an input on your browser to take input values and the input data can be stored in a variable. The prompt() method takes two arguments. The second argument is optional.
```js ```js
prompt('required text', 'optional text') prompt('required text', 'optional text');
``` ```
```js ```js
let number = prompt('Enter number', 'number goes here') let number = prompt('Enter number', 'number goes here');
console.log(number) console.log(number);
``` ```
### Window confirm() method ### Window confirm() method
@ -374,8 +371,8 @@ A confirm box is often used to ask permission from a user to execute something.
Clicking the OK yields true value, whereas clicking the Cancel button yields false value. Clicking the OK yields true value, whereas clicking the Cancel button yields false value.
```js ```js
const agree = confirm('Are you sure you like to delete? ') const agree = confirm('Are you sure you like to delete? ');
console.log(agree) // result will be true or false based on what you click on the dialog box console.log(agree); // result will be true or false based on what you click on the dialog box
``` ```
These are not all the window methods we will have a separate section to go deep into window methods. These are not all the window methods we will have a separate section to go deep into window methods.
@ -385,15 +382,15 @@ These are not all the window methods we will have a separate section to go deep
Time is an important thing. We like to know the time a certain activity or event. In JavaScript current time and date is created using JavaScript Date Object. The object we create using Date object provides many methods to work with date and time.The methods we use to get date and time information from a date object values are started with a word _get_ because it provide the information. Time is an important thing. We like to know the time a certain activity or event. In JavaScript current time and date is created using JavaScript Date Object. The object we create using Date object provides many methods to work with date and time.The methods we use to get date and time information from a date object values are started with a word _get_ because it provide the information.
_getFullYear(), getMonth(), getDate(), getDay(), getHours(), getMinutes, getSeconds(), getMilliseconds(), getTime(), getDay()_ _getFullYear(), getMonth(), getDate(), getDay(), getHours(), getMinutes, getSeconds(), getMilliseconds(), getTime(), getDay()_
![Date time Object](../images/date_time_object.png) ![Date time Object](../../images/date_time_object.png)
### Creating a time object ### Creating a time object
Once we create time object. The time object will provide information about time. Let us create a time object Once we create time object. The time object will provide information about time. Let us create a time object
```js ```js
const now = new Date() const now = new Date();
console.log(now) // Sat Jan 04 2020 00:56:41 GMT+0200 (Eastern European Standard Time) console.log(now); // Sat Jan 04 2020 00:56:41 GMT+0200 (Eastern European Standard Time)
``` ```
We have created a time object and we can access any date time information from the object using the get methods we have mentioned on the table. We have created a time object and we can access any date time information from the object using the get methods we have mentioned on the table.
@ -403,8 +400,8 @@ We have created a time object and we can access any date time information from t
Let's extract or get the full year from a time object. Let's extract or get the full year from a time object.
```js ```js
const now = new Date() const now = new Date();
console.log(now.getFullYear()) // 2020 console.log(now.getFullYear()); // 2020
``` ```
### Getting month ### Getting month
@ -412,8 +409,8 @@ console.log(now.getFullYear()) // 2020
Let's extract or get the month from a time object. Let's extract or get the month from a time object.
```js ```js
const now = new Date() const now = new Date();
console.log(now.getMonth()) // 0, because the month is January, month(0-11) console.log(now.getMonth()); // 0, because the month is January, month(0-11)
``` ```
### Getting date ### Getting date
@ -421,8 +418,8 @@ console.log(now.getMonth()) // 0, because the month is January, month(0-11)
Let's extract or get the date of the month from a time object. Let's extract or get the date of the month from a time object.
```js ```js
const now = new Date() const now = new Date();
console.log(now.getDate()) // 4, because the day of the month is 4th, day(1-31) console.log(now.getDate()); // 4, because the day of the month is 4th, day(1-31)
``` ```
### Getting day ### Getting day
@ -430,8 +427,8 @@ console.log(now.getDate()) // 4, because the day of the month is 4th, day(1-31)
Let's extract or get the day of the week from a time object. Let's extract or get the day of the week from a time object.
```js ```js
const now = new Date() const now = new Date();
console.log(now.getDay()) // 6, because the day is Saturday which is the 7th day console.log(now.getDay()); // 6, because the day is Saturday which is the 7th day
// Sunday is 0, Monday is 1 and Saturday is 6 // Sunday is 0, Monday is 1 and Saturday is 6
// Getting the weekday as a number (0-6) // Getting the weekday as a number (0-6)
``` ```
@ -441,8 +438,8 @@ console.log(now.getDay()) // 6, because the day is Saturday which is the 7th day
Let's extract or get the hours from a time object. Let's extract or get the hours from a time object.
```js ```js
const now = new Date() const now = new Date();
console.log(now.getHours()) // 0, because the time is 00:56:41 console.log(now.getHours()); // 0, because the time is 00:56:41
``` ```
### Getting minutes ### Getting minutes
@ -450,8 +447,8 @@ console.log(now.getHours()) // 0, because the time is 00:56:41
Let's extract or get the minutes from a time object. Let's extract or get the minutes from a time object.
```js ```js
const now = new Date() const now = new Date();
console.log(now.getMinutes()) // 56, because the time is 00:56:41 console.log(now.getMinutes()); // 56, because the time is 00:56:41
``` ```
### Getting seconds ### Getting seconds
@ -459,8 +456,8 @@ console.log(now.getMinutes()) // 56, because the time is 00:56:41
Let's extract or get the seconds from a time object. Let's extract or get the seconds from a time object.
```js ```js
const now = new Date() const now = new Date();
console.log(now.getSeconds()) // 41, because the time is 00:56:41 console.log(now.getSeconds()); // 41, because the time is 00:56:41
``` ```
### Getting time ### Getting time
@ -470,35 +467,35 @@ This method give time in milliseconds starting from January 1, 1970. It is also
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(); //
console.log(allSeconds) // 1578092201341, this is the number of seconds passed from January 1, 1970 to January 4, 2020 00:56:41 console.log(allSeconds); // 1578092201341, this is the number of seconds passed from January 1, 1970 to January 4, 2020 00:56:41
const timeInSeconds = new Date().getTime() const timeInSeconds = new Date().getTime();
console.log(allSeconds == timeInSeconds) // true console.log(allSeconds == timeInSeconds); // true
``` ```
Let us format these values to a human readable time format. 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
``` ```
🌕 You have boundless energy. You have just completed day 3 challenges and you are three steps a head in to your way to greatness. Now do some exercises for your brain and for your muscle. 🌕 You have boundless energy. You have just completed day 3 challenges and you are three steps a head in to your way to greatness. Now do some exercises for your brain and for your muscle.
## 💻 Day 3: Exercises ## 💻 Day 3: Exercises
@ -508,10 +505,12 @@ console.log(`${date}/${month}/${year} ${hours}:${minutes}`) // 4/1/2020 0:56
2. Check if type of '10' is equal to 10 2. Check if type of '10' is equal to 10
3. Check if parseInt('9.8') is equal to 10 3. Check if parseInt('9.8') is equal to 10
4. Boolean value is either true or false. 4. Boolean value is either true or false.
1. Write three JavaScript statement which provide truthy value. 1. Write three JavaScript statement which provide truthy value.
2. Write three JavaScript statement which provide falsy value. 2. Write three JavaScript statement which provide falsy value.
5. Figure out the result of the following comparison expression first without using console.log(). After you decide the result confirm it using console.log() 5. 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
2. 4 >= 3 2. 4 >= 3
3. 4 < 3 3. 4 < 3
@ -526,6 +525,7 @@ console.log(`${date}/${month}/${year} ${hours}:${minutes}`) // 4/1/2020 0:56
12. Find the length of python and jargon and make a falsy comparison statement. 12. Find the length of python and jargon and make a falsy comparison statement.
6. Figure out the result of the following expressions first without using console.log(). After you decide the result confirm it by using console.log() 6. 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
2. 4 > 3 && 10 > 12 2. 4 > 3 && 10 > 12
3. 4 > 3 || 10 < 12 3. 4 > 3 || 10 < 12
@ -583,20 +583,20 @@ console.log(`${date}/${month}/${year} ${hours}:${minutes}`) // 4/1/2020 0:56
1. If the length of your name is greater than 7 say, your name is long else say your name is short. 1. If the length of your name is greater than 7 say, your name is long else say your name is short.
1. Compare your first name length and your family name length and you should get this output. 1. Compare your first name length and your family name length and you should get this output.
```js ```js
let firstName = 'Asabeneh' let firstName = 'Asabeneh';
let lastName = 'Yetayeh' let lastName = 'Yetayeh';
``` ```
```sh ```sh
Your first name, Asabeneh is longer than your family name, Yetayeh Your first name, Asabeneh is longer than your family name, Yetayeh
``` ```
1. Declare two variables _myAge_ and _yourAge_ and assign them initial values and myAge and yourAge. 1. Declare two variables _myAge_ and _yourAge_ and assign them initial values and myAge and yourAge.
```js ```js
let myAge = 250 let myAge = 250;
let yourAge = 25 let yourAge = 25;
``` ```
```sh ```sh

@ -16,7 +16,7 @@
[<< Dia 4](../Dia_04_Condicionais.md) | [Dia 6 >>](../Dia_06_Loops/Dia_06_Loops.md) [<< Dia 4](../Dia_04_Condicionais.md) | [Dia 6 >>](../Dia_06_Loops/Dia_06_Loops.md)
![Dia 5](../../images/banners/day_1_5.png) ![Dia 5](/images/banners/day_1_5.png)
- [📔 Dia 5](#-dia-5) - [📔 Dia 5](#-dia-5)
- [Arrays](#arrays) - [Arrays](#arrays)
@ -169,7 +169,7 @@ console.log(words);
Acessamos cada elemento em um array usando seu índice. O índice de um array começa do 0. A imagem abaixo mostra claramente o índice de cada elemento no array. Acessamos cada elemento em um array usando seu índice. O índice de um array começa do 0. A imagem abaixo mostra claramente o índice de cada elemento no array.
![arr index](../../images/array_index.png) ![arr index](/images/array_index.png)
```js ```js
const frutas = ['banana', 'laranja', 'manga', 'limão']; const frutas = ['banana', 'laranja', 'manga', 'limão'];

Loading…
Cancel
Save