Skip to content

Commit

Permalink
Merge pull request #4 from Aleksandr-Anokhin/module5-task1
Browse files Browse the repository at this point in the history
  • Loading branch information
keksobot authored Oct 11, 2024
2 parents 9434491 + 192c75d commit 612b4f1
Show file tree
Hide file tree
Showing 4 changed files with 57 additions and 49 deletions.
2 changes: 1 addition & 1 deletion index.html
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +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>
<script type="module" src="/js/main.js"></script>
<title>Кекстаграм</title>
</head>

Expand Down
50 changes: 2 additions & 48 deletions js/main.js
Original file line number Diff line number Diff line change
@@ -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 = () => {
Expand Down
28 changes: 28 additions & 0 deletions js/script.js
Original file line number Diff line number Diff line change
@@ -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};
26 changes: 26 additions & 0 deletions js/util.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
const PHOTO_COUNT = 25;

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

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

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

export {PHOTO_COUNT, MESSAGES, DESCRIPTIONS, NAMES};

0 comments on commit 612b4f1

Please sign in to comment.