Skip to content

Commit 37a37eb

Browse files
committed
generation name SkillfactoryCoding#1 change
1 parent 5c54b0a commit 37a37eb

File tree

4 files changed

+173
-9
lines changed

4 files changed

+173
-9
lines changed

bjs/10_function_object/index.html

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,16 +19,22 @@
1919
<div class="card-body">
2020
<div class="row">
2121
<div class="col">
22-
<h3 class="card-title"><span id="surnameOutput">Генерация фамилии</span></h3>
22+
<h3 class="card-title"><span id="surnameOutput">Генерация фамилии: Иванов</span></h3>
2323
<h4>Имя: <span id="firstNameOutput">Иван</span></h4>
24+
<h4>Отчество: <span id="middleName">Иванович</span></h4>
2425
<p>
2526
<span id="genderOutput">Генерация пола</span>
2627
<span>, </span>
27-
<span id="birthYearOutput">Генерация года рождения</span>
28+
<span id="dayOutput"></span><span> </span><span id="monthOutput"></span><span> </span><span id="birthYearOutput">Генерация года рождения</span> <span>, </span>
29+
<span id="profession">Профессия</span>
2830
</p>
2931
</div>
3032
</div>
3133
</div>
34+
<div class="btn-group">
35+
<button class="btn btn-info btn-lg" id="btnStart">Генерация!</button>
36+
<button class="btn btn-success btn-lg" id="btnReset">Сброс!</button>
37+
</div>
3238
</div>
3339
</div>
3440
</div>

bjs/10_function_object/init.js

Lines changed: 23 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,28 @@
1+
const generation = document.getElementById('btnStart');
2+
const reset = document.getElementById('btnReset');
13

2-
window.onload = function()
4+
generation.addEventListener('click', function()
35
{
46
const initPerson = personGenerator.getPerson();
57
document.getElementById('firstNameOutput').innerText = initPerson.firstName;
6-
};
8+
document.getElementById('middleName').innerText = initPerson.middleName;
9+
document.getElementById('surnameOutput').innerText = `Фамилия: ${initPerson.surname}`;
10+
document.getElementById('genderOutput').innerText = initPerson.gender;
11+
document.getElementById('birthYearOutput').innerText = initPerson.year;
12+
document.getElementById('dayOutput').innerText = initPerson.day;
13+
document.getElementById('monthOutput').innerText = initPerson.month;
14+
document.getElementById('profession').innerText = initPerson.profession;
15+
});
716

17+
reset.addEventListener('click', function()
18+
{
19+
document.getElementById('surnameOutput').innerText = "Генерация фамилии: Иванов";
20+
document.getElementById('firstNameOutput').innerText = "Иван";
21+
document.getElementById('middleName').innerText = "Иванович";
22+
document.getElementById('genderOutput').innerText = "Генерация пола";
23+
document.getElementById('birthYearOutput').innerText = "Генерация года рождения";
24+
document.getElementById('dayOutput').innerText = "";
25+
document.getElementById('monthOutput').innerText = "";
26+
document.getElementById('profession').innerText = "Профессия";
27+
document.getElementById('middleName').innerText = "Иванович";
28+
});

bjs/10_function_object/personGenerator.js

