Skip to content

Commit 01247c4

Browse files
committed
final commit SkillfactoryCoding#1
1 parent 9c35d7e commit 01247c4

File tree

4 files changed

+154
-9
lines changed

4 files changed

+154
-9
lines changed

bjs/10_function_object/index.html

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -19,16 +19,21 @@
1919
<div class="card-body">
2020
<div class="row">
2121
<div class="col">
22-
<h3 class="card-title"><span id="surnameOutput">Генерация фамилии</span></h3>
23-
<h4>Имя: <span id="firstNameOutput">Иван</span></h4>
22+
<h3 class="card-title"><span id="surnameOutput"></span></h3>
23+
<h4><span id="firstNameOutput"></span></h4>
24+
<h4><span id="middleNameOutput"></span></h4>
25+
<h5><span id="professionOutput"></span></h5>
2426
<p>
25-
<span id="genderOutput">Генерация пола</span>
27+
<span id="genderOutput"></span>
2628
<span>, </span>
27-
<span id="birthYearOutput">Генерация года рождения</span>
29+
<h6>Дата рождения: <span id="birthYearOutput">Генерация года рождения</span></h6>
2830
</p>
2931
</div>
3032
</div>
3133
</div>
34+
<div class="card-btn">
35+
<button id="resetOutput" type="reset" class="btn btn-warning">Нажми для генерации</button>
36+
</div>
3237
</div>
3338
</div>
3439
</div>

bjs/10_function_object/init.js

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,5 +3,13 @@ window.onload = function()
33
{
44
const initPerson = personGenerator.getPerson();
55
document.getElementById('firstNameOutput').innerText = initPerson.firstName;
6+
document.getElementById('middleNameOutput').innerText = initPerson.middleName;
7+
document.getElementById('professionOutput').innerText = initPerson.profession;
8+
document.getElementById('surnameOutput').innerText = initPerson.surname;
9+
document.getElementById('genderOutput').innerText = initPerson.gender;
10+
document.getElementById('birthYearOutput').innerText = initPerson.birthday;
11+
document.getElementById('resetOutput').onclick = function() {
12+
location.reload();
13+
};
614
};
715

bjs/10_function_object/personGenerator.js

