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

Hw10 #919

Closed
wants to merge 3 commits into from
Closed

Hw10 #919

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
172 changes: 112 additions & 60 deletions index.html
Original file line number Diff line number Diff line change
@@ -1,71 +1,123 @@
<!DOCTYPE html>
<html>
<head>
<title>Проект "Комменты"</title>
<meta charset="utf-8" />
<link rel="stylesheet" href="styles.css" />
</head>

<body>
<div class="container">
<ul class="comments">
<li class="comment">
<div class="comment-header">
<div>Глеб Фокин</div>
<div>12.02.22 12:18</div>
</div>
<div class="comment-body">
<div class="comment-text">
Это будет первый комментарий на этой странице
</div>
</div>
<div class="comment-footer">
<div class="likes">
<span class="likes-counter">3</span>
<button class="like-button"></button>
</div>
<head>
<title>Проект "Комменты"</title>
<meta charset="utf-8" />
<link rel="stylesheet" href="styles.css" />
</head>

<body>
<div class="container">
<ul id="comments" class="comments">
<li class="comment">
<div class="comment-header">
<div>Глеб Фокин</div>
<div>12.02.22 12:18</div>
</div>
<div class="comment-body">
<div class="comment-text">
Это будет первый комментарий на этой странице
</div>
</li>
<li class="comment">
<div class="comment-header">
<div>Варвара Н.</div>
<div>13.02.22 19:22</div>
</div>
<div class="comment-footer">
<div class="likes">
<span class="likes-counter">3</span>
<button class="like-button"></button>
</div>
<div class="comment-body">
<div class="comment-text">
Мне нравится как оформлена эта страница! ❤
</div>
</div>
</li>
<li class="comment">
<div class="comment-header">
<div>Варвара Н.</div>
<div>13.02.22 19:22</div>
</div>
<div class="comment-body">
<div class="comment-text">
Мне нравится как оформлена эта страница! ❤
</div>
<div class="comment-footer">
<div class="likes">
<span class="likes-counter">75</span>
<button class="like-button -active-like"></button>
</div>
</div>
<div class="comment-footer">
<div class="likes">
<span class="likes-counter">75</span>
<button class="like-button -active-like"></button>
</div>
</li>
</ul>
<div class="add-form">
<input
type="text"
class="add-form-name"
placeholder="Введите ваше имя"
/>
<textarea
type="textarea"
class="add-form-text"
placeholder="Введите ваш коментарий"
rows="4"
></textarea>
<div class="add-form-row">
<button class="add-form-button">Написать</button>
</div>
</li>
</ul>
<div class="add-form">
<input id="add-form-name" type="text" class="add-form-name" placeholder="Введите ваше имя" />
<textarea id="add-form-text" type="textarea" class="add-form-text" placeholder="Введите ваш коментарий"
rows="4"></textarea>
<div class="add-form-row">
<button id="add-form-button" class="add-form-button">Написать</button>
</div>
</div>
</body>
</div>
</body>

<script>
"use strict";
const buttonEl = document.getElementById("add-form-button");
const commentsEl = document.getElementById("comments");
const nameInputEl = document.getElementById("add-form-name");
const textInputEl = document.getElementById("add-form-text");
const likeButtonEls = document.querySelectorAll(".like-button");


const currentDate = new Date().toLocaleDateString('default', { day: '2-digit', month: '2-digit', year: '2-digit' })
+ " " + new Date().toLocaleTimeString().slice(0, -3);

const comments = [
{
name: 'Глеб Фокин',
date: '12.02.22 12:18',
text: 'Это будет первый комментарий на этой странице',
isLiker: false,
likeCount: 3,
},

{
name: 'Варвара Н.',
date: '13.02.22 19:22',
text: 'Мне нравится как оформлена эта страница! ❤',
isLiker: true,
likeCount: 75,
}
];

function renderComments() {
li
}

buttonEl.addEventListener('click', () => {
if (nameInputEl.value === "") {
nameInputEl.classList.add("error");
return;
} else {
nameInputEl.classList.remove("error");
}
if (textInputEl.value === "") {
textInputEl.classList.add("error");
return;
} else {
textInputEl.classList.remove("error");
};

comments.push(
{
name: nameInputEl.value,
date: currentDate,
text: textInputEl.value,
isLiker: false,
likeCount: 0,
});

nameInputEl.value = '';
textInputEl.value = '';
});

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

<script>
"use strict";
// Код писать здесь
console.log("It works!");
</script>
</html>
</html>
6 changes: 5 additions & 1 deletion styles.css
Original file line number Diff line number Diff line change
Expand Up @@ -134,4 +134,8 @@ body {

.add-form-button:hover {
opacity: 0.9;
}
}

.error {
background-color: red;
}
Loading