Skip to content

Commit

Permalink
Merge pull request #6 from dennyhappysomuch/module7-task1
Browse files Browse the repository at this point in the history
Module7 task1
  • Loading branch information
kvakazyambra authored Dec 26, 2024
2 parents 2939564 + 27db2b0 commit 4996415
Show file tree
Hide file tree
Showing 4 changed files with 32 additions and 3 deletions.
2 changes: 1 addition & 1 deletion js/data.js
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ function describePhoto() {
}

function createArrayPhoto() {
Array.from({length: 25}, describePhoto);
return Array.from({length: 25}, describePhoto);
}

export {createArrayPhoto};
4 changes: 3 additions & 1 deletion js/main.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
import './utils.js';
import './pictures.js';
import {createArrayPhoto} from './data.js';
import { renderPosts } from './pictures.js';

createArrayPhoto();
renderPosts(createArrayPhoto());
20 changes: 20 additions & 0 deletions js/pictures.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
const pictures = document.querySelector('.pictures');
const picturesTemplate = document.querySelector('#picture').content.querySelector('.picture');
const fragment = document.createDocumentFragment();

function renderPosts (posts) {
posts.forEach((picture) => {
const clonedPicture = picturesTemplate.cloneNode(true);

clonedPicture.querySelector('.picture__img').src = picture.url;
clonedPicture.querySelector('.picture__img').alt = picture.description;
clonedPicture.querySelector('.picture__likes').textContent = picture.likes;
clonedPicture.querySelector('.picture__comments').textContent = picture.comments.length;

fragment.appendChild(clonedPicture);
});

pictures.appendChild(fragment);
}

export {renderPosts};
9 changes: 8 additions & 1 deletion js/utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,17 @@ function createRandomIdFromRangeGenerator (min, max) {

return function () {
let currentValue = getRandomInteger(min, max);
if (previousValues.includes(currentValue)) {

if (previousValues.length >= (max - min + 1)) {
return null;
}

while (previousValues.includes(currentValue)) {
currentValue = getRandomInteger(min, max);
}

previousValues.push(currentValue);

return currentValue;
};
}
Expand Down

0 comments on commit 4996415

Please sign in to comment.