Lines changed: 129 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
const personGenerator = {
22
surnameJson: `{
3-
"count": 15,
3+
"count": 16,
44
"list": {
55
"id_1": "Иванов",
66
"id_2": "Смирнов",
@@ -20,6 +20,21 @@ const personGenerator = {
2020
"id_16": "Морозов"
2121
}
2222
}`,
23+
firstNameFemaleJson: `{
24+
"count": 10,
25+
"list": {
26+
"id_1": "Екатерина",
27+
"id_2": "Анна",
28+
"id_3": "Рита",
29+
"id_4": "Мария",
30+
"id_5": "Юлия",
31+
"id_6": "Алиса",
32+
"id_7": "Полина",
33+
"id_8": "Соня",
34+
"id_9": "Ольга",
35+
"id_10": "Елена"
36+
}
37+
}`,
2338
firstNameMaleJson: `{
2439
"count": 10,
2540
"list": {
@@ -35,6 +50,55 @@ const personGenerator = {
3550
"id_10": "Андрей"
3651
}
3752
}`,
53+
middleNameJson: `{
54+
"count": 10,
55+
"list": {
56+
"id_1": "Александро",
57+
"id_2": "Максимо",
58+
"id_3": "Ивано",
59+
"id_4": "Артемо",
60+
"id_5": "Дмитре",
61+
"id_6": "Никито",
62+
"id_7": "Михаило",
63+
"id_8": "Даниило",
64+
"id_9": "Егоро",
65+
"id_10": "Андрее"
66+
}
67+
}`,
68+
monthJson: `{
69+
"count": 12,
70+
"list": {
71+
"id_1": "Января",
72+
"id_2": "Февраля",
73+
"id_3": "Марта",
74+
"id_4": "Апреля",
75+
"id_5": "Мая",
76+
"id_6": "Июня",
77+
"id_7": "Июля",
78+
"id_8": "Августа",
79+
"id_9": "Сентября",
80+
"id_10": "Октября",
81+
"id_11": "Ноября",
82+
"id_12": "Декабря"
83+
}
84+
}`,
85+
professionJson: `{
86+
"count": 12,
87+
"list": {
88+
"id_1": "Шахтер",
89+
"id_2": "Повар",
90+
"id_3": "Врач",
91+
"id_4": "Медсестра",
92+
"id_5": "Водитель",
93+
"id_6": "Строитель",
94+
"id_7": "Официант",
95+
"id_8": "Программист",
96+
"id_9": "Инженер",
97+
"id_10": "Солдат",
98+
"id_11": "Менеджер",
99+
"id_12": "Риэлтор"
100+
}
101+
}`,
38102

39103
GENDER_MALE: 'Мужчина',
40104
GENDER_FEMALE: 'Женщина',
@@ -53,18 +117,78 @@ const personGenerator = {
53117

54118
},
55119

120+
randomFirstNameShe: function() {
121+
122+
return this.randomValue(this.firstNameFemaleJson);
123+
124+
},
56125

57-
randomSurname: function() {
126+
randomSurname: function() {
58127

59128
return this.randomValue(this.surnameJson);
60129

61130
},
62131

132+
randomMiddleName: function() {
133+
134+
return this.randomValue(this.middleNameJson);
135+
136+
},
137+
138+
randomMonth: function () {
139+
140+
return this.randomValue(this.monthJson);
141+
142+
},
143+
144+
randomProfession: function () {
145+
146+
return this.randomValue(this.professionJson);
147+
148+
},
149+
150+
randomGender: function () {
151+
const randomGender=this.randomIntNumber(2, 1);
152+
if (randomGender==1) {
153+
return this.GENDER_MALE;
154+
}else {
155+
return this.GENDER_FEMALE;
156+
}
157+
},
63158

64159
getPerson: function () {
65160
this.person = {};
66-
// this.person.gender = this.randomGender();
67-
this.person.firstName = this.randomFirstName();
161+
this.person.year = this.randomIntNumber(2002, 1920);
162+
const crazyYear = this.person.year % 4;
163+
this.person.month = this.randomMonth();
164+
if ((this.person.month == "Апреля") || (this.person.month == "Июня") || (this.person.month == "Сентября") || (this.person.month == "Ноября")) {
165+
this.person.day = this.randomIntNumber(30, 1);
166+
}else if (this.person.month == "Февраля") {
167+
if (crazyYear == 0) {
168+
this.person.day = this.randomIntNumber(29, 1);
169+
}else {
170+
this.person.day = this.randomIntNumber(28, 1);};
171+
}else{
172+
this.person.day = this.randomIntNumber(30, 1);};
173+
this.person.profession = this.randomProfession();
174+
if (this.person.profession == "Медсестра") {
175+
this.person.gender = this.GENDER_FEMALE;
176+
}else if ((this.person.profession == "Шахтер") || (this.person.profession == "Строитель") || (this.person.profession == "Солдат")) {
177+
this.person.gender = this.GENDER_MALE;
178+
}else {
179+
this.person.gender = this.randomGender();
180+
};
181+
if (this.person.gender == this.GENDER_MALE) {
182+
this.person.firstName = this.randomFirstName();
183+
this.person.surname = this.randomSurname();
184+
this.person.middleName = `${this.randomMiddleName()}вич`;
185+
}else {
186+
this.person.firstName = this.randomFirstNameShe();
187+
this.person.surname = `${this.randomSurname()}a`;
188+
this.person.middleName = `${this.randomMiddleName()}вна`;
189+
}
190+
68191
return this.person;
69-
}
192+
},
193+
70194
};

bjs/10_function_object/style.css

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
.card {
2+
background-color: Khaki;
3+
}
4+
5+
.card-header {
6+
background-color: goldenrod;
7+
color: white;
8+
font-size: 28px;
9+
}
10+
11+
.btn-group {
12+
margin: 5px;
13+
}

0 commit comments

Comments
 (0)