Skip to content
Closed
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 .github/workflows/greetings.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,4 +12,4 @@ jobs:
- uses: superbrothers/close-pull-request@v3
with:
# Optional. Post a issue comment just before closing a pull request.
comment: "Привет! Сделай пожалуйста Pull Request в свой репозиторий, сейчас ты сделал PR в репозиторий Глеба. Посмотри в домашке, там на скриншоте нарисовано где выбрать свой репозиторий"
comment: "Привет! Сделай пожалуйста Pull Request в свой репозиторий, сейчас ты сделал PR в репозиторий Глеба. Посмотри в домашке, там на скриншоте нарисовано где выбрать свой репозиторий"
86 changes: 84 additions & 2 deletions index.html
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,89 @@

<script>
"use strict";
// Код писать здесь

const nameInput = document.querySelector('.add-form-name');
const textInput = document.querySelector('.add-form-text');
const addButton = document.querySelector('.add-form-button');
const commentsList = document.querySelector('.comments');

function getCurrentDateTime() {
const now = new Date();

const day = String(now.getDate()).padStart(2, '0');
const month = String(now.getMonth() + 1).padStart(2, '0');
const year = String(now.getFullYear()).slice(2);

const hours = String(now.getHours()).padStart(2, '0');
const minutes = String(now.getMinutes()).padStart(2, '0');

return `${day}.${month}.${year} ${hours}:${minutes}`;
}

function validateForm() {
const name = nameInput.value.trim();
const text = textInput.value.trim();

if (name === '' || text === '') {
alert('Пожалуйста, заполните и имя, и текст комментария');
return false;
}

return true;
}

function createComment(name, text) {
const currentDateTime = getCurrentDateTime();

const commentHTML = `
<li class="comment">
<div class="comment-header">
<div>${name}</div>
<div>${currentDateTime}</div>
</div>
<div class="comment-body">
<div class="comment-text">
${text}
</div>
</div>
<div class="comment-footer">
<div class="likes">
<span class="likes-counter">0</span>
<button class="like-button"></button>
</div>
</div>
</li>
`;

return commentHTML;
}

function addComment() {
if (!validateForm()) {
return;
}

const name = nameInput.value.trim();
const text = textInput.value.trim();

const newComment = createComment(name, text);

commentsList.innerHTML += newComment;

nameInput.value = '';
textInput.value = '';
}

addButton.addEventListener('click', addComment);

nameInput.addEventListener('input', function() {
console.log('Имя изменено');
});

textInput.addEventListener('input', function() {
console.log('Текст изменен');
});

console.log("It works!");
</script>
</html>
</html>
Loading