You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
//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)
231
231
console.log(Math.log(2)) // 0.6931471805599453
232
232
console.log(Math.log(10)) // 2.302585092994046
233
233
@@ -244,7 +244,7 @@ Math.cos(60)
244
244
The JavaScript Math Object has a random() method number generator which generates number from 0 to 0.999999999...
245
245
246
246
```js
247
-
let randomNum =Math.random() // generates 0 to 0.999
247
+
let randomNum =Math.random() // generates 0 to 0.999...
248
248
```
249
249
250
250
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
261
261
262
262
## Strings
263
263
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.
265
265
Let's see some examples of strings:
266
266
267
267
```js
@@ -272,12 +272,13 @@ let country = 'Finland'
272
272
let city ='Helsinki'
273
273
let language ='JavaScript'
274
274
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.`
275
277
```
276
278
277
279
### String Concatenation
278
280
279
281
Connecting two or more strings together is called concatenation.
280
-
281
282
Using the strings declared in the previous String section:
282
283
283
284
```js
@@ -305,8 +306,9 @@ let city = 'Helsinki'
305
306
let language ='JavaScript'
306
307
let job ='teacher'
307
308
let age =250
308
-
let fullName =firstName.concat(space).concat(lastName) // concat string method
309
309
310
+
311
+
let fullName =firstName + space + lastName
310
312
let personInfoOne = fullName +'. I am '+ age +'. I live in '+ country; // ES5 string addition
311
313
312
314
console.log(personInfoOne)
@@ -330,6 +332,7 @@ to global audience and I started a Python challenge from November 20 - December
330
332
It was one of the most rewarding and inspiring experience.\
331
333
Now, we are in 2020. I am enjoying preparing the 30DaysOfJavaScript challenge and \
332
334
I hope you are enjoying too."
335
+
333
336
console.log(paragraph)
334
337
```
335
338
@@ -341,7 +344,7 @@ In JavaScript and other programming languages \ followed by some characters is a
341
344
- \t: Tab, means 8 spaces
342
345
-\\\\: Back slash
343
346
-\\': Single quote (')
344
-
-\\":Double quote (")
347
+
-\\":Double quote (")
345
348
346
349
```js
347
350
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
374
377
375
378
#### Template Literals (Template Strings)
376
379
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.
378
381
379
382
```js
380
383
//Syntax
@@ -528,17 +531,17 @@ console.log(country.substring(3)) // land
528
531
```js
529
532
let string = '30 Days Of JavaScript'
530
533
531
-
console.log(string.split()) // ["30 Days Of JavaScript"]
@@ -626,10 +629,8 @@ console.log(string.charCodeAt(lastIndex)) // t ASCII is 116
626
629
627
630
```
628
631
629
-
630
632
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
631
633
632
-
633
634
```js
634
635
string.indexOf(substring)
635
636
```
@@ -704,11 +705,11 @@ string.endsWith(substring)
704
705
```
705
706
706
707
```js
707
-
let string = 'Love is the best to in this world'
708
+
let string = 'Love is the most powerful feeling in the world'
708
709
709
710
console.log(string.endsWith('world')) // true
710
711
console.log(string.endsWith('love')) // false
711
-
console.log(string.endsWith('in this world')) // true
712
+
console.log(string.endsWith('in the world')) // true
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.
721
722
722
723
```js
723
724
string.search(substring)
724
725
```
725
726
726
727
```js
727
728
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
729
731
```
730
732
731
733
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.
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.
775
777
776
778
```js
777
779
string.repeat(n)
@@ -931,7 +933,6 @@ console.log(numInt) // 9
931
933
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.
932
934
```
933
935
934
-
935
936
2. Using console.log() print out the following quote by Mother Teresa:
936
937
937
938
```sh
@@ -955,6 +956,7 @@ console.log(numInt) // 9
955
956
4 1 4 16 64
956
957
5 1 5 25 125
957
958
```
959
+
958
960
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'__
0 commit comments