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

[1주차] 박지수 미션 제출합니다. #11

Open
wants to merge 6 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 1 commit
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
3 changes: 1 addition & 2 deletions jsomnium/todo.html
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@ <h1>✔ To Do</h1>
<section class="todo-container">
<div class="todo-header">
<h2>오늘 할 일</h2>
<div>9월 7일 토요일 (날짜)</div>
<p id="currentDate"></p>
</div>

Expand All @@ -32,7 +31,7 @@ <h2>오늘 할 일</h2>
</section>
</main>

<script src="script.js"></script>
<script src="todo.js"></script>
</body>

</html>
31 changes: 31 additions & 0 deletions jsomnium/todo.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
// 날짜 출력
const currentDateElement = document.getElementById('currentDate');
const today = new Date();
const days = ['일', '월', '화', '수', '목', '금', '토'];
currentDateElement.textContent = `${today.getMonth() + 1}월 ${today.getDate()}일 ${days[today.getDay()]}요일`;

// 할 일 추가 기능
const addButton = document.getElementById('addButton');
const newTodoInput = document.getElementById('newTodo');
const todoList = document.getElementById('todoList');

addButton.addEventListener('click', addTodo);

function addTodo() {
const newTodo = newTodoInput.value.trim();
if (newTodo) {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

할일 내용이 없을 때 사용자에게 이에 대한 피드백이 없어서 UX적으로 조금 어색할 수 있을 것 같아요!
할일 없을 때, 버튼의 색을 다르게 한다거나 메시지를 띄워서 양식이 invalid함을 사용자에게 알릴 수 있으면 좋을 것 같아요!

const todoItem = document.createElement('li');
const textNode = document.createTextNode(newTodo);
const removeButton = document.createElement('button');
removeButton.textContent = '삭제';
removeButton.addEventListener('click', () => {
todoList.removeChild(todoItem);
});

todoItem.appendChild(textNode);
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

appendchild()를 여러번 사용하면, dom 조작이 여러번 발생할 수 있어 성능에 그리 좋지 않다고 해요!
다른 분들 코드리뷰에도 언급한 내용이니 dom 조작을 최적화하는 documnet fragment 객체와 리플로우 리페인팅에 대해서 살펴보시면 좋을 것 같아요!

#4 (comment)

todoItem.appendChild(removeButton);
todoList.appendChild(todoItem);

newTodoInput.value = '';
}
}