@@ -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