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주차] 김선영 미션 제출합니다. #2

Open
wants to merge 13 commits into
base: master
Choose a base branch
from
17 changes: 16 additions & 1 deletion index.html
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,22 @@
</head>

<body>
<div class="container"></div>
<div class="container">
<div class="box">
Copy link
Member

Choose a reason for hiding this comment

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

Semantic Tag에 대해 공부한 만큼 여기서도 div말고 적절한 Semantic Tag를 사용해보는 것은 어떨까요~?

<form id="todo-form">
<h2>☑️ 투두리스트 ☑️ </h2>
<input type="text" placeholder="할 일을 작성하세요" required maxlength="30"/>
</form>
</div>
<div class="box">
<h2>📝 할 일 목록 📝</h2>
<ul class="list" id="todo-list"></ul>
Copy link
Member

Choose a reason for hiding this comment

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

공통적인 부분은 class로 묶고 고유한 속성은 id로 따로 정의해서 재사용성을 높인 부분 너무 좋은 것 같아요!

</div>
<div class="box">
<h2>💙 완료 목록 💙</h2>
<ul class="list" id="done-list"></ul>
</div>
</div>
</body>
<script src="script.js"></script>
</html>
69 changes: 69 additions & 0 deletions script.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
const todoForm = document.getElementById("todo-form");
const todoInput = todoForm.querySelector("input");
const todoList = document.getElementById("todo-list");
const doneList = document.getElementById("done-list");

todoForm.addEventListener("submit", submitTodo);

function submitTodo(e) {
e.preventDefault();
createTodo(todoInput.value);
todoInput.value = "";
}

/*
코드 방식 어떤게 좋을까요.?.?
createTodo() 처럼 변수를 생성하고 해당 변수에 대해 작업을 작성하는게 좋을지,
completeTodo() 처럼 변수 생성을 한번에 하고 작업을 한번에 하는게 좋을지
궁금해서 올려요!
*/
Comment on lines +14 to +19
Copy link
Member

Choose a reason for hiding this comment

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

이미 아시겠지만 코드에는 정답이 없습니다! 자기만의 기준을 명확하게 세우고 코드를 구성한다면 그게 바로 좋은 방법 아닐까요☺️ 다만 제 생각을 조금 덧붙이자면 개인적으로는 createTodo()와 같이 변수를 선언하고 바로 작업을 진행하는 방법이 기능을 명확하게 표현하는 느낌이라 더 많이 사용하게 되는 것 같아요. 하지만 선언하게되는 변수가 일정 개수 이상 넘어가게되면 기능을 더 세분화해서 로직을 다른 함수로 빼는게 가장 깔끔할 것 같네요~!

Copy link
Author

Choose a reason for hiding this comment

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

@jhj2713 오오.. 사실 질문하면서도 많이 애매한 부분이라 소심하게 주석으로 질문했는데 이렇게 좋은 답변 주셔서 너무 감사합니다 💙

Copy link

Choose a reason for hiding this comment

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

저도 이 점 굉장히 궁금했는데 선영님이 고민하시고 효정님이 답변해주신 글 보니까 고민이 해결되었습니다! 앞으로도 좀 더 명확하고 좋은 코드를 위해 고민하겠습니다!


function createTodo(content) {
const todoSpan = document.createElement("span");
todoSpan.innerText = content;

const completeBtn = document.createElement("button");
completeBtn.innerText = "✅";
completeBtn.addEventListener("click", completeTodo);

const newTodoLi = document.createElement("li");
newTodoLi.append(todoSpan, completeBtn);

todoList.append(newTodoLi);
}

function completeTodo(e) {
const target = e.target.parentElement;

const doneLi = document.createElement("li");
const doneSpan = document.createElement("span");
const doneBtn = document.createElement("button");
const returnBtn = document.createElement("button");

doneSpan.innerText = target.querySelector("span").innerText;
Copy link
Member

Choose a reason for hiding this comment

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

저는 span 태그가 아직 익숙하지 않아서 다른 방법을 사용했는데, 선영님처럼 span 을 사용하면 조금 더 깔끔하게 코드를 작성할 수 있어 좋은 것 같습니다!


doneBtn.innerText = "❌";
doneBtn.addEventListener("click", deleteTodo);

returnBtn.innerText = "🆙";
returnBtn.addEventListener("click", returnTodo);

Copy link

Choose a reason for hiding this comment

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

저는 span을 클릭해서 todo 리스트로 옮기는 방식으로 했는데 returnBtn을 넣는게 사용자 입장에서는 더 명확한 기능일 것 같네요! 너무 좋은 방식 같습니다 🥰

doneLi.appendChild(doneSpan);
doneLi.appendChild(doneBtn);
doneLi.appendChild(returnBtn);
seondal marked this conversation as resolved.
Show resolved Hide resolved

doneList.append(doneLi);

target.remove();
}

function returnTodo(e) {
Copy link
Member

Choose a reason for hiding this comment

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

추가, 삭제하는 함수가 중복되는 부분이 없어 깔끔해 좋은 것 같습니다. e.target을 사용하여 깔끔하게 코드 작성할 수 있는 점 배우고 갑니다 ㅎㅎ 감사합니다

const value = e.target.parentElement.querySelector("span").innerText;
createTodo(value);

deleteTodo(e);
}
Comment on lines +60 to +65
Copy link
Member

Choose a reason for hiding this comment

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

returnTodo()에서 중복된 로직인 createTodo()deleteTodo()를 재사용하신 점 깔끔한 것 같아요👍


function deleteTodo(e) {
e.target.parentElement.remove();
}
Copy link

Choose a reason for hiding this comment

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

deleteTodo 함수를 이렇게 깔끔하게 적는 방법도 있군요! 저는 고민을 많이해서 쓸데없는 코드도 많이 적었는데 ... 배워갑니다!

73 changes: 73 additions & 0 deletions style.css
Original file line number Diff line number Diff line change
@@ -0,0 +1,73 @@
@font-face {
font-family: 'EarlyFontDiary';
src: url('https://cdn.jsdelivr.net/gh/projectnoonnu/noonfonts_220508@1.0/EarlyFontDiary.woff2') format('woff2');
font-weight: normal;
font-style: normal;
}

html, body {
font-family: 'EarlyFontDiary';
height: 100%;
display: flex;
align-items : center;
justify-content: center;
flex-direction: column;
padding: 20px;
overflow: hidden;
background-color: rgb(0, 70, 42);
}

.container {
display: flex;
flex-direction: column;
align-items: center;
background-color: whitesmoke;
width: 360px;
padding: 20px;
border-radius: 20px;
}

.box {
display: flex;
flex-direction: column;
width: 100%;
align-items: center;
padding-bottom: 20px;
border-bottom: 1px solid gray;
}

form {
width: 100%;
display: flex;
flex-direction: column;
align-items: center;
}

input {
box-sizing: border-box;
padding: 10px;
height: 50px;
width: 250px;
border: 1px solid lightgray;
border-radius: 10px;
box-shadow: none;
}

button {
border: 0;
background: none;
cursor: pointer;
}

.list {
display: flex;
flex-direction: column;
width: 80%;
height: 200px;
overflow: hidden auto;
}

#done-list {
text-decoration: line-through;
color: gray;
}