From 192c75dfe4757ac978e30fc04afc938296e42f4f Mon Sep 17 00:00:00 2001 From: Aleksandr Anokhin Date: Wed, 9 Oct 2024 19:21:28 +0300 Subject: [PATCH] =?UTF-8?q?=D1=80=D0=B0=D0=B7=D0=B4=D0=B5=D0=BB=D0=B8?= =?UTF-8?q?=D0=BB=20=D1=84=D1=83=D0=BD=D0=BA=D1=86=D0=B8=D1=8E=20=D1=81?= =?UTF-8?q?=D0=BE=D0=B7=D0=B4=D0=B0=D0=BD=D0=B8=D1=8F=20=D0=BC=D0=B0=D1=81?= =?UTF-8?q?=D1=81=D0=B8=D0=B2=D0=BE=D0=B2=20=D0=BD=D0=B0=20=D0=BC=D0=BE?= =?UTF-8?q?=D0=B4=D1=83=D0=BB=D0=B8?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- index.html | 2 +- js/main.js | 50 ++------------------------------------------------ js/script.js | 28 ++++++++++++++++++++++++++++ js/util.js | 26 ++++++++++++++++++++++++++ 4 files changed, 57 insertions(+), 49 deletions(-) create mode 100644 js/script.js create mode 100644 js/util.js diff --git a/index.html b/index.html index 579e039..2816cc2 100644 --- a/index.html +++ b/index.html @@ -7,7 +7,7 @@ - + Кекстаграм diff --git a/js/main.js b/js/main.js index bab4c55..420ea9e 100644 --- a/js/main.js +++ b/js/main.js @@ -1,52 +1,6 @@ -const PHOTO_COUNT = 25; +import {PHOTO_COUNT, DESCRIPTIONS} from './util.js'; -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), -}); +import {getRandomArrayElement, getRandomIntInclusive, uniquePhoto, uniqueId, createComments} from './script.js'; const createPhoto = () => { diff --git a/js/script.js b/js/script.js new file mode 100644 index 0000000..84754f6 --- /dev/null +++ b/js/script.js @@ -0,0 +1,28 @@ +import {MESSAGES, NAMES} from './util.js'; + +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), +}); + +export {getRandomArrayElement, getRandomIntInclusive, uniquePhoto, uniqueId, createComments}; diff --git a/js/util.js b/js/util.js new file mode 100644 index 0000000..97ec59a --- /dev/null +++ b/js/util.js @@ -0,0 +1,26 @@ +const PHOTO_COUNT = 25; + +const MESSAGES = [ + 'Всё отлично!', + 'В целом всё неплохо. Но не всё.', + 'У моего кота получилась фотография лучше.', +]; + +const DESCRIPTIONS = [ + 'Утро!', + 'Котик', + 'Солнышко', + 'Красивое фото', + 'Что-то новенькое', +]; + +const NAMES = [ + 'Иван', + 'Себастьян', + 'Мария', + 'Кристоф', + 'Виктор', + 'Юлия', +]; + +export {PHOTO_COUNT, MESSAGES, DESCRIPTIONS, NAMES};