Skip to content

Commit

Permalink
Merge pull request #3 from Aleksandr-Anokhin/module4-task1
Browse files Browse the repository at this point in the history
  • Loading branch information
keksobot authored Oct 9, 2024
2 parents 3fdb113 + 21419ba commit 9434491
Show file tree
Hide file tree
Showing 2 changed files with 68 additions and 0 deletions.
1 change: 1 addition & 0 deletions index.html
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
<link rel="stylesheet" href="css/style.css">
<link rel="shortcut icon" href="favicon.ico" type="image/x-icon">
<script src="/js/functions.js"></script>
<script src="/js/main.js"></script>
<title>Кекстаграм</title>
</head>

Expand Down
67 changes: 67 additions & 0 deletions js/main.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
const PHOTO_COUNT = 25;

const MESSAGES = [
'Всё отлично!',
'В целом всё неплохо. Но не всё.',
'У моего кота получилась фотография лучше.',
];

const DESCRIPTIONS = [
'Утро!',
'Котик',
'Солнышко',
'Красивое фото',
'Что-то новенькое',
];

const NAMES = [
'Иван',
'Себастьян',
'Мария',
'Кристоф',
'Виктор',
'Юлия',
];

const getRandomIntInclusive = (min, max) => {
min = Math.ceil(min);
max = Math.floor(max);
return Math.floor(Math.random() * (max - min + 1) + min);
};

const counter = () => {
let sum = 0;
return () => {
sum = sum + 1;
return sum;
};
};

const uniquePhoto = counter();
const uniqueId = counter();
const getRandomArrayElement = (elements) => elements[getRandomIntInclusive(0, elements.length - 1)];

const createComments = () => ({
id: getRandomIntInclusive(0, 30),
avatar: `img/avatar-${getRandomIntInclusive(1, 6)}.svg`,
message: getRandomArrayElement(MESSAGES),
name: getRandomArrayElement(NAMES),
});


const createPhoto = () => {
const id = uniqueId();
return {
id: id,
url: `photos/${uniquePhoto()}.jpg`,
description: getRandomArrayElement(DESCRIPTIONS),
likes: getRandomIntInclusive(15, 200),
comments: Array.from({ length: getRandomIntInclusive(0, 30) }, createComments),
};
};

const createPhotos = () => Array.from({ length: PHOTO_COUNT }, createPhoto);

console.log(
createPhotos()
);

0 comments on commit 9434491

Please sign in to comment.