дублирование логики item.classList.add('popup_opened') необходимо вынести в отдельные функции, чтобы было только одно место для внесения изменений

function openPopupForm(item) {
    item.classList.add('popup_opened');
    formName.value = profileName.textContent;
    formParagraph.value = profileParagraph.textContent;
}

function openPopupImage(item, image) {
    item.classList.add('popup_opened');
    imagePopup.src = image.src;
    imagePopup.alt = image.alt;
    captionPopup.textContent = image.alt;
}

Ответы (1 шт):

Автор решения: Алис

Я так понимаю вам просто нужна функция которая вешала бы класс popup_opened на передаваемый в неё элемент?

В таком случае:

function openPopupForm(item) {
    addClassOpened (item);
    formName.value = profileName.textContent;
    formParagraph.value = profileParagraph.textContent;
}

function openPopupImage(item, image) {
    addClassOpened (item);
    imagePopup.src = image.src;
    imagePopup.alt = image.alt;
    captionPopup.textContent = image.alt;
}

function addClassOpened (el) {
    el.classList.add('popup_opened');
}

Однако польза такой функции сомнительна, так что предлагаю чтобы её можно было использовать ещё и для закрытия:

function openPopupForm(item) {
    toggleClass (item);
    formName.value = profileName.textContent;
    formParagraph.value = profileParagraph.textContent;
}

function openPopupImage(item, image) {
    toggleClass (item);
    imagePopup.src = image.src;
    imagePopup.alt = image.alt;
    captionPopup.textContent = image.alt;
}

function toggleClass (el) {
    el.classList.toggle('popup_opened');
}
→ Ссылка