Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Модуляция #4

Merged
merged 3 commits into from
Nov 21, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion index.html
Original file line number Diff line number Diff line change
Expand Up @@ -233,7 +233,7 @@ <h2 class="success__title">Изображение успешно загруже
<h2 class="data-error__title">Не удалось загрузить данные</h2>
</section>
</template>
<script src="./js/main.js">
<script type="module" src="./js/main.js">
</script>
</body>
</html>
76 changes: 76 additions & 0 deletions js/data.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,76 @@
import {getRandomInteger} from './util.js'

Check failure on line 1 in js/data.js

View workflow job for this annotation

GitHub Actions / Check

Missing semicolon

const COUNT_PHOTO = 25;
const MIN_LIKES = 15;
const MAX_LIKES = 200;
const DESCRIPTIONS = [
'Утро',
'Котик',
'Луна',
'Молния',
'Море',
'Горы',
'Компьютер',
'Солнышко',
'Велосипед',
'Машина',
]

Check failure on line 17 in js/data.js

View workflow job for this annotation

GitHub Actions / Check

Missing semicolon
const COUNT_COMMENT = 30;
const MIN_AVATAR = 1;
const MAX_AVATAR = 6;
const MESSAGE = [
'Всё отлично!',
'В целом всё неплохо. Но не всё.',
'Когда вы делаете фотографию, хорошо бы убирать палец из кадра. В конце концов это просто непрофессионально.',
'Моя бабушка случайно чихнула с фотоаппаратом в руках и у неё получилась фотография лучше.',
'Я поскользнулся на банановой кожуре и уронил фотоаппарат на кота и у меня получилась фотография лучше.',
'Лица у людей на фотке перекошены, как будто их избивают. Как можно было поймать такой неудачный момент?!'
]

Check failure on line 28 in js/data.js

View workflow job for this annotation

GitHub Actions / Check

Missing semicolon

const NAME = [
'Артем',
'Настя',
'Михаил',
'Анна',
'Павел',
'Елена',
'Костя',
'Сергей'
]

Check failure on line 39 in js/data.js

View workflow job for this annotation

GitHub Actions / Check

Missing semicolon

const getComments = () => {
const comments = [];
const countComments = getRandomInteger(0, COUNT_COMMENT);
for (let i = 1; i <= countComments; i++) {
comments.push({
id: getRandomInteger(0, 1000),
avatar: `img/avatar-${getRandomInteger(MIN_AVATAR, MAX_AVATAR)}.svg`,
message: MESSAGE[getRandomInteger(0, MESSAGE.length - 1)],
name: NAME[getRandomInteger(0, NAME.length - 1)]
}
)

Check failure on line 51 in js/data.js

View workflow job for this annotation

GitHub Actions / Check

Missing semicolon
}
return comments

Check failure on line 53 in js/data.js

View workflow job for this annotation

GitHub Actions / Check

Missing semicolon
}

Check failure on line 54 in js/data.js

View workflow job for this annotation

GitHub Actions / Check

Missing semicolon


const getPhoto = (i) => {

Check failure on line 57 in js/data.js

View workflow job for this annotation

GitHub Actions / Check

Unexpected block statement surrounding arrow body; parenthesize the returned value and move it immediately after the `=>`
return {
id: i,
url: `photos/${i}.jpg`,
description: DESCRIPTIONS[getRandomInteger(0, DESCRIPTIONS.length - 1)],
likes: getRandomInteger(MIN_LIKES, MAX_LIKES),
comments: getComments()
}

Check failure on line 64 in js/data.js

View workflow job for this annotation

GitHub Actions / Check

Missing semicolon
}

Check failure on line 65 in js/data.js

View workflow job for this annotation

GitHub Actions / Check

Missing semicolon

const getData = () => {
const data = [];
for (let i = 1; i <= COUNT_PHOTO; i++) {
data.push(getPhoto(i))
}

return data;
}

