Skip to content

Commit

Permalink
Merge pull request #6 from skyfxllen/module7-task1
Browse files Browse the repository at this point in the history
  • Loading branch information
keksobot authored Dec 10, 2024
2 parents 1ab907f + da998ba commit b231d5f
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 8 deletions.
10 changes: 5 additions & 5 deletions js/data.js
Original file line number Diff line number Diff line change
@@ -1,18 +1,18 @@
import {getARandomNumber} from './utils.js';

Check warning on line 1 in js/data.js

View workflow job for this annotation

GitHub Actions / Check

Strings must use doublequote
import {names, comments, descriptions} from './constants.js';

Check warning on line 2 in js/data.js

View workflow job for this annotation

GitHub Actions / Check

Strings must use doublequote
export function createArrayOfPhotos(){
const photos = [];
export function createArrayOfPictures(){
const pictures = [];
for (let i = 0; i < 25; i++){
const newPhoto = {
const newPicture = {
id : i + 1,
url: `photos/${i + 1}.jpg`,
description: descriptions[getARandomNumber(descriptions.length)],
likes: getARandomNumber(200, 15),
comments: createArrayOfComments(),
};
photos.push(newPhoto);
pictures.push(newPicture);
}
return photos;
return pictures;
}

export function createArrayOfComments(){
Expand Down
5 changes: 2 additions & 3 deletions js/main.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
import {createArrayOfPhotos} from './data.js';

createArrayOfPhotos();
import {generatePictures} from './pictures.js';

generatePictures();
24 changes: 24 additions & 0 deletions js/pictures.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
import {createArrayOfPictures} from "./data.js";

export function generatePictures(){
const picturesContainer = document.querySelector(".pictures");
const pictureTemplate = document.querySelector("#picture").content.querySelector(".picture");
const pictureFragment = document.createDocumentFragment();

const pictures = createArrayOfPictures();

pictures.forEach((photo) => {
const {url, description, comments, likes} = photo;
const picture = pictureTemplate.cloneNode(true);

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

pictureFragment.append(picture);
});

picturesContainer.append(pictureFragment);
}

0 comments on commit b231d5f

Please sign in to comment.