commit
8c7833483d
Before Width: | Height: | Size: 75 KiB |
@ -1,34 +0,0 @@
|
||||
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))
|
@ -1,30 +0,0 @@
|
||||
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
|
@ -1,9 +0,0 @@
|
||||
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)
|
@ -1,14 +0,0 @@
|
||||
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
|
@ -1,19 +0,0 @@
|
||||
// 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)
|
@ -1,7 +0,0 @@
|
||||
let space = ' ' // an empty space string
|
||||
let firstName = 'Asabeneh'
|
||||
let lastName = 'Yetayeh'
|
||||
let country = 'Finland'
|
||||
let city = 'Helsinki'
|
||||
let language = 'JavaScript'
|
||||
let job = 'teacher'
|
@ -1,12 +0,0 @@
|
||||
// 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
|
@ -1,6 +0,0 @@
|
||||
// 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
|
@ -1,7 +0,0 @@
|
||||
// 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
|
@ -1,6 +0,0 @@
|
||||
// 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
|
@ -1,11 +0,0 @@
|
||||
// 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
|
@ -1,14 +0,0 @@
|
||||
// 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
|
@ -1,11 +0,0 @@
|
||||
// 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
|
@ -1,6 +0,0 @@
|
||||
// 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
|
@ -1,6 +0,0 @@
|
||||
// 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
|
@ -1,22 +0,0 @@
|
||||
// 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 Python. Now, in 2020 I super exited to start this challenge'
|
||||
let regEx = /\d/g // 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(txt.match(regEx)) // ["2", "0", "1", "9", "3", "0", "2", "0", "2", "0"]
|
||||
console.log(txt.match(/\d+/g)) // ["2019", "30", "2020"]
|
@ -1,4 +0,0 @@
|
||||
// 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
|
@ -1,7 +0,0 @@
|
||||
// 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
|
@ -1,4 +0,0 @@
|
||||
// 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
|
@ -1,10 +0,0 @@
|
||||
// split(): The split method splits a string at a specified place.
|
||||
let string = '30 Days Of JavaScript'
|
||||
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"]
|
@ -1,11 +0,0 @@
|
||||
// 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
|
@ -1,5 +0,0 @@
|
||||
//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
|
@ -1,9 +0,0 @@
|
||||
// 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
|
@ -1,7 +0,0 @@
|
||||
// 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
|
@ -1,8 +0,0 @@
|
||||
// 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
|
@ -1,7 +0,0 @@
|
||||
//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()) //
|
@ -0,0 +1,17 @@
|
||||
<!DOCTYPE html>
|
||||
<html lang="en">
|
||||
|
||||
<head>
|
||||
<title>30DaysOfJavaScript: 03 Day</title>
|
||||
</head>
|
||||
|
||||
<body>
|
||||
<h1>30DaysOfJavaScript:03 Day</h1>
|
||||
<h2>Booleans, undefined, null, date object</h2>
|
||||
|
||||
<!-- import your scripts here -->
|
||||
<script src="./scripts/main.js"></script>
|
||||
|
||||
</body>
|
||||
|
||||
</html>
|
@ -0,0 +1 @@
|
||||
// this is your main.js script
|
@ -0,0 +1,633 @@
|
||||
<div align="center">
|
||||
<h1> 30 Dias De JavaScript: Boleanos, Operadores e Data</h1>
|
||||
<a class="header-badge" target="_blank" href="https://www.linkedin.com/in/asabeneh/">
|
||||
<img src="https://img.shields.io/badge/style--5eba00.svg?label=LinkedIn&logo=linkedin&style=social">
|
||||
</a>
|
||||
<a class="header-badge" target="_blank" href="https://twitter.com/Asabeneh">
|
||||
<img alt="Twitter Follow" src="https://img.shields.io/twitter/follow/asabeneh?style=social">
|
||||
</a>
|
||||
|
||||
<sub>Autor;
|
||||
<a href="https://www.linkedin.com/in/asabeneh/" target="_blank">Asabeneh Yetayeh</a><br>
|
||||
<small> Janeiro, 2020</small>
|
||||
</sub>
|
||||
</div>
|
||||
|
||||
[<< Day 2](../Dia_02_Tipos_Dados/dia_02_tipos_dados.md) | [Day 4 >>](../04_Day_Conditionals/04_day_conditionals.md)
|
||||
|
||||

