Skip to content

Commit 1451814

Browse files
committed
update SkillfactoryCoding#10 firstname surname birthday gender generation
1 parent 0c692bc commit 1451814

File tree

3 files changed

+76
-8
lines changed

3 files changed

+76
-8
lines changed

bjs/10_function_object/index.html

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -22,9 +22,9 @@
2222
<h3 class="card-title"><span id="surnameOutput">Генерация фамилии</span></h3>
2323
<h4>Имя: <span id="firstNameOutput">Иван</span></h4>
2424
<p>
25-
<span id="genderOutput">Генерация пола</span>
26-
<span>, </span>
27-
<span id="birthYearOutput">Генерация года рождения</span>
25+
<span id="genderOutput">Генерация пола</span><!--
26+
--><span>, </span><!--
27+
--><span id="birthYearOutput">Генерация года рождения</span>
2828
</p>
2929
</div>
3030
</div>

bjs/10_function_object/init.js

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,9 @@
22
window.onload = function()
33
{
44
const initPerson = personGenerator.getPerson();
5-
document.getElementById('firstNameOutput').innerText = initPerson.firstName;
5+
document.querySelector('#firstNameOutput').innerText = initPerson.firstName;
6+
document.querySelector('#surnameOutput').innerText = initPerson.surName;
7+
document.querySelector('#genderOutput').innerText = initPerson.gender;
8+
document.querySelector('#birthYearOutput').innerText = initPerson.birthday;
69
};
710

bjs/10_function_object/personGenerator.js

Lines changed: 69 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,21 @@ 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+
}`,
3853

3954
GENDER_MALE: 'Мужчина',
4055
GENDER_FEMALE: 'Женщина',
@@ -49,22 +64,72 @@ const personGenerator = {
4964

5065
randomFirstName: function() {
5166

52-
return this.randomValue(this.firstNameMaleJson);
67+
if (this.person.gender === this.GENDER_MALE)
68+
{
69+
return this.randomValue(this.firstNameMaleJson);
70+
}
71+
else
72+
{
73+
return this.randomValue(this.firstNameFemaleJson);
74+
}
75+
76+
},
77+
78+
79+
randomSurname: function() {
80+
81+
let result = this.randomValue(this.surnameJson);
82+
83+
if (this.person.gender === this.GENDER_FEMALE)
84+
{
85+
result = result + "а";
86+
}
87+
88+
return result;
89+
90+
},
91+
92+
randomGender: function() {
93+
94+
return this.randomIntNumber() === 1 ? this.GENDER_MALE : this.GENDER_FEMALE;
5395

5496
},
5597

98+
randomDate: function() {
5699

57-
randomSurname: function() {
100+
const year = this.randomIntNumber(110, 70) + 1900;
101+
const month = this.randomIntNumber(12, 1);
102+
103+
const isEven = month % 2 === 0;
104+
105+
let maxDay;
106+
107+
if (month === 2)
108+
{
109+
const isLeap = year % 4 === 0;
110+
maxDay = isLeap ? 29 : 28;
111+
}
112+
else if (month < 8)
113+
{
114+
maxDay = isEven ? 30 : 31;
115+
}
116+
else
117+
{
118+
maxDay = isEven ? 31 : 30;
119+
}
58120

59-
return this.randomValue(this.surnameJson);
121+
const day = this.randomIntNumber(maxDay, 1);
60122

123+
return `${day}.${month}.${year}`;
61124
},
62125

63126

64127
getPerson: function () {
65128
this.person = {};
66-
// this.person.gender = this.randomGender();
129+
this.person.gender = this.randomGender();
67130
this.person.firstName = this.randomFirstName();
131+
this.person.surName = this.randomSurname();
132+
this.person.birthday = this.randomDate();
68133
return this.person;
69134
}
70135
};

0 commit comments

Comments
 (0)