Skip to content

Commit d0b95e7

Browse files
committed
day 3
1 parent b6fd2c6 commit d0b95e7

2 files changed

Lines changed: 153 additions & 39 deletions

File tree

images/date_time_object.png

81 KB
Loading

readMe.md

Lines changed: 153 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,9 @@
4747
- [Escape Sequences in string](#escape-sequences-in-string)
4848
- [Template Literals(Template Strings)](#template-literalstemplate-strings)
4949
- [String Methods](#string-methods)
50+
- [💻 Day 2: Exercises](#%f0%9f%92%bb-day-2-exercises)
51+
- [Exercises: String Part](#exercises-string-part)
52+
- [📔 Day 3](#%f0%9f%93%94-day-3)
5053
- [Booleans](#booleans-1)
5154
- [Undefined](#undefined-1)
5255
- [Null](#null-1)
@@ -58,13 +61,22 @@
5861
- [Increment Operator](#increment-operator)
5962
- [Decrement Operator](#decrement-operator)
6063
- [Operator Precendence](#operator-precendence)
61-
- [💻 Day 2: Exercises](#%f0%9f%92%bb-day-2-exercises)
62-
- [Exercises: String Part](#exercises-string-part)
64+
- [Date Object](#date-object)
65+
- [Creating a time object](#creating-a-time-object)
66+
- [Getting full year](#getting-full-year)
67+
- [Getting month](#getting-month)
68+
- [Getting date](#getting-date)
69+
- [Getting hours](#getting-hours)
70+
- [Getting minutes](#getting-minutes)
71+
- [Getting seconds](#getting-seconds)
72+
- [Getting time](#getting-time)
73+
- [💻 Day 3: Exercises](#%f0%9f%92%bb-day-3-exercises)
6374
- [Exercises: Data types Part](#exercises-data-types-part)
6475
- [Exercises: Arithmetic Operators Part](#exercises-arithmetic-operators-part)
6576
- [Exercises: Booleans Part](#exercises-booleans-part)
6677
- [Exercises: Comparison Operators](#exercises-comparison-operators)
6778
- [Exercises: Logical Operators](#exercises-logical-operators)
79+
- [Exercises: Date time Object](#exercises-date-time-object)
6880

6981

7082
# 📔Day 1
@@ -744,14 +756,17 @@ In JavaScript and other programming language \ followed by some characters is a
744756
* \\': Single quote (')
745757
* \\":Double quote (")
746758
```js
747-
console.log('I hope every one is enjoying the 30 Days Of JavaScript challenge.\nDo you ?') # line break
759+
console.log('I hope every one is enjoying the 30 Days Of JavaScript challenge.\nDo you ?') // line break
748760
console.log('Days\tTopics\tExercises')
749761
console.log('Day 1\t3\t5')
750762
console.log('Day 2\t3\t5')
751763
console.log('Day 3\t3\t5')
752764
console.log('Day 4\t3\t5')
753-
console.log('This is a back slash symbol (\\)') # To write a back slash
754-
console.log('In every programming language it starts with \"Hello, World!\"')
765+
console.log('This is a back slash symbol (\\)') // To write a back slash
766+
console.log('In every programming language it starts with \"Hello, World!\"')
767+
console.log("In every programming language it starts with \'Hello, World!\'")
768+
console.log('The saying \'Seeing is Believing\' is\'t correct in 2020')
769+
755770
```
756771
#### Template Literals(Template Strings)
757772
To create a template string, we use two backticks. We can inject data as expression inside a template string. To inject data, we enclose the expression with a curly bracket({}) followed by a $ sign. See the syntax below.
@@ -1070,6 +1085,54 @@ let string = 'love'
10701085
console.log(string.repeat(10)) // lovelovelovelovelovelovelovelovelovelove
10711086
```
10721087

1088+
1089+
1090+
# 💻 Day 2: Exercises
1091+
## Exercises: String Part
1092+
1093+
1. Declare a variable name challenge and assign it to an initial value **'30 Days Of JavaScript'**.
1094+
2. Print the string on the browser console using __console.log()__
1095+
3. Print the __length__ of the string on the browser console using _console.log()_
1096+
4. Change all the string to capital letters using __toUpperCase()__ method
1097+
5. Change all the string to lowercase letters using __toLowerCase()__ method
1098+
6. Cut(slice) out the first word of the string using __substr()__ or __substring()__ method
1099+
7. Slice out the phrase *Days Of JavaScript* from *30 Days Of JavaScript*.
1100+
8. Use __substr__ to slice out the phase __because because because__ in the following sentence:__'You cannot end a sentence with because because because is a conjunction'__
1101+
9. Check if the string contains a word __Script__ using __includes()__ method
1102+
10. Split the __string__ into __array__ using __split()__ method
1103+
11. Split the string 30 Days Of JavaScript at the space using __split()__ method
1104+
12. 'Facebook, Google, Microsoft, Apple, IBM, Oracle, Amazon' __split__ the string at the comma and change it to an array.
1105+
13. Change 30 Days Of JavaScript to 30 Days Of Python using __replace()__ method.
1106+
14. What is character at index 15 in '30 Days Of JavaScript' string use __charAt()__ method.
1107+
15. What is the character code of J in '30 Days Of JavaScript' string using __charCodeAt()__
1108+
16. Use __indexOf__ to determine the position of the first occurrence of a in 30 Days Of JavaScript
1109+
17. Use __lastIndexOf__ to determine the position of the last occurrence of a in 30 Days Of JavaScript.
1110+
18. Use __indexOf__ to find the position of the first occurrence of the word __because__ in the following sentence:__'You cannot end a sentence with because because because is a conjunction'__
1111+
19. Use __lastIndexOf__ to find the position of the first occurrence of the word __because__ in the following sentence:__'You cannot end a sentence with because because because is a conjunction'__
1112+
20. Use __search__ to find the position of the first occurrence of the word __because__ in the following sentence:__'You cannot end a sentence with because because because is a conjunction'__
1113+
21. Use __trim()__ to remove if there is trailing whitespace at the beginning and the end of a string.E.g ' 30 Days Of JavaScript '.
1114+
22. Use __startsWith()__ method with the string *30 Days Of JavaScript* make the result true
1115+
23. Use __endsWith()__ method with the string *30 Days Of JavaScript* make the result true
1116+
24. Use __match()__ method to find all the a’s in 30 Days Of JavaScript
1117+
25. Use __match()__ to count the number all because's in the following sentence:__'You cannot end a sentence with because because because is a conjunction'__
1118+
26. Use __concat()__ and merge '30 Days of' and 'JavaScript' to a single string, '30 Days Of JavaScript'
1119+
27. Use __repeat()__ method to print 30 Days Of JavaScript 2 times
1120+
28. Love is the best thing in this world. Some found their love and some are still looking for their love. Count the number of word love in this sentence.
1121+
29. Calculate the total annual income of the person by extract the numbers from the following text. 'He earns 5000 euro from salary per month, 10000 euro annual bonus, 15000 euro online courses per month.'
1122+
30. Clean the following text and find the most frequent word(hint, use replace and regular express).
1123+
```js
1124+
const sentence = '%I $am@% a %tea@cher%, &and& I lo%#ve %tea@ching%;. There $is nothing; &as& mo@re rewarding as educa@ting &and& @emp%o@wering peo@ple. ;I found tea@ching m%o@re interesting tha@n any other %jo@bs. %Do@es thi%s mo@tivate yo@u to be a tea@cher!? %Th#is 30#Days&OfJavaScript &is also $the $result of &love& of tea&ching'
1125+
```
1126+
31. Using console.log() print out the following statement.
1127+
```sh
1128+
The quote 'There is no exercise better for the heart than reaching down and lifting people up.' by John Holmes teaches us to help to one another.
1129+
```
1130+
32. Using console.log() print out the following quote by Mother Teresa.
1131+
```sh
1132+
"Love is not patronizing and charity isn't about pity, it is about love. Charity and love are the same -- with charity you give love, so don't just give money but reach out your hand instead."
1133+
```
1134+
1135+
# 📔 Day 3
10731136
## Booleans
10741137

10751138
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.
@@ -1242,42 +1305,82 @@ console.log(count) // -1
12421305
### Operator Precendence
12431306
I would like to recommend you to read about operator precendence from this [link](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Operators/Operator_Precedence)
12441307

1245-
# 💻 Day 2: Exercises
1246-
## Exercises: String Part
1308+
## Date Object
1309+
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.
1310+
_getFullYear(), getMonths(), getDate(), getDay(), getHours(), getMinutes, getSeconds(), getMilliseconds(), getTime(), getDay()_
12471311

1248-
1. Declare a variable name challenge and assign it to an initial value **'30 Days Of JavaScript'**.
1249-
2. Print the string on the browser console using __console.log()__
1250-
3. Print the __length__ of the string on the browser console using _console.log()_
1251-
4. Change all the string to capital letters using __toUpperCase()__ method
1252-
5. Change all the string to lowercase letters using __toLowerCase()__ method
1253-
6. Cut(slice) out the first word of the string using __substr()__ or __substring()__ method
1254-
7. Slice out the phrase *Days Of JavaScript* from *30 Days Of JavaScript*.
1255-
8. Use __substr__ to slice out the phase __because because because__ in the following sentence:__'You cannot end a sentence with because because because is a conjunction'__
1256-
9. Check if the string contains a word __Script__ using __includes()__ method
1257-
10. Split the __string__ into __array__ using __split()__ method
1258-
11. Split the string 30 Days Of JavaScript at the space using __split()__ method
1259-
12. 'Facebook, Google, Microsoft, Apple, IBM, Oracle, Amazon' __split__ the string at the comma and change it to an array.
1260-
13. Change 30 Days Of JavaScript to 30 Days Of Python using __replace()__ method.
1261-
14. What is character at index 15 in '30 Days Of JavaScript' string use __charAt()__ method.
1262-
15. What is the character code of J in '30 Days Of JavaScript' string using __charCodeAt()__
1263-
16. Use __indexOf__ to determine the position of the first occurrence of a in 30 Days Of JavaScript
1264-
17. Use __lastIndexOf__ to determine the position of the last occurrence of a in 30 Days Of JavaScript.
1265-
18. Use __indexOf__ to find the position of the first occurrence of the word __because__ in the following sentence:__'You cannot end a sentence with because because because is a conjunction'__
1266-
19. Use __lastIndexOf__ to find the position of the first occurrence of the word __because__ in the following sentence:__'You cannot end a sentence with because because because is a conjunction'__
1267-
20. Use __search__ to find the position of the first occurrence of the word __because__ in the following sentence:__'You cannot end a sentence with because because because is a conjunction'__
1268-
21. Use __trim()__ to remove if there is trailing whitespace at the beginning and the end of a string.E.g ' 30 Days Of JavaScript '.
1269-
22. Use __startsWith()__ method with the string *30 Days Of JavaScript* make the result true
1270-
23. Use __endsWith()__ method with the string *30 Days Of JavaScript* make the result true
1271-
24. Use __match()__ method to find all the a’s in 30 Days Of JavaScript
1272-
25. Use __match()__ to count the number all because's in the following sentence:__'You cannot end a sentence with because because because is a conjunction'__
1273-
26. Use __concat()__ and merge '30 Days of' and 'JavaScript' to a single string, '30 Days Of JavaScript'
1274-
27. Use __repeat()__ method to print 30 Days Of JavaScript 2 times
1275-
28. Love is the best thing in this world. Some found their love and some are still looking for their love. Count the number of word love in this sentence.
1276-
29. Calculate the total annual income of the person by extract the numbers from the following text. 'He earns 5000 euro from salary per month, 10000 euro annual bonus, 15000 euro online courses per month.'
1277-
30. Clean the following text and find the most frequent word(hint, use replace and regular express).
1312+
![Date time Object](images/date_time_object.png)
1313+
### Creating a time object
1314+
Once we create time object. The time object will provide information about time. Let us create a time object
12781315
```js
1279-
const sentence = '%I $am@% a %tea@cher%, &and& I lo%#ve %tea@ching%;. There $is nothing; &as& mo@re rewarding as educa@ting &and& @emp%o@wering peo@ple. ;I found tea@ching m%o@re interesting tha@n any other %jo@bs. %Do@es thi%s mo@tivate yo@u to be a tea@cher!? %Th#is 30#Days&OfJavaScript &is also $the $result of &love& of tea&ching'
1316+
const now = new Date () //
1317+
console.log(now) // Sat Jan 04 2020 00:56:41 GMT+0200 (Eastern European Standard Time)
12801318
```
1319+
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.
1320+
### Getting full year
1321+
Let's extract or get the full from a time object.
1322+
```js
1323+
const now = new Date () //
1324+
console.log(now.getFullYear()) // 2020
1325+
```
1326+
### Getting month
1327+
Let's extract or get the month from a time object.
1328+
```js
1329+
const now = new Date () //
1330+
console.log(now.getMonth()) // 0, because the month is January, month(0-11)
1331+
```
1332+
### Getting date
1333+
Let's extract or get the date of the month from a time object.
1334+
```js
1335+
const now = new Date () //
1336+
console.log(now.getMonth()) // 0, because the month is January, month(0-11)
1337+
```
1338+
### Getting hours
1339+
Let's extract or get the hours from a time object.
1340+
```js
1341+
const now = new Date () //
1342+
console.log(now.getHours()) // 0, because the time is 00:56:41
1343+
```
1344+
### Getting minutes
1345+
Let's extract or get the minutes from a time object.
1346+
```js
1347+
const now = new Date () //
1348+
console.log(now.getMinutes()) // 56, because the time is 00:56:41
1349+
```
1350+
### Getting seconds
1351+
Let's extract or get the minutes from a time object.
1352+
```js
1353+
const now = new Date () //
1354+
console.log(now.getMinutes()) // 56, because the time is 00:56:41
1355+
```
1356+
### Getting time
1357+
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:
1358+
1. Using *getTime()*
1359+
```js
1360+
const now = new Date () //
1361+
console.log(now.getTime()) // 1578092201341, this is the number of seconds passed from January 1, 1970 to January 4, 2020 00:56:41
1362+
```
1363+
2. Using *Date.now()*
1364+
```js
1365+
const allSeconds = Date.now () //
1366+
console.log(allSeconds) // 1578092201341, this is the number of seconds passed from January 1, 1970 to January 4, 2020 00:56:41
1367+
const timeInSeconds = new Date ().getTime()
1368+
console.log(allSeconds == timeInSeconds) // true
1369+
```
1370+
Let us format these values to a human readable time format.
1371+
**Example:**
1372+
```js
1373+
1374+
const now = new Date ();
1375+
const year = now.getFullYear(); // return year
1376+
const month = now.getMonth() + 1; // return month(0 - 11)
1377+
const date = now.getDate(); // return date (1 - 31)
1378+
const hours = now.getHours(); // return number (0 - 23)
1379+
const minutes = now.getMinutes();// return number (0 -59)
1380+
console.log(`${date}/${month}/${year} ${hours}:${minutes}`) // 4/1/2020 0:56
1381+
```
1382+
1383+
# 💻 Day 3: Exercises
12811384
## Exercises: Data types Part
12821385
1. Declare firstName, lastName, country, city, age, isMarried, year variable and assign value to it
12831386

@@ -1327,7 +1430,18 @@ Figure out the result of the following expressions first without using console.l
13271430
1. !(4 > 3 && 10 < 12)
13281431
1. !(4 > 3 && 10 > 12)
13291432
1. !(4 === '4')
1330-
1433+
## Exercises: Date time Object
1434+
1. What is the year today?
1435+
1. What is the month today?
1436+
1. What is the date today?
1437+
1. What is the day today?
1438+
1. What is the hours now?
1439+
1. What is the minutes now?
1440+
1. Find out the numbers of seconds elapsed from January 1, 1970 to now.
1441+
1. Create a human readable time format
1442+
1. YYY-MM-DD HH:mm:ss
1443+
2. DD-MM-YYYY HH:mm:ss
1444+
3. DD/MM/YYY HH:mm:ss
13311445

13321446

13331447

0 commit comments

Comments
 (0)