Skip to content

Commit 12451de

Browse files
author
Юлия Перелыгина
committed
добавляет функции для создания массива
1 parent 6597fbe commit 12451de

2 files changed

Lines changed: 103 additions & 7 deletions

File tree

index.html

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,14 @@
11
<!DOCTYPE html>
22
<html lang="ru">
3+
34
<head>
45
<meta charset="utf-8">
56
<meta name="viewport" content="width=device-width,initial-scale=1">
67
<link rel="stylesheet" href="css/normalize.css">
78
<link rel="stylesheet" href="css/style.css">
89
<link rel="shortcut icon" href="favicon.ico" type="image/x-icon">
910
<title>Кекстаграм</title>
11+
<script src="js/main.js" defer></script>
1012
</head>
1113

1214
<body>
@@ -162,7 +164,7 @@ <h2 class="big-picture__title visually-hidden">Просмотр фотогра
162164
</li>
163165
<li class="social__comment">
164166
<img class="social__picture" src="img/avatar-3.svg" alt="Аватар комментатора фотографии" width="35" height="35">
165-
<p class="social__text">Да это фоташоп!!!!!!!!</p>
167+
<p class="social__text">Да это фоташоп!!!!!!!!</p>
166168
</li>
167169
</ul>
168170

@@ -227,12 +229,13 @@ <h2 class="success__title">Изображение успешно загруже
227229
</section>
228230
</template>
229231

230-
<!-- Сообщение с ошибкой загрузки изображений от других пользователей -->
231-
<template id="data-error">
232-
<section class="data-error">
233-
<h2 class="data-error__title">Не удалось загрузить данные</h2>
234-
</section>
235-
</template>
232+
<!-- Сообщение с ошибкой загрузки изображений от других пользователей -->
233+
<template id="data-error">
234+
<section class="data-error">
235+
<h2 class="data-error__title">Не удалось загрузить данные</h2>
236+
</section>
237+
</template>
236238

237239
</body>
240+
238241
</html>

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)