1+ // Regural Expressions
2+
3+ let myReguralExpression = / j a v a - s c r i p t / ;
4+
5+ console . log ( myReguralExpression . test ( 'java-script' ) ) ;
6+
7+ const myNewRegExp = new RegExp ( 'some' ) ;
8+
9+ console . log ( myNewRegExp . test ( 'some' ) ) ;
10+
11+ // []
12+ console . log ( '--------' ) ;
13+
14+ let checkRegExp = new RegExp ( '[A-C]' ) ;
15+
16+ console . log ( checkRegExp . test ( 'A' ) ) ;
17+ console . log ( checkRegExp . test ( 'B' ) ) ;
18+ console . log ( checkRegExp . test ( 'C' ) ) ;
19+ console . log ( checkRegExp . test ( 'a' ) ) ;
20+ console . log ( checkRegExp . test ( 'b' ) ) ;
21+ console . log ( checkRegExp . test ( 'D' ) ) ;
22+
23+ // Task 1
24+
25+ function check ( string ) {
26+ const rightAnswer = new RegExp ( 'JavaScript' ) ;
27+ return rightAnswer . test ( string ) ;
28+ }
29+
30+ console . log ( check ( 'JavaScript' ) ) ;
31+ console . log ( check ( 'JavaScrpt' ) ) ;
32+
33+ //----------
34+
35+ const superJs = 'JS is is is is awesome' ;
36+
37+ console . log ( superJs . replace ( / i s / gi, 'are' ) ) ;
38+
39+ /*
40+ i - делает не чувствительным к регистру
41+ g - заменяет все совпадения
42+ */
43+
44+ //Task 2
45+
46+ function holdOneIs ( string ) {
47+ const secretKey = '%_%_%' ;
48+ return string . replace ( / i s / i, secretKey ) . replace ( / i s / gmi, '' ) . replace ( secretKey , 'is' ) ;
49+ }
50+
51+ console . log ( holdOneIs ( superJs ) ) ;
52+
53+ // ^ логическое НЕ
54+
55+ //DOM
56+
57+ const div = document . createElement ( 'div' ) ;
58+ div . textContent = 'content' ;
59+
60+ console . dir ( div ) ;
61+
62+ const div2 = document . createElement ( 'div' ) ;
63+
64+ div . append ( div2 ) ;
65+
66+ console . log ( div ) ;
67+
68+ document . body . appendChild ( div ) ;
69+
70+ //Task 3
71+
72+ const ul = document . createElement ( 'ul' ) ;
73+ const firstLi = document . createElement ( 'li' ) ;
74+ const secondLi = document . createElement ( 'li' ) ;
75+ const thirdLi = document . createElement ( 'li' ) ;
76+
77+ firstLi . textContent = 'JavaScript' ;
78+ secondLi . textContent = 'React' ;
79+ thirdLi . textContent = 'Node.js' ;
80+
81+ ul . append ( firstLi ) ;
82+ ul . append ( secondLi ) ;
83+ ul . append ( thirdLi ) ;
84+
85+ document . body . appendChild ( ul ) ;
86+ // -----------
87+ const ul2 = document . createElement ( 'ul' ) ;
88+ // Визуализация данных
89+ const content = [ 'qwerty' , 'test' , 'EPAM' , 'awda' ] ;
90+
91+ for ( let i = 0 ; i < content . length ; i ++ ) {
92+ let li = document . createElement ( 'li' ) ;
93+ li . textContent = content [ i ] ;
94+ ul2 . append ( li ) ;
95+ }
96+
97+ document . body . appendChild ( ul2 ) ;
0 commit comments