Skip to content

Commit a5ee1ec

Browse files
authored
Merge pull request #3 from Julyova/module4-task1
2 parents 38f54ab + d7a12ec commit a5ee1ec

2 files changed

Lines changed: 94 additions & 1 deletion

File tree

index.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
<link rel="stylesheet" href="css/style.css">
99
<link rel="shortcut icon" href="favicon.ico" type="image/x-icon">
1010
<title>Кекстаграм</title>
11-
<script src="scripts/index.js" defer></script>
11+
<script src="js/main.js" defer></script>
1212
</head>
1313

1414
<body>

js/main.js

Lines changed: 93 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,93 @@
1+
/* eslint-disable no-console */
2+
3+
const getRandomInteger = (min, max) => {
4+
const lower = Math.ceil(Math.min(min, max));
5+
const upper = Math.floor(Math.max(min, max));
6+
return Math.floor(Math.random() * (upper - lower + 1) + lower);
7+
};
8+
9+
const MESSAGES = [
10+
'Всё отлично!',
11+
'В целом всё неплохо. Но не всё.',
12+
'Когда вы делаете фотографию, хорошо бы убирать палец из кадра. В конце концов это просто непрофессионально.',
13+
'Моя бабушка случайно чихнула с фотоаппаратом в руках и у неё получилась фотография лучше.',
14+
'Я поскользнулся на банановой кожуре и уронил фотоаппарат на кота и у меня получилась фотография лучше.',
15+
'Лица у людей на фотке перекошены, как будто их избивают. Как можно было поймать такой неудачный момент?!',
16+
];
17+
18+
const NAMES = ['Артём', 'Мария', 'Иван', 'Анна', 'Дмитрий', 'Елена', 'Сергей', 'Ольга'];
19+
20+
const DESCRIPTIONS = [
21+
'Отличный день!',
22+
'Прекрасный вид',
23+
'Незабываемый момент',
24+
'Лучший отпуск',
25+
'Море и солнце',
26+
'С друзьями весело',
27+
'Природа прекрасна',
28+
'Городские джунгли',
29+
];
30+
31+
const PHOTOS_COUNT = 25;
32+
const MIN_LIKES = 15;
33+
const MAX_LIKES = 200;
34+
const MIN_COMMENTS = 0;
35+
const MAX_COMMENTS = 30;
36+
const AVATAR_COUNT = 6;
37+
38+
let commentId = 0;
39+
40+
const createMessage = () => {
41+
const sentenceCount = getRandomInteger(1, 2);
42+
const messages = [];
43+
44+
for (let i = 0; i < sentenceCount; i++) {
45+
messages.push(MESSAGES[getRandomInteger(0, MESSAGES.length - 1)]);
46+
}
47+
48+
return messages.join(' ');
49+
};
50+
51+
const createComment = () => {
52+
commentId++;
53+
return {
54+
id: commentId,
55+
avatar: `img/avatar-${getRandomInteger(1, AVATAR_COUNT)}.svg`,
56+
message: createMessage(),
57+
name: NAMES[getRandomInteger(0, NAMES.length - 1)],
58+
};
59+
};
60+
61+
const createComments = () => {
62+
const commentsCount = getRandomInteger(MIN_COMMENTS, MAX_COMMENTS);
63+
const comments = [];
64+
65+
for (let i = 0; i < commentsCount; i++) {
66+
comments.push(createComment());
67+
}
68+
69+
return comments;
70+
};
71+
72+
const createPhoto = (index) => ({
73+
id: index,
74+
url: `photos/${index}.jpg`,
75+
description: DESCRIPTIONS[getRandomInteger(0, DESCRIPTIONS.length - 1)],
76+
likes: getRandomInteger(MIN_LIKES, MAX_LIKES),
77+
comments: createComments(),
78+
});
79+
80+
const createPhotos = () => {
81+
const result = [];
82+
83+
for (let i = 1; i <= PHOTOS_COUNT; i++) {
84+
result.push(createPhoto(i));
85+
}
86+
87+
return result;
88+
};
89+
90+
const photos = createPhotos();
91+
92+
93+
console.log(photos);

0 commit comments

Comments
 (0)