Skip to content

Commit 00c4b55

Browse files
Add files via upload
1 parent cd2246d commit 00c4b55

File tree

3 files changed

+116
-0
lines changed

3 files changed

+116
-0
lines changed

bjs/10_function_object/index.html

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
<!DOCTYPE html>
2+
<html lang="en">
3+
<head>
4+
<meta charset="UTF-8">
5+
<title>Генератор случайных пользователей</title>
6+
<link rel="stylesheet" href="https://stackpath.bootstrapcdn.com/bootstrap/4.4.1/css/bootstrap.min.css"
7+
integrity="sha384-Vkoo8x4CGsO3+Hhxv8T/Q5PaXtkKtu6ug5TOeNV6gBiFeWPGFN9MuhOf23Q9Ifjh" crossorigin="anonymous">
8+
<link href="https://fonts.googleapis.com/css2?family=Open+Sans" rel="stylesheet">
9+
<link rel="stylesheet" href="style.css" type="text/css"/>
10+
</head>
11+
<body>
12+
<div class="container">
13+
<div class="row game-card align-items-center">
14+
<div class="col col-md-6 offset-md-3">
15+
<div class="card text-center">
16+
<div class="card-header">
17+
<p class="m-0">Окно результатов генерации</p>
18+
</div>
19+
<div class="card-body">
20+
<div class="row">
21+
<div class="col">
22+
<h3 class="card-title"><span id="surnameOutput">Генерация фамилии</span></h3>
23+
<h4>Имя: <span id="firstNameOutput">Иван</span></h4>
24+
<p>
25+
<span id="genderOutput">Генерация пола</span>
26+
<span>, </span>
27+
<span id="birthYearOutput">Генерация года рождения</span>
28+
</p>
29+
</div>
30+
</div>
31+
</div>
32+
</div>
33+
</div>
34+
</div>
35+
</div>
36+
<script src="personGenerator.js"></script>
37+
<script src="init.js"></script>
38+
</body>
39+
</html>

bjs/10_function_object/init.js

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
2+
window.onload = function()
3+
{
4+
const initPerson = personGenerator.getPerson();
5+
document.getElementById('firstNameOutput').innerText = initPerson.firstName;
6+
};
7+
Lines changed: 70 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,70 @@
1+
const personGenerator = {
2+
surnameJson: `{
3+
"count": 15,
4+
"list": {
5+
"id_1": "Иванов",
6+
"id_2": "Смирнов",
7+
"id_3": "Кузнецов",
8+
"id_4": "Васильев",
9+
"id_5": "Петров",
10+
"id_6": "Михайлов",
11+
"id_7": "Новиков",
12+
"id_8": "Федоров",
13+
"id_9": "Кравцов",
14+
"id_10": "Николаев",
15+
"id_11": "Семёнов",
16+
"id_12": "Славин",
17+
"id_13": "Степанов",
18+
"id_14": "Павлов",
19+
"id_15": "Александров",
20+
"id_16": "Морозов"
21+
}
22+
}`,
23+
firstNameMaleJson: `{
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+
}`,
38+
39+
GENDER_MALE: 'Мужчина',
40+
GENDER_FEMALE: 'Женщина',
41+
42+
randomIntNumber: (max = 1, min = 0) => Math.floor(Math.random() * (max - min + 1) + min),
43+
44+
randomValue: function (json) {
45+
const obj = JSON.parse(json);
46+
const prop = `id_${this.randomIntNumber(obj.count, 1)}`; // this = personGenerator
47+
return obj.list[prop];
48+
},
49+
50+
randomFirstName: function() {
51+
52+
return this.randomValue(this.firstNameMaleJson);
53+
54+
},
55+
56+
57+
randomSurname: function() {
58+
59+
return this.randomValue(this.surnameJson);
60+
61+
},
62+
63+
64+
getPerson: function () {
65+
this.person = {};
66+
// this.person.gender = this.randomGender();
67+
this.person.firstName = this.randomFirstName();
68+
return this.person;
69+
}
70+
};

0 commit comments

Comments
 (0)