Skip to content

Commit 9bdd818

Browse files
committed
day 2 reviewed
1 parent 65bc076 commit 9bdd818

1 file changed

Lines changed: 29 additions & 27 deletions

File tree

02_Day/02_day_data_types.md

Lines changed: 29 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -18,8 +18,8 @@
1818

1919
![Thirty Days Of JavaScript](../images/banners/day_1_2.png)
2020

21-
- [📔 Day 2](#%f0%9f%93%94-day-2)
22-
- [Data types](#data-types)
21+
- [📔 Day 2](#-day-2)
22+
- [Data Types](#data-types)
2323
- [Primitive Data Types](#primitive-data-types)
2424
- [Non-Primitive Data Types](#non-primitive-data-types)
2525
- [Numbers](#numbers)
@@ -28,7 +28,7 @@
2828
- [Random Number Generator](#random-number-generator)
2929
- [Strings](#strings)
3030
- [String Concatenation](#string-concatenation)
31-
- [Concatenating Using Dddition Operator](#concatenating-using-addition-operator)
31+
- [Concatenating Using Addition Operator](#concatenating-using-addition-operator)
3232
- [Long Literal Strings](#long-literal-strings)
3333
- [Escape Sequences in Strings](#escape-sequences-in-strings)
3434
- [Template Literals (Template Strings)](#template-literals-template-strings)
@@ -39,7 +39,7 @@
3939
- [String to Int](#string-to-int)
4040
- [String to Float](#string-to-float)
4141
- [Float to Int](#float-to-int)
42-
- [💻 Day 2: Exercises](#%f0%9f%92%bb-day-2-exercises)
42+
- [💻 Day 2: Exercises](#-day-2-exercises)
4343
- [Exercise: Level 1](#exercise-level-1)
4444
- [Exercise: Level 2](#exercise-level-2)
4545
- [Exercises: Level 3](#exercises-level-3)
@@ -170,11 +170,11 @@ Let's see some examples of Numbers.
170170

171171
```js
172172
let age = 35
173-
const gravity = 9.81 //we use const for non-changing values, gravitational constant in m/s2
173+
const gravity = 9.81 // we use const for non-changing values, gravitational constant in m/s2
174174
let mass = 72 // mass in Kilogram
175175
const PI = 3.14 // pi a geometrical constant
176176

177-
//More Examples
177+
// More Examples
178178
const boilingPoint = 100 // temperature in oC, boiling point of water which is a constant
179179
const bodyTemp = 37 // oC average human body temperature, which is a constant
180180

@@ -227,7 +227,7 @@ console.log(Math.pow(3, 2)) // 9
227227
console.log(Math.E) // 2.718
228228

229229
// Logarithm
230-
//Returns the natural logarithm with base E of x, Math.log(x)
230+
// Returns the natural logarithm with base E of x, Math.log(x)
231231
console.log(Math.log(2)) // 0.6931471805599453
232232
console.log(Math.log(10)) // 2.302585092994046
233233

@@ -244,7 +244,7 @@ Math.cos(60)
244244
The JavaScript Math Object has a random() method number generator which generates number from 0 to 0.999999999...
245245

246246
```js
247-
let randomNum = Math.random() // generates 0 to 0.999
247+
let randomNum = Math.random() // generates 0 to 0.999...
248248
```
249249

250250
Now, let us see how we can use random() method to generate a random number between 0 and 10:
@@ -261,7 +261,7 @@ console.log(randomNumRoundToFloor) // this gives between 0 and 10
261261

262262
## Strings
263263

264-
Strings are texts, which are under **_single_** or **_double_** quote. To declare a string, we need a variable name, assignment operator, a value under a single quote, double quote, or backtick quote.
264+
Strings are texts, which are under **_single_** , **_double_**, **_back-tick_** quote. To declare a string, we need a variable name, assignment operator, a value under a single quote, double quote, or backtick quote.
265265
Let's see some examples of strings:
266266

267267
```js
@@ -272,12 +272,13 @@ let country = 'Finland'
272272
let city = 'Helsinki'
273273
let language = 'JavaScript'
274274
let job = 'teacher'
275+
let quote = "The saying,'Seeing is Believing' is not correct in 2020."
276+
let quotWithBackTick = `The saying,'Seeing is Believing' is not correct in 2020.`
275277
```
276278

277279
### String Concatenation
278280

279281
Connecting two or more strings together is called concatenation.
280-
281282
Using the strings declared in the previous String section:
282283

283284
```js
@@ -305,8 +306,9 @@ let city = 'Helsinki'
305306
let language = 'JavaScript'
306307
let job = 'teacher'
307308
let age = 250
308-
let fullName = firstName.concat(space).concat(lastName) // concat string method
309309

310+
311+
let fullName =firstName + space + lastName
310312
let personInfoOne = fullName + '. I am ' + age + '. I live in ' + country; // ES5 string addition
311313

312314
console.log(personInfoOne)
@@ -330,6 +332,7 @@ to global audience and I started a Python challenge from November 20 - December
330332
It was one of the most rewarding and inspiring experience.\
331333
Now, we are in 2020. I am enjoying preparing the 30DaysOfJavaScript challenge and \
332334
I hope you are enjoying too."
335+
333336
console.log(paragraph)
334337
```
335338

@@ -341,7 +344,7 @@ In JavaScript and other programming languages \ followed by some characters is a
341344
- \t: Tab, means 8 spaces
342345
- \\\\: Back slash
343346
- \\': Single quote (')
344-
- \\":Double quote (")
347+
- \\": Double quote (")
345348

346349
```js
347350
console.log('I hope everyone is enjoying the 30 Days Of JavaScript challenge.\nDo you ?') // line break
@@ -374,7 +377,7 @@ The saying 'Seeing is Believing' isn't correct in 2020
374377
375378
#### Template Literals (Template Strings)
376379
377-
To create a template strings, we use two backticks. We can inject data as expressions inside a template string. To inject data, we enclose the expression with a curly bracket({}) preceded by a $ sign. See the syntax below.
380+
To create a template strings, we use two back-ticks. We can inject data as expressions inside a template string. To inject data, we enclose the expression with a curly bracket({}) preceded by a $ sign. See the syntax below.
378381
379382
```js
380383
//Syntax
@@ -528,17 +531,17 @@ console.log(country.substring(3)) // land
528531
```js
529532
let string = '30 Days Of JavaScript'
530533
531-
console.log(string.split()) // ["30 Days Of JavaScript"]
532-
console.log(string.split(' ')) // ["30", "Days", "Of", "JavaScript"]
534+
console.log(string.split()) // Changes to an array -> ["30 Days Of JavaScript"]
535+
console.log(string.split(' ')) // Split to an array at space -> ["30", "Days", "Of", "JavaScript"]
533536
534537
let firstName = 'Asabeneh'
535538
536-
console.log(firstName.split()) // ["Asabeneh"]
537-
console.log(firstName.split('')) // ["A", "s", "a", "b", "e", "n", "e", "h"]
539+
console.log(firstName.split()) // Change to an array - > ["Asabeneh"]
540+
console.log(firstName.split('')) // Split to an array at each letter -> ["A", "s", "a", "b", "e", "n", "e", "h"]
538541
539542
let countries = 'Finland, Sweden, Norway, Denmark, and Iceland'
540543
541-
console.log(countries.split(',')) // ["Finland", " Sweden", " Norway", " Denmark", " and Iceland"]
544+
console.log(countries.split(',')) // split to any array at comma -> ["Finland", " Sweden", " Norway", " Denmark", " and Iceland"]
542545
console.log(countries.split(', ')) //  ["Finland", "Sweden", "Norway", "Denmark", "and Iceland"]
543546
```
544547

@@ -547,7 +550,7 @@ console.log(countries.split(', ')) //  ["Finland", "Sweden", "Norway", "Denmark
547550
```js
548551
let string = ' 30 Days Of JavaScript '
549552
550-
console.log(string)
553+
console.log(string)
551554
console.log(string.trim(' '))
552555
553556
let firstName = ' Asabeneh '
@@ -626,10 +629,8 @@ console.log(string.charCodeAt(lastIndex)) // t ASCII is 116
626629
627630
```
628631
629-
630632
13. *indexOf()*: 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
631633
632-
633634
```js
634635
string.indexOf(substring)
635636
```
@@ -704,11 +705,11 @@ string.endsWith(substring)
704705
```
705706
706707
```js
707-
let string = 'Love is the best to in this world'
708+
let string = 'Love is the most powerful feeling in the world'
708709
709710
console.log(string.endsWith('world')) // true
710711
console.log(string.endsWith('love')) // false
711-
console.log(string.endsWith('in this world')) // true
712+
console.log(string.endsWith('in the world')) // true
712713
713714
let country = 'Finland'
714715
@@ -717,15 +718,16 @@ console.log(country.endsWith('fin')) // false
717718
console.log(country.endsWith('Fin')) // false
718719
```
719720
720-
18. *search*: it takes a substring as an argument and it returns the index of the first match.
721+
18. *search*: it takes a substring as an argument and it returns the index of the first match. The search value can be a string or a regular expression pattern.
721722
722723
```js
723724
string.search(substring)
724725
```
725726
726727
```js
727728
let string = 'I love JavaScript. If you do not love JavaScript what else can you love.'
728-
console.log(string.search('love')) // 2
729+
console.log(string.search('love')) // 2
730+
console.log(string.search(/javascript/gi)) // 7
729731
```
730732
731733
19. *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.
@@ -771,7 +773,7 @@ console.log(txt.match(regEx)) // ["2", "0", "1", "9", "3", "0", "2", "0", "2",
771773
console.log(txt.match(/\d+/g)) // ["2019", "30", "2020"]
772774
```
773775
774-
20. *repeat()*: it takes a number as argument and it returns the repeated version of the string.
776+
20. *repeat()*: it takes a number as argument and it returns the repeated version of the string.
775777
776778
```js
777779
string.repeat(n)
@@ -931,7 +933,6 @@ console.log(numInt) // 9
931933
The quote 'There is no exercise better for the heart than reaching down and lifting people up.' by John Holmes teaches us to help one another.
932934
```
933935
934-
935936
2. Using console.log() print out the following quote by Mother Teresa:
936937
937938
```sh
@@ -955,6 +956,7 @@ console.log(numInt) // 9
955956
4 1 4 16 64
956957
5 1 5 25 125
957958
```
959+
958960
12. Use __substr__ to slice out the phrase __because because because__ from the following sentence:__'You cannot end a sentence with because because because is a conjunction'__
959961
960962
### Exercises: Level 3

0 commit comments

Comments
 (0)