export {getData};
21 changes: 20 additions & 1 deletion js/functions.js
Original file line number Diff line number Diff line change
Expand Up @@ -36,4 +36,23 @@ const cutNumber = (text) => {

//console.log(cutNumber('dhjlh4 hlfgh3 f7 j e8'))

// 4378
// 4378

// task 4

const MINUTES_IN_HOUR = 60;

const getTimePoint = (time) => {
const [hour, min] = time.split(':');
return hour * MINUTES_IN_HOUR + Number(min)
}

const checkMeeting = (start, end, startMeet, duringMeet) => {
const startPoint = getTimePoint(start);
const endPoint = getTimePoint(end);
const startMeetPoint = getTimePoint(startMeet);
const endMeetPoint = startMeetPoint + duringMeet;
return (startMeetPoint >= startPoint && startMeetPoint <= endPoint && endMeetPoint >= startPoint && endMeetPoint <= endPoint)
}

// console.log(checkMeeting('8:00', '18:00', '12:00', 90))
93 changes: 3 additions & 90 deletions js/main.js
Original file line number Diff line number Diff line change
@@ -1,92 +1,5 @@
const COUNT_PHOTO = 25;
const MIN_LIKES = 15;
const MAX_LIKES= 200;
const DESCRIPTIONS = [
'Утро',
'Котик',
'Луна',
'Молния',
'Море',
'Горы',
'Компьютер',
'Солнышко',
'Велосипед',
'Машина',
]
const COUNT_COMMENT = 30;
const MIN_AVATAR = 1;
const MAX_AVATAR = 6;
const MESSAGE = [
'Всё отлично!',
'В целом всё неплохо. Но не всё.',
'Когда вы делаете фотографию, хорошо бы убирать палец из кадра. В конце концов это просто непрофессионально.',
'Моя бабушка случайно чихнула с фотоаппаратом в руках и у неё получилась фотография лучше.',
'Я поскользнулся на банановой кожуре и уронил фотоаппарат на кота и у меня получилась фотография лучше.',
'Лица у людей на фотке перекошены, как будто их избивают. Как можно было поймать такой неудачный момент?!'
]
import {getData} from './data.js'

const NAME = [
'Артем',
'Настя',
'Михаил',
'Анна',
'Павел',
'Елена',
'Костя',
'Сергей'
]
const data = getData();

const getRandomInteger = (min, max) => {
const lower = Math.ceil(Math.min(Math.abs(min), Math.abs(max)));
const upper = Math.floor(Math.max(Math.abs(min), Math.abs(max)));
const result = Math.random() * (upper - lower + 1) + lower;

return Math.floor(result)
}


const getComment = (j) => {
return {
id: getRandomInteger(0,1000),
avatar: `img/avatar-${getRandomInteger(MIN_AVATAR, MAX_AVATAR)}.svg`,
message: MESSAGE[getRandomInteger(0, MESSAGE.length - 1)],
name: NAME[getRandomInteger(0, NAME.length - 1)]
}
}

const getComments = () => {
const comments = [];
const countComments = getRandomInteger(0, COUNT_COMMENT);
for(let i = 1; i<=countComments; i++) {
comments.push({
id: getRandomInteger(0,1000),
avatar: `img/avatar-${getRandomInteger(MIN_AVATAR, MAX_AVATAR)}.svg`,
message: MESSAGE[getRandomInteger(0, MESSAGE.length - 1)],
name: NAME[getRandomInteger(0, NAME.length - 1)]
}
)
}
return comments
}


const getPhoto = (i) => {
return {
id: i,
url: `photos/${i}.jpg`,
description: DESCRIPTIONS[getRandomInteger(0, DESCRIPTIONS.length - 1)],
likes: getRandomInteger(MIN_LIKES, MAX_LIKES),
comments: getComments()
}
}

const getData = () => {
const data = [];
for(let i = 1; i<=COUNT_PHOTO; i++) {
data.push(getPhoto(i))
}

return data;
}

console.log(getData());
console.log(data)
9 changes: 9 additions & 0 deletions js/util.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
const getRandomInteger = (min, max) => {
const lower = Math.ceil(Math.min(Math.abs(min), Math.abs(max)));
const upper = Math.floor(Math.max(Math.abs(min), Math.abs(max)));
const result = Math.random() * (upper - lower + 1) + lower;

return Math.floor(result)
}

export {getRandomInteger};
Loading