Lines changed: 125 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -35,36 +35,156 @@ const personGenerator = {
3535
"id_10": "Андрей"
3636
}
3737
}`,
38+
firstNameFemaleJson: `{
39+
"count": 10,
40+
"list": {
41+
"id_1": "Александра",
42+
"id_2": "Наталия",
43+
"id_3": "Ирина",
44+
"id_4": "Анна",
45+
"id_5": "Екатерина",
46+
"id_6": "Ярослава",
47+
"id_7": "Светлана",
48+
"id_8": "Анастасия",
49+
"id_9": "Валентина",
50+
"id_10": "Елена"
51+
}
52+
}`,
53+
54+
professionMaleJson: `{
55+
"count": 7,
56+
"list": {
57+
"id_1": "Слесарь",
58+
"id_2": "Инженер",
59+
"id_3": "Строитель",
60+
"id_4": "Водитель",
61+
"id_5": "Военный",
62+
"id_6": "Автомеханик",
63+
"id_7": "Программист"
64+
}
65+
}`,
66+
67+
professionFeMaleJson: `{
68+
"count": 7,
69+
"list": {
70+
"id_1": "Доктор",
71+
"id_2": "Манекенщица",
72+
"id_3": "Учитель",
73+
"id_4": "Домохозяйка",
74+
"id_5": "Бухгалтер",
75+
"id_6": "Менеджер",
76+
"id_7": "Продавец"
77+
}
78+
}`,
79+
80+
middleNameMaleJson: `{
81+
"count": 7,
82+
"list": {
83+
"id_1": "Александрович",
84+
"id_2": "Петрович",
85+
"id_3": "Владимирович",
86+
"id_4": "Дмитриевич",
87+
"id_5": "Анатольевич",
88+
"id_6": "Константинович",
89+
"id_7": "Сергеевич"
90+
}
91+
}`,
92+
93+
middleNameFeMaleJson: `{
94+
"count": 7,
95+
"list": {
96+
"id_1": "Александровна",
97+
"id_2": "Петровна",
98+
"id_3": "Владимировна",
99+
"id_4": "Дмитриевна",
100+
"id_5": "Анатольевна",
101+
"id_6": "Константиновна",
102+
"id_7": "Сергеевна"
103+
}
104+
}`,
38105

39106
GENDER_MALE: 'Мужчина',
40107
GENDER_FEMALE: 'Женщина',
41108

42-
randomIntNumber: (max = 1, min = 0) => Math.floor(Math.random() * (max - min + 1) + min),
43109

110+
randomIntNumber: (max = 1, min = 0) => Math.floor(Math.random() * (max - min + 1) + min),
111+
44112
randomValue: function (json) {
45113
const obj = JSON.parse(json);
46114
const prop = `id_${this.randomIntNumber(obj.count, 1)}`; // this = personGenerator
47115
return obj.list[prop];
48116
},
49117

50-
randomFirstName: function() {
118+
randomFirstNameMale: function() {
51119

52120
return this.randomValue(this.firstNameMaleJson);
121+
},
53122

123+
randomMiddleNameMale: function() {
124+
return this.randomValue(this.middleNameMaleJson);
54125
},
55126

127+
randomProfessionMale: function() {
128+
return this.randomValue(this.professionMaleJson);
129+
},
56130

57-
randomSurname: function() {
131+
randomFirstNameFeMale: function() {
132+
return this.randomValue(this.firstNameFemaleJson);
133+
},
58134

135+
randomMiddleNameFemale: function() {
136+
return this.randomValue(this.middleNameFeMaleJson);
137+
},
138+
139+
randomProfessionFeMale: function() {
140+
return this.randomValue(this.professionFeMaleJson);
141+
},
142+
143+
144+
randomSurname: function() {
59145
return this.randomValue(this.surnameJson);
146+
},
60147

148+
randomGender: function() {
149+
return (this.randomIntNumber(1, 0) === 0) ? this.GENDER_FEMALE : this.GENDER_MALE
61150
},
62151

152+
randomBirthDate: function(min, max) {
153+
if (min instanceof Date) {
154+
min = min.getTime();
155+
}
156+
157+
if (max instanceof Date) {
158+
max = max.getTime();
159+
}
160+
161+
const r = this.randomIntNumber(max, min);
162+
163+
return new Date(r)
164+
},
165+
63166

64167
getPerson: function () {
65168
this.person = {};
66-
// this.person.gender = this.randomGender();
67-
this.person.firstName = this.randomFirstName();
169+
this.person.gender = this.randomGender();
170+
this.person.surname = this.randomSurname();
171+
if (this.person.gender == this.GENDER_FEMALE) {
172+
this.person.surname += 'а';
173+
this.person.firstName = this.randomFirstNameFeMale();
174+
this.person.profession = this.randomProfessionFeMale();
175+
this.person.middleName = this.randomMiddleNameFemale();
176+
} else {
177+
this.person.firstName = this.randomFirstNameMale();
178+
this.person.profession = this.randomProfessionMale();
179+
this.person.middleName = this.randomMiddleNameMale();
180+
}
181+
var now = new Date();
182+
this.person.birthday = this.randomBirthDate(
183+
new Date(now.getFullYear() - 70, now.getMonth(), now.getDate()),
184+
new Date(now.getFullYear() - 18, now.getMonth(), now.getDate())
185+
);
186+
187+
68188
return this.person;
69189
}
70190
};

bjs/10_function_object/style.css

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
.card-header {
2+
background-color: rgb(243, 132, 6);
3+
font-size: large;
4+
}
5+
6+
.card-body {
7+
background-color: rgb(196, 194, 194);
8+
}
9+
10+
.btn {
11+
margin: 5px 5px;
12+
}

0 commit comments

Comments
 (0)