Skip to content

Commit 13427cf

Browse files
update homework_15
1 parent 152b057 commit 13427cf

File tree

1 file changed

+125
-107
lines changed

1 file changed

+125
-107
lines changed

js-core/homeworks/homework-15/index.js

Lines changed: 125 additions & 107 deletions
Original file line numberDiff line numberDiff line change
@@ -54,120 +54,138 @@ console.log('Task2 ---> ', flatten([25, 10, [10, [15]]]));
5454

5555

5656
//Task3
57-
const dataUsers = [
58-
{
59-
name: 'Иван',
60-
lastName: 'Петров',
61-
62-
},
63-
{
64-
name: 'Сергей',
65-
lastName: 'Сергей',
66-
67-
},
68-
{
69-
name: 'Иван',
70-
lastName: 'Иванов',
71-
72-
},
73-
{
74-
name: 'Александр',
75-
lastName: 'Александров',
76-
77-
},
78-
{
79-
name: 'Алекс',
80-
lastName: 'Смирнов',
81-
82-
},
83-
{
84-
name: 'Сергей',
85-
lastName: 'Волков',
86-
87-
},
88-
{
89-
name: 'Мария',
90-
lastName: 'Шарапова',
91-
92-
},
93-
{
94-
name: 'Александр',
95-
lastName: 'Винник',
96-
97-
},
98-
{
99-
name: 'Дарий',
100-
lastName: 'Смирнов',
101-
102-
},
103-
{
104-
name: 'Елена',
105-
lastName: 'Лещенко',
106-
107-
},
108-
{
109-
name: 'Ольга',
110-
lastName: 'Новикова',
111-
112-
},
113-
{
114-
name: 'Наталья',
115-
lastName: 'Шемякина',
116-
117-
},
118-
{
119-
name: 'Анна',
120-
lastName: 'Донцова',
121-
122-
},
123-
{
124-
name: 'Влад',
125-
lastName: 'Яма',
126-
127-
},
128-
{
129-
name: 'Кира',
130-
lastName: 'Воробьева',
131-
132-
},
133-
{
134-
name: 'Виктор',
135-
lastName: 'Кривенко',
136-
137-
}
138-
];
57+
class UsersContacts {
58+
constructor() {
59+
this.dataUsers = [
60+
{
61+
name: 'Иван',
62+
lastName: 'Петров',
63+
64+
},
65+
{
66+
name: 'Сергей',
67+
lastName: 'Сергей',
68+
69+
},
70+
{
71+
name: 'Иван',
72+
lastName: 'Иванов',
73+
74+
},
75+
{
76+
name: 'Александр',
77+
lastName: 'Александров',
78+
79+
},
80+
{
81+
name: 'Алекс',
82+
lastName: 'Смирнов',
83+
84+
},
85+
{
86+
name: 'Сергей',
87+
lastName: 'Волков',
88+
89+
},
90+
{
91+
name: 'Мария',
92+
lastName: 'Шарапова',
93+
94+
},
95+
{
96+
name: 'Александр',
97+
lastName: 'Винник',
98+
99+
},
100+
{
101+
name: 'Дарий',
102+
lastName: 'Смирнов',
103+
104+
},
105+
{
106+
name: 'Елена',
107+
lastName: 'Лещенко',
108+
109+
},
110+
{
111+
name: 'Ольга',
112+
lastName: 'Новикова',
113+
114+
},
115+
{
116+
name: 'Наталья',
117+
lastName: 'Шемякина',
118+
119+
},
120+
{
121+
name: 'Анна',
122+
lastName: 'Донцова',
123+
124+
},
125+
{
126+
name: 'Влад',
127+
lastName: 'Яма',
128+
129+
},
130+
{
131+
name: 'Кира',
132+
lastName: 'Воробьева',
133+
134+
},
135+
{
136+
name: 'Виктор',
137+
lastName: 'Кривенко',
138+
139+
}
140+
];
141+
this.columnHeadings = ['Name', 'Last name', 'Email'];
142+
};
139143

140-
const columnHeadings = ['Name', 'Last name', 'Email'];
144+
render() {
145+
let insert = document.querySelector('main > div');
146+
insert.appendChild(this.createTable());
147+
};
141148

142-
function render() {
143-
let createNewElement = function(newElem) {
149+
createNewElement(newElem) {
144150
return document.createElement(newElem);
145151
};
146-
let table = createNewElement('table');
147-
table.setAttribute('class', 'table table-hover contacts');
148-
let insert = document.querySelector('main > div');
149-
let thead = createNewElement('thead');
150-
table.appendChild(thead);
151-
let tr = createNewElement('tr');
152-
thead.appendChild(tr);
153-
columnHeadings.forEach((elem) => {
154-
let th = createNewElement('th');
155-
th.textContent = elem;
156-
tr.appendChild(th);
157-
});
158-
let tbody = createNewElement('tbody');
159-
table.appendChild(tbody);
160-
dataUsers.forEach((elem) => {
161-
let trInTbody = createNewElement('tr')
162-
tbody.appendChild(trInTbody);
152+
153+
createTable() {
154+
let table = this.createNewElement('table');
155+
table.setAttribute('class', 'table table-hover contacts');
156+
table.appendChild(this.cteateTheadInTable());
157+
table.appendChild(this.cteateTbodyInTable());
158+
return table;
159+
};
160+
161+
cteateTheadInTable() {
162+
let thead = this.createNewElement('thead');
163+
let tr = this.createNewElement('tr');
164+
thead.appendChild(tr);
165+
this.columnHeadings.forEach((elem) => {
166+
let th = this.createNewElement('th');
167+
th.textContent = elem;
168+
tr.appendChild(th);
169+
});
170+
return thead;
171+
};
172+
173+
cteateTbodyInTable() {
174+
let tbody = this.createNewElement('tbody');
175+
//table.appendChild(tbody);
176+
this.dataUsers.forEach((elem) => {
177+
let tr = this.createNewElement('tr')
178+
tbody.appendChild(tr);
163179
let arrObjkeys = Object.keys(elem);
164180
arrObjkeys.forEach((elemTd) => {
165-
let td = createNewElement('td');
181+
let td = this.createNewElement('td');
166182
td.textContent = elem[elemTd];
167-
trInTbody.appendChild(td);
183+
tr.appendChild(td);
184+
});
168185
});
169-
});
170-
return insert.appendChild(table);
186+
return tbody;
187+
};
171188
};
172189

173-
render();
190+
let usersContacts = new UsersContacts();
191+
usersContacts.render();

0 commit comments

Comments
 (0)