|
||||
|
||||
- [📔 Day 3](#-day-3)
|
||||
- [Booleans](#booleans)
|
||||
- [Truthy values](#truthy-values)
|
||||
- [Falsy values](#falsy-values)
|
||||
- [Undefined](#undefined)
|
||||
- [Null](#null)
|
||||
- [Operators](#operators)
|
||||
- [Assignment operators](#assignment-operators)
|
||||
- [Arithmetic Operators](#arithmetic-operators)
|
||||
- [Comparison Operators](#comparison-operators)
|
||||
- [Logical Operators](#logical-operators)
|
||||
- [Increment Operator](#increment-operator)
|
||||
- [Decrement Operator](#decrement-operator)
|
||||
- [Ternary Operators](#ternary-operators)
|
||||
- [Operator Precedence](#operator-precedence)
|
||||
- [Window Methods](#window-methods)
|
||||
- [Window alert() method](#window-alert-method)
|
||||
- [Window prompt() method](#window-prompt-method)
|
||||
- [Window confirm() method](#window-confirm-method)
|
||||
- [Date Object](#date-object)
|
||||
- [Creating a time object](#creating-a-time-object)
|
||||
- [Getting full year](#getting-full-year)
|
||||
- [Getting month](#getting-month)
|
||||
- [Getting date](#getting-date)
|
||||
- [Getting day](#getting-day)
|
||||
- [Getting hours](#getting-hours)
|
||||
- [Getting minutes](#getting-minutes)
|
||||
- [Getting seconds](#getting-seconds)
|
||||
- [Getting time](#getting-time)
|
||||
- [💻 Day 3: Exercises](#-day-3-exercises)
|
||||
- [Exercises: Level 1](#exercises-level-1)
|
||||
- [Exercises: Level 2](#exercises-level-2)
|
||||
- [Exercises: Level 3](#exercises-level-3)
|
||||
|
||||
# 📔 Day 3
|
||||
|
||||
## Booleans
|
||||
|
||||
A boolean data type represents one of the two values:_true_ or _false_. Boolean value is either true or false. The use of these data types will be clear when you start the comparison operator. Any comparisons return a boolean value which is either true or false.
|
||||
|
||||
**Example: Boolean Values**
|
||||
|
||||
```js
|
||||
let isLightOn = true
|
||||
let isRaining = false
|
||||
let isHungry = false
|
||||
let isMarried = true
|
||||
let truValue = 4 > 3 // true
|
||||
let falseValue = 4 < 3 // false
|
||||
```
|
||||
|
||||
We agreed that boolean values are either true or false.
|
||||
|
||||
### Truthy values
|
||||
|
||||
- All numbers(positive and negative) are truthy except zero
|
||||
- All strings are truthy except an empty string ('')
|
||||
- The boolean true
|
||||
|
||||
### Falsy values
|
||||
|
||||
- 0
|
||||
- 0n
|
||||
- null
|
||||
- undefined
|
||||
- NaN
|
||||
- the boolean false
|
||||
- '', "", ``, empty string
|
||||
|
||||
It is good to remember those truthy values and falsy values. In later section, we will use them with conditions to make decisions.
|
||||
|
||||
## 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
|
||||
let firstName
|
||||
console.log(firstName) //not defined, because it is not assigned to a value yet
|
||||
```
|
||||
|
||||
## Null
|
||||
|
||||
```js
|
||||
let empty = null
|
||||
console.log(empty) // -> null , means no value
|
||||
```
|
||||
|
||||
## Operators
|
||||
|
||||
### Assignment operators
|
||||
|
||||
An equal sign in JavaScript is an assignment operator. It uses to assign a variable.
|
||||
|
||||
```js
|
||||
let firstName = 'Asabeneh'
|
||||
let country = 'Finland'
|
||||
```
|
||||
|
||||
Assignment Operators
|
||||
|
||||

|
||||
|
||||
### Arithmetic Operators
|
||||
|
||||
Arithmetic operators are mathematical operators.
|
||||
|
||||
- Addition(+): a + b
|
||||
- Subtraction(-): a - b
|
||||
- Multiplication(*): a * b
|
||||
- Division(/): a / b
|
||||
- Modulus(%): a % b
|
||||
- Exponential(**): a ** b
|
||||
|
||||
```js
|
||||
let numOne = 4
|
||||
let numTwo = 3
|
||||
let sum = numOne + numTwo
|
||||
let diff = numOne - numTwo
|
||||
let mult = numOne * numTwo
|
||||
let div = numOne / numTwo
|
||||
let remainder = numOne % numTwo
|
||||
let powerOf = numOne ** numTwo
|
||||
|
||||
console.log(sum, diff, mult, div, remainder, powerOf) // 7,1,12,1.33,1, 64
|
||||
|
||||
```
|
||||
|
||||
```js
|
||||
const PI = 3.14
|
||||
let radius = 100 // length in meter
|
||||
|
||||
//Let us calculate area of a circle
|
||||
const areaOfCircle = PI * radius * radius
|
||||
console.log(areaOfCircle) // 314 m
|
||||
|
||||
|
||||
const gravity = 9.81 // in m/s2
|
||||
let mass = 72 // in Kilogram
|
||||
|
||||
// Let us calculate weight of an object
|
||||
const weight = mass * gravity
|
||||
console.log(weight) // 706.32 N(Newton)
|
||||
|
||||
const boilingPoint = 100 // temperature in oC, boiling point of water
|
||||
const bodyTemp = 37 // body temperature in oC
|
||||
|
||||
|
||||
// Concatenating string with numbers using string interpolation
|
||||
/*
|
||||
The boiling point of water is 100 oC.
|
||||
Human body temperature is 37 oC.
|
||||
The gravity of earth is 9.81 m/s2.
|
||||
*/
|
||||
console.log(
|
||||
`The boiling point of water is ${boilingPoint} oC.\nHuman body temperature is ${bodyTemp} oC.\nThe gravity of earth is ${gravity} m / s2.`
|
||||
)
|
||||
```
|
||||
|
||||
### 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.
|
||||
|
||||

|
||||
**Example: Comparison Operators**
|
||||
|
||||
```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) // 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(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 == '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) // false, compare only value
|
||||
console.log(3 !== 3) // false, compare both value and data type
|
||||
console.log(0 == false) // true, equivalent
|
||||
console.log(0 === false) // false, not exactly the same
|
||||
console.log(0 == '') // true, equivalent
|
||||
console.log(0 == ' ') // true, equivalent
|
||||
console.log(0 === '') // false, not exactly the same
|
||||
console.log(1 == true) // true, equivalent
|
||||
console.log(1 === true) // false, not exactly the same
|
||||
console.log(undefined == null) // true
|
||||
console.log(undefined === null) // false
|
||||
console.log(NaN == NaN) // false, not equal
|
||||
console.log(NaN === NaN) // false
|
||||
console.log(typeof NaN) // number
|
||||
|
||||
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) // true
|
||||
console.log('milk'.length != 'meat'.length) // false
|
||||
console.log('tomato'.length == 'potato'.length) // true
|
||||
console.log('python'.length > 'dragon'.length) // false
|
||||
```
|
||||
|
||||
Try to understand the above comparisons with some logic. Remembering without any logic might be difficult.
|
||||
JavaScript is somehow a wired kind of programming language. JavaScript code run and give you a result but unless you are good at it may not be the desired result.
|
||||
|
||||
As rule of thumb, if a value is not true with == it will not be equal with ===. Using === is safer than using ==. The following [link](https://dorey.github.io/JavaScript-Equality-Table/) has an exhaustive list of comparison of data types.
|
||||
|
||||
### Logical Operators
|
||||
|
||||
The following symbols are the common logical operators:
|
||||
&&(ampersand) , ||(pipe) and !(negation).
|
||||
The && operator gets true only if the two operands are true.
|
||||
The || operator gets true either of the operand is true.
|
||||
The ! operator negates true to false and false to true.
|
||||
|
||||
```js
|
||||
// && ampersand operator example
|
||||
|
||||
const check = 4 > 3 && 10 > 5 // true && true -> true
|
||||
const check = 4 > 3 && 10 < 5 // true && false -> false
|
||||
const check = 4 < 3 && 10 < 5 // false && false -> false
|
||||
|
||||
// || pipe or operator, example
|
||||
|
||||
const check = 4 > 3 || 10 > 5 // true || true -> true
|
||||
const check = 4 > 3 || 10 < 5 // true || false -> true
|
||||
const check = 4 < 3 || 10 < 5 // false || false -> false
|
||||
|
||||
//! Negation examples
|
||||
|
||||
let check = 4 > 3 // true
|
||||
let check = !(4 > 3) // false
|
||||
let isLightOn = true
|
||||
let isLightOff = !isLightOn // false
|
||||
let isMarried = !false // true
|
||||
```
|
||||
|
||||
### Increment Operator
|
||||
|
||||
In JavaScript we use the increment operator to increase a value stored in a variable. The increment could be pre or post increment. Let us see each of them:
|
||||
|
||||
1. Pre-increment
|
||||
|
||||
```js
|
||||
let count = 0
|
||||
console.log(++count) // 1
|
||||
console.log(count) // 1
|
||||
```
|
||||
|
||||
1. Post-increment
|
||||
|
||||
```js
|
||||
let count = 0
|
||||
console.log(count++) // 0
|
||||
console.log(count) // 1
|
||||
```
|
||||
|
||||
We use most of the time post-increment. At least you should remember how to use post-increment operator.
|
||||
|
||||
### Decrement Operator
|
||||
|
||||
In JavaScript we use the decrement operator to decrease a value stored in a variable. The decrement could be pre or post decrement. Let us see each of them:
|
||||
|
||||
1. Pre-decrement
|
||||
|
||||
```js
|
||||
let count = 0
|
||||
console.log(--count) // -1
|
||||
console.log(count) // -1
|
||||
```
|
||||
|
||||
2. Post-decrement
|
||||
|
||||
```js
|
||||
let count = 0
|
||||
console.log(count--) // 0
|
||||
console.log(count) // -1
|
||||
```
|
||||
|
||||
### Ternary Operators
|
||||
|
||||
Ternary operator allows to write a condition.
|
||||
Another way to write conditionals is using ternary operators. Look at the following examples:
|
||||
|
||||
```js
|
||||
let isRaining = true
|
||||
isRaining
|
||||
? console.log('You need a rain coat.')
|
||||
: console.log('No need for a rain coat.')
|
||||
isRaining = false
|
||||
|
||||
isRaining
|
||||
? console.log('You need a rain coat.')
|
||||
: console.log('No need for a rain coat.')
|
||||
```
|
||||
|
||||
```sh
|
||||
You need a rain coat.
|
||||
No need for a rain coat.
|
||||
```
|
||||
|
||||
```js
|
||||
let number = 5
|
||||
number > 0
|
||||
? console.log(`${number} is a positive number`)
|
||||
: console.log(`${number} is a negative number`)
|
||||
number = -5
|
||||
|
||||
number > 0
|
||||
? console.log(`${number} is a positive number`)
|
||||
: console.log(`${number} is a negative number`)
|
||||
```
|
||||
|
||||
```sh
|
||||
5 is a positive number
|
||||
-5 is a negative number
|
||||
```
|
||||
|
||||
### Operator Precedence
|
||||
|
||||
I would like to recommend you to read about operator precedence from this [link](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Operators/Operator_Precedence)
|
||||
|
||||
## Window Methods
|
||||
|
||||
### Window alert() method
|
||||
|
||||
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
|
||||
alert(message)
|
||||
```
|
||||
|
||||
```js
|
||||
alert('Welcome to 30DaysOfJavaScript')
|
||||
```
|
||||
|
||||
Do not use too much alert because it is destructing and annoying, use it just to test.
|
||||
|
||||
### Window prompt() method
|
||||
|
||||
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
|
||||
prompt('required text', 'optional text')
|
||||
```
|
||||
|
||||
```js
|
||||
let number = prompt('Enter number', 'number goes here')
|
||||
console.log(number)
|
||||
```
|
||||
|
||||
### Window confirm() method
|
||||
|
||||
The confirm() method displays a dialog box with a specified message, along with an OK and a Cancel button.
|
||||
A confirm box is often used to ask permission from a user to execute something. Window confirm() takes a string as an argument.
|
||||
Clicking the OK yields true value, whereas clicking the Cancel button yields false value.
|
||||
|
||||
```js
|
||||
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
|
||||
```
|
||||
|
||||
These are not all the window methods we will have a separate section to go deep into window methods.
|
||||
|
||||
## Date Object
|
||||
|
||||
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()_
|
||||
|
||||

|
||||
|
||||
### Creating a time object
|
||||
|
||||
Once we create time object. The time object will provide information about time. Let us create a time object
|
||||
|
||||
```js
|
||||
const now = new Date()
|
||||
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.
|
||||
|
||||
### Getting full year
|
||||
|
||||
Let's extract or get the full year from a time object.
|
||||
|
||||
```js
|
||||
const now = new Date()
|
||||
console.log(now.getFullYear()) // 2020
|
||||
```
|
||||
|
||||
### Getting month
|
||||
|
||||
Let's extract or get the month from a time object.
|
||||
|
||||
```js
|
||||
const now = new Date()
|
||||
console.log(now.getMonth()) // 0, because the month is January, month(0-11)
|
||||
```
|
||||
|
||||
### Getting date
|
||||
|
||||
Let's extract or get the date of the month from a time object.
|
||||
|
||||
```js
|
||||
const now = new Date()
|
||||
console.log(now.getDate()) // 4, because the day of the month is 4th, day(1-31)
|
||||
```
|
||||
|
||||
### Getting day
|
||||
|
||||
Let's extract or get the day of the week from a time object.
|
||||
|
||||
```js
|
||||
const now = new Date()
|
||||
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
|
||||
// Getting the weekday as a number (0-6)
|
||||
```
|
||||
|
||||
### Getting hours
|
||||
|
||||
Let's extract or get the hours from a time object.
|
||||
|
||||
```js
|
||||
const now = new Date()
|
||||
console.log(now.getHours()) // 0, because the time is 00:56:41
|
||||
```
|
||||
|
||||
### Getting minutes
|
||||
|
||||
Let's extract or get the minutes from a time object.
|
||||
|
||||
```js
|
||||
const now = new Date()
|
||||
console.log(now.getMinutes()) // 56, because the time is 00:56:41
|
||||
```
|
||||
|
||||
### Getting seconds
|
||||
|
||||
Let's extract or get the seconds from a time object.
|
||||
|
||||
```js
|
||||
const now = new Date()
|
||||
console.log(now.getSeconds()) // 41, because the time is 00:56:41
|
||||
```
|
||||
|
||||
### Getting time
|
||||
|
||||
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()_
|
||||
|
||||
```js
|
||||
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
|
||||
```
|
||||
|
||||
1. Using _Date.now()_
|
||||
|
||||
```js
|
||||
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
|
||||
|
||||
const timeInSeconds = new Date().getTime()
|
||||
console.log(allSeconds == timeInSeconds) // true
|
||||
```
|
||||
|
||||
Let us format these values to a human readable time format.
|
||||
**Example:**
|
||||
|
||||
```js
|
||||
const now = new Date()
|
||||
const year = now.getFullYear() // return year
|
||||
const month = now.getMonth() + 1 // return month(0 - 11)
|
||||
const date = now.getDate() // return date (1 - 31)
|
||||
const hours = now.getHours() // return number (0 - 23)
|
||||
const minutes = now.getMinutes() // return number (0 -59)
|
||||
|
||||
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.
|
||||
|
||||
## 💻 Day 3: Exercises
|
||||
|
||||
### Exercises: Level 1
|
||||
|
||||
1. Declare firstName, lastName, country, city, age, isMarried, year variable and assign value to it and use the typeof operator to check different data types.
|
||||
2. Check if type of '10' is equal to 10
|
||||
3. Check if parseInt('9.8') is equal to 10
|
||||
4. Boolean value is either true or false.
|
||||
1. Write three JavaScript statement which provide truthy 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()
|
||||
1. 4 > 3
|
||||
2. 4 >= 3
|
||||
3. 4 < 3
|
||||
4. 4 <= 3
|
||||
5. 4 == 4
|
||||
6. 4 === 4
|
||||
7. 4 != 4
|
||||
8. 4 !== 4
|
||||
9. 4 != '4'
|
||||
10. 4 == '4'
|
||||
11. 4 === '4'
|
||||
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()
|
||||
1. 4 > 3 && 10 < 12
|
||||
2. 4 > 3 && 10 > 12
|
||||
3. 4 > 3 || 10 < 12
|
||||
4. 4 > 3 || 10 > 12
|
||||
5. !(4 > 3)
|
||||
6. !(4 < 3)
|
||||
7. !(false)
|
||||
8. !(4 > 3 && 10 < 12)
|
||||
9. !(4 > 3 && 10 > 12)
|
||||
10. !(4 === '4')
|
||||
11. There is no 'on' in both dragon and python
|
||||
|
||||
7. Use the Date object to do the following activities
|
||||
1. What is the year today?
|
||||
2. What is the month today as a number?
|
||||
3. What is the date today?
|
||||
4. What is the day today as a number?
|
||||
5. What is the hours now?
|
||||
6. What is the minutes now?
|
||||
7. Find out the numbers of seconds elapsed from January 1, 1970 to now.
|
||||
|
||||
### Exercises: Level 2
|
||||
|
||||
1. Write a script that prompt the user to enter base and height of the triangle and calculate an area of a triangle (area = 0.5 x b x h).
|
||||
|
||||
```sh
|
||||
Enter base: 20
|
||||
Enter height: 10
|
||||
The area of the triangle is 100
|
||||
```
|
||||
|
||||
1. Write a script that prompt the user to enter side a, side b, and side c of the triangle and and calculate the perimeter of triangle (perimeter = a + b + c)
|
||||
|
||||
```sh
|
||||
Enter side a: 5
|
||||
Enter side b: 4
|
||||
Enter side c: 3
|
||||
The perimeter of the triangle is 12
|
||||
```
|
||||
|
||||
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))
|
||||
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.
|
||||
1. Calculate the slope, x-intercept and y-intercept of y = 2x -2
|
||||
1. Slope is m = (y<sub>2</sub>-y<sub>1</sub>)/(x<sub>2</sub>-x<sub>1</sub>). Find the slope between point (2, 2) and point(6,10)
|
||||
1. Compare the slope of above two questions.
|
||||
1. Calculate the value of y (y = x<sup>2</sup> + 6x + 9). Try to use different x values and figure out at what x value y is 0.
|
||||
1. Writ a script that prompt a user to enter hours and rate per hour. Calculate pay of the person?
|
||||
|
||||
```sh
|
||||
Enter hours: 40
|
||||
Enter rate per hour: 28
|
||||
Your weekly earning is 1120
|
||||
```
|
||||
|
||||
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.
|
||||
|
||||
```js
|
||||
let firstName = 'Asabeneh'
|
||||
let lastName = 'Yetayeh'
|
||||
```
|
||||
|
||||
```sh
|
||||
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.
|
||||
|
||||
```js
|
||||
let myAge = 250
|
||||
let yourAge = 25
|
||||
```
|
||||
|
||||
```sh
|
||||
I am 225 years older than you.
|
||||
```
|
||||
|
||||
1. Using prompt get the year the user was born and if the user is 18 or above allow the user to drive if not tell the user to wait a certain amount of years.
|
||||
|
||||
```sh
|
||||
|
||||
Enter birth year: 1995
|
||||
You are 25. You are old enough to drive
|
||||
|
||||
Enter birth year: 2005
|
||||
You are 15. You will be allowed to drive after 3 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
|
||||
Enter number of years you live: 100
|
||||
You lived 3153600000 seconds.
|
||||
```
|
||||
|
||||
1. Create a human readable time format using the Date time object
|
||||
1. YYYY-MM-DD HH:mm
|
||||
2. DD-MM-YYYY HH:mm
|
||||
3. DD/MM/YYYY HH:mm
|
||||
|
||||
### Exercises: Level 3
|
||||
|
||||
1. Create a human readable time format using the Date time object. The hour and the minute should be all the time two digits(7 hours should be 07 and 5 minutes should be 05 )
|
||||
1. YYY-MM-DD HH:mm eg. 20120-01-02 07:05
|
||||
|
||||
[<< Dia 2](../Dia_02_Tipos_Dados/dia_02_tipos_dados.md) | [Dia 4 >>](../04_Day_Conditionals/04_day_conditionals.md)
|
@ -0,0 +1,629 @@
|
||||
<div align="center">
|
||||
<h1> 30 Days Of JavaScript: Booleans, Operators, Date</h1>
|
||||
<a class="header-badge" target="_blank" href="https://www.linkedin.com/in/asabeneh/">
|
||||
<img src="https://img.shields.io/badge/style--5eba00.svg?label=LinkedIn&logo=linkedin&style=social">
|
||||
</a>
|
||||
<a class="header-badge" target="_blank" href="https://twitter.com/Asabeneh">
|
||||
<img alt="Twitter Follow" src="https://img.shields.io/twitter/follow/asabeneh?style=social">
|
||||
</a>
|
||||
|
||||
<sub>Tác giả:
|
||||
<a href="https://www.linkedin.com/in/asabeneh/" target="_blank">Asabeneh Yetayeh</a><br>
|
||||
<small> Tháng 1, 2020</small>
|
||||
</sub>
|
||||
</div>
|
||||
|
||||
[<< Ngày 2](../02_Day_Data_types/02_day_data_types.md) | [Ngày 4 >>](../04_Day_Conditionals/04_day_conditionals.md)
|
||||
|
||||

|
||||
|
||||
- [📔 Ngày 3](#-day-3)
|
||||
- [Booleans](#booleans)
|
||||
- [Giá trị đúng](#gia-tri-dung)
|
||||
- [Giá trị sai](#gia-tri-sai)
|
||||
- [Không xác định](#undefined)
|
||||
- [Giá trị không tồn tại](#null)
|
||||
- [Toán tử](#operators)
|
||||
- [Toán tử gán](#assignment-operators)
|
||||
- [Toán tử số học](#arithmetic-operators)
|
||||
- [Toán tử so sánh](#comparison-operators)
|
||||
- [Toán tử logic](#logical-operators)
|
||||
- [Toán tử tăng](#increment-operator)
|
||||
- [Toán tử giảm](#decrement-operator)
|
||||
- [Toán tử điều kiện](#ternary-operators)
|
||||
- [Độ ưu tiên của toán tử](#operator-precedence)
|
||||
- [Phương thức cửa sổ](#window-methods)
|
||||
- [Phương thức alert()](#window-alert-method)
|
||||
- [Phương thức prompt()](#window-prompt-method)
|
||||
- [Phương thức confirm()](#window-confirm-method)
|
||||
- [Đối tượng Date](#date-object)
|
||||
- [Tạo một đối tượng thời gian](#creating-a-time-object)
|
||||
- [Lấy giá trị năm](#getting-full-year)
|
||||
- [Lấy giá trị tháng](#getting-month)
|
||||
- [Lấy giá trị ngày](#getting-date)
|
||||
- [Lấy giá trị thứ trong tuần](#getting-day)
|
||||
- [Getting hours](#getting-hours)
|
||||
- [Getting minutes](#getting-minutes)
|
||||
- [Getting seconds](#getting-seconds)
|
||||
- [Getting time](#getting-time)
|
||||
- [💻 Ngày 3: Bài tập](#-day-3-exercises)
|
||||
- [Bài tập: Cấp độ 1](#exercises-level-1)
|
||||
- [Bài tập: Cấp độ 2](#exercises-level-2)
|
||||
- [Bài tập: Cấp độ 3](#exercises-level-3)
|
||||
|
||||
# 📔 Day 3
|
||||
|
||||
## Booleans
|
||||
|
||||
|
||||
Dữ liệu boolean thể hiện một trong hai giá trị: True (đúng) hoặc False (sai). Giá trị của boolean sẽ là đúng (True) hoặc sai (False). Việc sử dụng các kiểu dữ liệu này sẽ rõ ràng khi bạn sử dụng toán tử so sánh. Bất kì phương thức so sánh nào đều sẽ trả về giá trị boolean đúng hoặc sai.
|
||||
|
||||
**Ví dụ: Giá Trị Boolean**
|
||||
|
||||
```js
|
||||
let isLightOn = true
|
||||
let isRaining = false
|
||||
let isHungry = false
|
||||
let isMarried = true
|
||||
let truValue = 4 > 3 // true
|
||||
let falseValue = 4 < 3 // false
|
||||
```
|
||||
|
||||
Chúng ta có thể thấy được boolean chỉ có giá trị đúng hoặc sai.
|
||||
|
||||
### Giá trị đúng
|
||||
|
||||
- Mọi số thực (dương và âm) đều mang giá trị đúng trừ 0
|
||||
- Mọi chuỗi đều có giá trị đúng trừ chuỗi rỗng ('')
|
||||
- Boolean đúng
|
||||
|
||||
### Giá trị sai
|
||||
|
||||
- 0
|
||||
- 0n
|
||||
- null
|
||||
- Không xác định
|
||||
- NaN
|
||||
- Boolean sai
|
||||
- '', "", ``, những chuỗi rỗng
|
||||
|
||||
Ghi nhớ những điều kiện để giá trị đúng sai sẽ có ích, bởi vì ở phần tiếp theo, chúng ta sẽ sử dụng chúng với điều kiện để đưa ra lựa chọn.
|
||||
|
||||
## Không xác định
|
||||
|
||||
Nếu chúng ta tạo một biến nhưng không gán một giá trị vào biến ấy, giá trị của biến ấy sẽ là *undefined*. Đồng thời, nếu một phương thức không trả một giá trị, phương thức ấy sẽ cho ra giá trị *underfined*
|
||||
|
||||
```js
|
||||
let firstName
|
||||
console.log(firstName) // Không xác định, bởi vì biến firstName chưa được gán giá trị
|
||||
```
|
||||
|
||||
## Null
|
||||
|
||||
```js
|
||||
let empty = null
|
||||
console.log(empty) // -> null , nghĩa là không tồn tại
|
||||
```
|
||||
|
||||
## Toán tử
|
||||
|
||||
### Toán tử gán
|
||||
|
||||
Dấu bằng trong JavaScript là một toán tử gán. Nó được dụng để gán giá trị vào biến
|
||||
|
||||
```js
|
||||
let firstName = 'Asabeneh' // Gán giá trị 'Asabeneh' vào biến firstName
|
||||
let country = 'Finland' // Gán giá trị 'Finland' vào biến country
|
||||
```
|
||||
|
||||
Toán tử gán
|
||||
|
||||

|
||||
|
||||
### Toán tử số học
|
||||
|
||||
Toán tử số học là những phép tính toán.
|
||||
|
||||
- Phép cộng(+): a + b
|
||||
- Phép trừ(-): a - b
|
||||
- Phép nhân(*): a * b
|
||||
- Phép chia(/): a / b
|
||||
- Phép chia lấy dư(%): a % b
|
||||
- Lũy thừa(**): a ** b
|
||||
|
||||
```js
|
||||
let numOne = 4
|
||||
let numTwo = 3
|
||||
let sum = numOne + numTwo
|
||||
let diff = numOne - numTwo
|
||||
let mult = numOne * numTwo
|
||||
let div = numOne / numTwo
|
||||
let remainder = numOne % numTwo
|
||||
let powerOf = numOne ** numTwo
|
||||
|
||||
console.log(sum, diff, mult, div, remainder, powerOf) // 7,1,12,1.33,1, 64
|
||||
|
||||
```
|
||||
|
||||
```js
|
||||
const PI = 3.14
|
||||
let radius = 100 // độ dài đơn vị mét
|
||||
|
||||
//Let us calculate area of a circle
|
||||
const areaOfCircle = PI * radius * radius
|
||||
console.log(areaOfCircle) // 314 m
|
||||
|
||||
|
||||
const gravity = 9.81 // đơn vị m/s2
|
||||
let mass = 72 // đơn vị Kilogram
|
||||
|
||||
//Chúng ta sẽ tính khối lượng của đối tượng này
|
||||
const weight = mass * gravity
|
||||
console.log(weight) // 706.32 N(Newton)
|
||||
|
||||
const boilingPoint = 100 // Nhiệt độ sôi của nước (oC)
|
||||
const bodyTemp = 37 // Nhiệt độ cơ thể (oC)
|
||||
|
||||
// Nối chuỗi với số sử dụng phép nội suy chuỗi
|
||||
/*
|
||||
The boiling point of water is 100 oC.
|
||||
Human body temperature is 37 oC.
|
||||
The gravity of earth is 9.81 m/s2.
|
||||
*/
|
||||
console.log(
|
||||
`The boiling point of water is ${boilingPoint} oC.\nHuman body temperature is ${bodyTemp} oC.\nThe gravity of earth is ${gravity} m / s2.`
|
||||
)
|
||||
```
|
||||
|
||||
### Toán tử so sánh
|
||||
|
||||
Trong lập trình, khi chúng ta so sánh 2 giá trị với nhau, chúng ta sẽ sử dụng toán tử so sánh. Toán tử so sánh giúp cho chúng ta biết giá trị 1 sẽ lớn hoặc hay nhỏ hơn hoặc bằng giá trị 2.
|
||||
|
||||

|
||||
**Ví dụ: Toán tử so sánh**
|
||||
|
||||
```js
|
||||
console.log(3 > 2) // Đúng, bởi vì 3 lớn hơn 2
|
||||
console.log(3 >= 2) // Đúng, bởi vì 3 lớn hơn 2
|
||||
console.log(3 < 2) // Sai, bởi vì 3 lớn hơn 2
|
||||
console.log(2 < 3) // Đúng, bởi vì 2 bé hơn 3
|
||||
console.log(2 <= 3) // Đúng, bởi vì 2 bé hơn 3
|
||||
console.log(3 == 2) // Sai, bởi vì 3 không bằng 2
|
||||
console.log(3 != 2) // Đúng, bởi vì 3 không bằng 2
|
||||
console.log(3 == '3') // Đúng, chỉ so sánh giá trị
|
||||
console.log(3 === '3') // Sai, so sánh cả giá trị lẫn kiểu dữ liệu
|
||||
console.log(3 !== '3') // Đúng, so sánh cả giá trị lẫn kiểu dữ liệu
|
||||
console.log(3 != 3) // Sai, chỉ so sánh giá trị
|
||||
console.log(3 !== 3) // Sai, so sánh cả giá trị lẫn kiểu dữ liệu
|
||||
console.log(0 == false) // Đúng, 2 giá trị tương đương nhau
|
||||
console.log(0 === false) // Sai, 2 giá trị không giống nhau hoàn toàn
|
||||
console.log(0 == '') // Đúng, giá trị tương đương nhau
|
||||
console.log(0 == ' ') // Đúng, giá trị tương đương nhau
|
||||
console.log(0 === '') // Sai, 2 giá trị không giống nhau hoàn toàn
|
||||
console.log(1 == true) // Đúng, giá trị tương đương nhau
|
||||
console.log(1 === true) // Sai, 2 giá trị không giống nhau hoàn toàn
|
||||
console.log(undefined == null) // Đúng
|
||||
console.log(undefined === null) // Sai
|
||||
console.log(NaN == NaN) // Sai, không bằng nhau
|
||||
console.log(NaN === NaN) // Sai
|
||||
console.log(typeof NaN) // Kiểu dữ liệu số
|
||||
|
||||
console.log('mango'.length == 'avocado'.length) // Sai
|
||||
console.log('mango'.length != 'avocado'.length) // Đúng
|
||||
console.log('mango'.length < 'avocado'.length) // Đúng
|
||||
console.log('milk'.length == 'meat'.length) // Đúng
|
||||
console.log('milk'.length != 'meat'.length) // Sai
|
||||
console.log('tomato'.length == 'potato'.length) // Đúng
|
||||
console.log('python'.length > 'dragon'.length) // Sai
|
||||
```
|
||||
|
||||
Hãy cố hiểu những so sánh trên theo logic, không nên học thuộc lòng bởi vì sẽ khó hơn.
|
||||
Javascript là một ngôn ngữ lập trình lạ. Code Javascript sẽ chạy và đưa ra kết quả nhưng trừ khi bạn thật sự thành thạo ngôn ngữ này, kết quả sẽ không như mong đợi.
|
||||
|
||||
Theo như quy tắc ngón tay, nếu giá trị là không đúng với '==' thì cũng sẽ không đúng với '==='. Sử dụng '===' để so sánh sẽ an toàn hơn sử dụng '=='. Đường [link](https://dorey.github.io/JavaScript-Equality-Table/) sau đây bao gồm một dãy kết quả so sánh giữa các kiểu dữ liệu khác nhau.
|
||||
|
||||
### Toán tử Logic
|
||||
|
||||
Các ký hiệu sau đây là các toán tử logic thông dụng:
|
||||
&& (và) , || (hoặc) và ! (phủ định). Toán tử && sẽ cho kết quả đúng khi cả hai đều kiện đều đúng. Toán tử || sẽ cho kết quả đúng khi một trong hai điều kiện đúng. Toán tử ! sẽ đảo ngược kết quả lại.
|
||||
|
||||
```js
|
||||
// Ví dự toán tử &&
|
||||
|
||||
const check = 4 > 3 && 10 > 5 // đúng && đúng -> đúng
|
||||
const check = 4 > 3 && 10 < 5 // đúng && sai -> sai
|
||||
const check = 4 < 3 && 10 < 5 // sai && sai -> sai
|
||||
|
||||
// Ví dụ toán tử ||
|
||||
|
||||
const check = 4 > 3 || 10 > 5 // đúng || đúng -> đúng
|
||||
const check = 4 > 3 || 10 < 5 // đúng || sai -> đúng
|
||||
const check = 4 < 3 || 10 < 5 // sai || sai -> sai
|
||||
|
||||
//Ví dụ toán tử !
|
||||
|
||||
let check = 4 > 3 // đúng
|
||||
let check = !(4 > 3) // sai
|
||||
let isLightOn = true
|
||||
let isLightOff = !isLightOn // sai
|
||||
let isMarried = !false // đúng
|
||||
```
|
||||
|
||||
### Toán tử tăng
|
||||
|
||||
Trong JavaScipt chúng ta dùng toán tử tăng để tăng giá trị được chứa trong một biến. Toán tử tăng có thể nằm trước hoặc sau. Sau đây là ví dụ về cả 2 dạng:
|
||||
|
||||
1. Tăng nằm trước
|
||||
|
||||
```js
|
||||
let count = 0
|
||||
console.log(++count) // 1
|
||||
console.log(count) // 1
|
||||
```
|
||||
|
||||
1. Tăng nằm sau
|
||||
|
||||
```js
|
||||
let count = 0
|
||||
console.log(count++) // 0
|
||||
console.log(count) // 1
|
||||
```
|
||||
|
||||
Đa phần chúng ta sẽ dùng toán tử tăng nằm sau. Vì thế chúng ta nên nhớ cách sử dụng toán tử tăng nằm sau.
|
||||
|
||||
### Toán tử giảm
|
||||
|
||||
Trong Javascript chúng ta dùng toán tử giảm để giảm giá trị được chứa trong một biến. Toán tử giảm có thể nằm trước hoặc sau. Sau đây là ví dụ về cả 2 dạng:
|
||||
|
||||
1. Giảm nằm trước
|
||||
|
||||
```js
|
||||
let count = 0
|
||||
console.log(--count) // -1
|
||||
console.log(count) // -1
|
||||
```
|
||||
|
||||
2. Giảm nằm sau
|
||||
|
||||
```js
|
||||
let count = 0
|
||||
console.log(count--) // 0
|
||||
console.log(count) // -1
|
||||
```
|
||||
|
||||
### Toán tử điều kiện
|
||||
|
||||
Toán tử điều kiện cho chúng ta viết được điều kiện. Một cách khác để viết điều kiện là sử dụng toán tử điều kiện. Hãy xem các ví dụ sau:
|
||||
|
||||
```js
|
||||
let isRaining = true
|
||||
isRaining
|
||||
? console.log('You need a rain coat.')
|
||||
: console.log('No need for a rain coat.')
|
||||
isRaining = false
|
||||
|
||||
isRaining
|
||||
? console.log('You need a rain coat.')
|
||||
: console.log('No need for a rain coat.')
|
||||
```
|
||||
|
||||
```sh
|
||||
You need a rain coat.
|
||||
No need for a rain coat.
|
||||
```
|
||||
|
||||
```js
|
||||
let number = 5
|
||||
number > 0
|
||||
? console.log(`${number} is a positive number`)
|
||||
: console.log(`${number} is a negative number`)
|
||||
number = -5
|
||||
|
||||
number > 0
|
||||
? console.log(`${number} is a positive number`)
|
||||
: console.log(`${number} is a negative number`)
|
||||
```
|
||||
|
||||
```sh
|
||||
5 is a positive number
|
||||
-5 is a negative number
|
||||
```
|
||||
|
||||
### Độ ưu tiên toán tử
|
||||
|
||||
Nếu bạn muốn biết thêm về độ ưu tiên các toán tử hãy truy cập vào [link](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Operators/Operator_Precedence) này.
|
||||
|
||||
## Phương thức cửa sổ
|
||||
|
||||
### Hàm alert()
|
||||
|
||||
Như ở đầu đã thấy, hàm alert() hiện một cửa sổ cảnh báo với một tin nhắn cụ thể và một nút bấm với chữ 'OK'. Đây là một hàm có sẵn và có thể nhận tham số.
|
||||
|
||||
```js
|
||||
alert(message)
|
||||
```
|
||||
|
||||
```js
|
||||
alert('Welcome to 30DaysOfJavaScript')
|
||||
```
|
||||
|
||||
Đừng sử dụng hàm alert() quá nhiều bởi vì sẽ gây khó chịu cho người sử dụng. Chỉ nên dùng để kiểm tra.
|
||||
|
||||
### Hàm prompt()
|
||||
|
||||
Hàm prompt sẽ hiện một cửa sổ cho phép chúng ta nhập dữ liệu vào trong trình duyệt và dữ liệu sẽ được lưu vào một biến. Hàm prompt() nhận 2 tham số. Tham số thứ hai có thể có hoặc không.
|
||||
|
||||
```js
|
||||
prompt('required text', 'optional text')
|
||||
```
|
||||
|
||||
```js
|
||||
let number = prompt('Enter number', 'number goes here')
|
||||
console.log(number)
|
||||
```
|
||||
|
||||
### Hàm confirm()
|
||||
|
||||
Hàm confirm() hiện một cửa sổ với một đoạn tin nhắn kèm theo một nút bấm 'OK' và nút bấm 'Cancel'.
|
||||
Hàm confirm() thường được dùng để hỏi sự chấp thuận của người dùng trước khi thực hiện một hành động nào đó. Hàm confirm() nhận chuỗi làm tham số. Chọn nút 'OK' sẽ trả về giá trị đúng, còn nút 'Cancel' sẽ trả về giá trị sai.
|
||||
|
||||
```js
|
||||
const agree = confirm('Are you sure you like to delete? ')
|
||||
console.log(agree) // kết quả sẽ trả về đúng hoặc sai tùy vào nút người dùng chọn trong cửa sổ
|
||||
```
|
||||
|
||||
Đây không phải là toàn bộ phương thức cửa sổ. Sẽ có một phần riêng biệt để đi sâu vào các phương thức cửa sổ.
|
||||
|
||||
## Đối tượng Date
|
||||
|
||||
Thời gian là một thứ quan trọng. Chúng ta muốn biết được thời gian của một hành động hoặc sự kiện gì đó. Trong Javascript, thời gian và ngày hiện tại được tạo ra sử dụng Đối tượng Date trong JavaScript. Đối tượng được tạo ra từ đối tượng Date sẽ có nhiều hàm giúp chúng ta trong việc xử lí thời gian và ngày. Những hàm được sử dụng để lấy được thông tin thời gian và ngày trong đối tượng Date đều bắt đầu với từ _get_.
|
||||
_getFullYear(), getMonth(), getDate(), getDay(), getHours(), getMinutes, getSeconds(), getMilliseconds(), getTime(), getDay()_
|
||||
|
||||

|
||||
|
||||
### Tạo một đối tượng thời gian
|
||||
|
||||
Sau khi tạo một đối tượng thời gian. Đối tượng đó sẽ cho chúng ta thông tin về thời gian. Đây là bước để tạo đối tượng thời gian.
|
||||
|
||||
```js
|
||||
const now = new Date()
|
||||
console.log(now) // Sat Jan 04 2020 00:56:41 GMT+0200 (Eastern European Standard Time)
|
||||
```
|
||||
|
||||
Chúng ta đã tạo một đối tượng thời gian. Giờ chúng ta có thể lấy mọi thông tin liên quan đến thời gian từ đối tượng đã tạo bằng cách sử dụng các hàm _get_ trong bảng trên.
|
||||
|
||||
### Lấy năm
|
||||
|
||||
Lấy năm từ đối tượng thời gian
|
||||
|
||||
```js
|
||||
const now = new Date()
|
||||
console.log(now.getFullYear()) // 2020
|
||||
```
|
||||
|
||||
### Lấy tháng
|
||||
|
||||
Lấy tháng từ đối tượng thời gian
|
||||
|
||||
```js
|
||||
const now = new Date()
|
||||
console.log(now.getMonth()) // 0, bởi vì đây là tháng Giêng, tháng(0-11)
|
||||
```
|
||||
|
||||
### Lấy ngày
|
||||
|
||||
Lấy ngày trong tháng từ đối tượng thời gian
|
||||
|
||||
```js
|
||||
const now = new Date()
|
||||
console.log(now.getDate()) // 4, bởi vì ngày trong tháng là ngày bốn, ngày(1-31)
|
||||
```
|
||||
|
||||
### Lấy thứ
|
||||
|
||||
Lấy thứ ngày trong tuần từ đối tượng thời gian
|
||||
|
||||
```js
|
||||
const now = new Date()
|
||||
console.log(now.getDay()) // 6, bởi vì hôm nay là thứ bảy
|
||||
// Chủ nhật là 0, thứ Hai là 1 và thứ bảy là 6
|
||||
// Ngày trong tuần (0-6)
|
||||
```
|
||||
|
||||
### Lấy giờ
|
||||
|
||||
Lấy giờ từ đối tượng thời gian
|
||||
|
||||
```js
|
||||
const now = new Date()
|
||||
console.log(now.getHours()) // 0, bời vì thời gian là 00:56:41
|
||||
```
|
||||
|
||||
### Lấy phút
|
||||
|
||||
Lấy phút từ đối tượng thời gian
|
||||
|
||||
```js
|
||||
const now = new Date()
|
||||
console.log(now.getMinutes()) // 56, bời vì thời gian là 00:56:41
|
||||
```
|
||||
|
||||
### Lấy giây
|
||||
|
||||
Lấy giây từ đối tượng thời gian
|
||||
|
||||
```js
|
||||
const now = new Date()
|
||||
console.log(now.getSeconds()) // 41, bời vì thời gian là 00:56:41
|
||||
```
|
||||
|
||||
### Lấy thời gian
|
||||
|
||||
Phương thức này sẽ cho chúng ta thời gian theo giây tính từ ngày 1, tháng 1, năm 1970. Đây còn được gọi là thời gian Unix. Chúng ta có thể lấy thời gian Unix theo 2 cách sau:
|
||||
|
||||
1. Sử dụng hàm _getTime()_
|
||||
|
||||
```js
|
||||
const now = new Date() //
|
||||
console.log(now.getTime()) // 1578092201341, đây là số giây đã trôi qua kể từ ngày 1, tháng 1, năm 1970 đến 4 Tháng 1, 2020 00:56:41
|
||||
```
|
||||
|
||||
1. Sử dụng hàm _Date.now()_
|
||||
|
||||
```js
|
||||
const allSeconds = Date.now() //
|
||||
console.log(allSeconds) // 1578092201341,đây là số giây đã trôi qua kể từ ngày 1, tháng 1, năm 1970 đến 4 Tháng 1, 2020 00:56:41
|
||||
|
||||
const timeInSeconds = new Date().getTime()
|
||||
console.log(allSeconds == timeInSeconds) // đúng
|
||||
```
|
||||
|
||||
Chúng ta sẽ điều chỉnh lại giá trị để có thể dễ đọc thời gian hơn
|
||||
|
||||
**Ví dụ:**
|
||||
|
||||
```js
|
||||
const now = new Date()
|
||||
const year = now.getFullYear() // Lấy năm
|
||||
const month = now.getMonth() + 1 // Lấy tháng(0 - 11)
|
||||
const date = now.getDate() // Lấy ngày (1 - 31)
|
||||
const hours = now.getHours() // Lấy giờ (0 - 23)
|
||||
const minutes = now.getMinutes() // Lấy phút (0 -59)
|
||||
|
||||
console.log(`${date}/${month}/${year} ${hours}:${minutes}`) // 4/1/2020 0:56
|
||||
```
|
||||
|
||||
🌕 Bạn có năng lượng vô tận. Bạn vừa hoàn thành thử thách của ngày thứ 3 và bạn đã tiến được 3 bước trên con đường vươn tới sự vĩ đại. Bây giờ hãy làm một số bài tập để giúp cho trí não của bạn.
|
||||
|
||||
## 💻 Day 3: Bài tập
|
||||
|
||||
### Bài tập: Level 1
|
||||
|
||||
1. Khai báo biến firstName, lastName, country, city, age, isMarried, year và gán giá trị cho nó và sử dụng toán tử typeof để kiểm tra các kiểu dữ liệu khác nhau.
|
||||
2. Kiểm tra xem kiểu dữ liệu của '10' có giống với 10
|
||||
3. Kiểm tra parseInt('9.8') có bằng 10 không
|
||||
4. Giá trị boolean có thể đúng hoặc sai
|
||||
1. Viết ba câu lệnh JavaScript cung cấp giá trị đúng.
|
||||
2. Viết ba câu lệnh JavaScript cung cấp giá trị sai.
|
||||
|
||||
5. Hãy tìm ra kết quả của các biểu thức so sánh sau không sử dụng console.log(). Sau khi làm xong, hãy xác nhận nó bằng console.log()
|
||||
1. 4 > 3
|
||||
2. 4 >= 3
|
||||
3. 4 < 3
|
||||
4. 4 <= 3
|
||||
5. 4 == 4
|
||||
6. 4 === 4
|
||||
7. 4 != 4
|
||||
8. 4 !== 4
|
||||
9. 4 != '4'
|
||||
10. 4 == '4'
|
||||
11. 4 === '4'
|
||||
12. Tìm độ dài của python và biệt ngữ và đưa ra một câu lệnh so sánh sai
|
||||
|
||||
6. Hãy tìm ra kết quả của các biểu thức so sánh sau không sử dụng console.log(). Sau khi làm xong, hãy xác nhận nó bằng console.log()
|
||||
1. 4 > 3 && 10 < 12
|
||||
2. 4 > 3 && 10 > 12
|
||||
3. 4 > 3 || 10 < 12
|
||||
4. 4 > 3 || 10 > 12
|
||||
5. !(4 > 3)
|
||||
6. !(4 < 3)
|
||||
7. !(false)
|
||||
8. !(4 > 3 && 10 < 12)
|
||||
9. !(4 > 3 && 10 > 12)
|
||||
10. !(4 === '4')
|
||||
11. Không có 'on' trong cả 2 từ dragon và python
|
||||
|
||||
7. Sử dụng đối tượng Date để làm các câu hỏi sau
|
||||
1. Năm nay là năm mấy?
|
||||
2. Tháng này là tháng mấy dưới dạng số?
|
||||
3. Hôm nay ngày mấy?
|
||||
4. Hôm nay là thứ mấy dưới dạng số?
|
||||
5. Bây giờ mấy giờ?
|
||||
6. Bây giờ mấy phút?
|
||||
7. Tìm số giây đã trôi qua kể từ ngày 1, tháng 1, năm 1970 đến bây giờ.
|
||||
|
||||
### Bài tập: Level 2
|
||||
|
||||
1. Viết một đoạn lệnh yêu cầu người dùng nhập độ dài đáy và chiều cao của hình tam giác và tính diện tích của tam giác ấy (diện tích = 0.5 x đáy x cao).
|
||||
|
||||
```sh
|
||||
Enter base: 20
|
||||
Enter height: 10
|
||||
The area of the triangle is 100
|
||||
```
|
||||
|
||||
2. Viết một đoạn lệnh yêu cầu người dùng nhập độ dài cạnh a, cạnh b, cạnh c của hình tam giác và tính chu vi của tam giác ấy (chu vi = a + b + c).
|
||||
|
||||
```sh
|
||||
Enter side a: 5
|
||||
Enter side b: 4
|
||||
Enter side c: 3
|
||||
The perimeter of the triangle is 12
|
||||
```
|
||||
|
||||
3. Yêu cầu nhập độ dài và độ rộng sau đó tính diện tích hình chữ nhật (diện tích = dài x rộng) và tính chu vi hình chữ nhật (chu vi = 2 x (dài + rộng).
|
||||
4. Yêu cầu nhập bán kính r sau đó tính diện tích hình tròn (diện tích = pi x r x r) và tính chu vi hình tròn (chu vi = 2 x pi x r), lấy pi = 3.14.
|
||||
5. Tính hệ số góc, tung độ gốc x và tung độ gốc y của phương trình y = 2x -2
|
||||
6. Tung độ góc m = (y<sub>2</sub>-y<sub>1</sub>)/(x<sub>2</sub>-x<sub>1</sub>). Tìm tung độ góc giữa 2 điểm (2, 2) và (6, 10).
|
||||
7. So sánh tung độ góc của câu 5 và câu 6.
|
||||
8. Tính giá trị của y (y = x<sup>2</sup> + 6x + 9). Hãy thử sử dụng các giá trị x khác nhau và tìm ra giá trị x để y bằng 0.
|
||||
9. Viết đoạn lệnh yêu cầu người dùng nhập thời gian và mức lương theo giờ. Tính lương của người đó?
|
||||
|
||||
```sh
|
||||
Enter hours: 40
|
||||
Enter rate per hour: 28
|
||||
Your weekly earning is 1120
|
||||
```
|
||||
|
||||
10. Nếu độ dài tên bạn lớn hơn 7, hiển thị 'your name is long' nếu không, hiển thị 'your name is short'.
|
||||
11. So sánh tên của bạn và họ của bạn, hiển thị kết quả theo cấu trúc sau.
|
||||
|
||||
```js
|
||||
let firstName = 'Asabeneh'
|
||||
let lastName = 'Yetayeh'
|
||||
```
|
||||
|
||||
```sh
|
||||
Your first name, Asabeneh is longer than your family name, Yetayeh
|
||||
```
|
||||
|
||||
12. Tạo 2 biến _myAge_ và _yourAge_ và gán giá trị vào 2 biến ấy. Hiển thị kết quả theo cấu trúc sau.
|
||||
|
||||
```js
|
||||
let myAge = 250
|
||||
let yourAge = 25
|
||||
```
|
||||
|
||||
```sh
|
||||
I am 225 years older than you.
|
||||
```
|
||||
|
||||
13. Yêu cầu người dùng nhập năm sinh. Nếu người dùng lớn hơn hoặc bằng 18, cho phép người dùng lái xe. Nếu không hiển thị số năm người dùng cần phải chờ để đủ 18.
|
||||
|
||||
```sh
|
||||
|
||||
Enter birth year: 1995
|
||||
You are 25. You are old enough to drive
|
||||
|
||||
Enter birth year: 2005
|
||||
You are 15. You will be allowed to drive after 3 years.
|
||||
```
|
||||
|
||||
14. Viết đoạn lệnh yêu cầu người dùng nhập số năm. Tính số giây của số năm đã nhập.
|
||||
|
||||
```sh
|
||||
Enter number of years you live: 100
|
||||
You lived 3153600000 seconds.
|
||||
```
|
||||
|
||||
15. Tạo các định dạng thời gian dễ đọc sử dụng đối tượng Date
|
||||
1. YYYY-MM-DD HH:mm
|
||||
2. DD-MM-YYYY HH:mm
|
||||
3. DD/MM/YYYY HH:mm
|
||||
|
||||
### Bài tập: Level 3
|
||||
|
||||
1. Tạo định dạng thời gian có thể đọc được bằng cách sử dụng đối tượng Date. Giờ và phút phải luôn có hai chữ số (7 giờ phải là 07 và 5 phút phải là 05 )
|
||||
1. YYY-MM-DD HH:mm eg. 20120-01-02 07:05
|
||||
|
||||
[<< Day 2](../02_Day_Data_types/02_day_data_types.md) | [Day 4 >>](../04_Day_Conditionals/04_day_conditionals.md)
|
Loading…
Reference in new issue