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주차] 신동현 미션 제출합니다 #9

Open
wants to merge 10 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
8 changes: 4 additions & 4 deletions index.html
Original file line number Diff line number Diff line change
Expand Up @@ -14,19 +14,19 @@
<div class = "round Yellow" ></div>
<div class = "round Green " ></div>
</div>
<h1>Todo List</h1>
<h1> ✏️ Todo List </h1>
<div class ="todoInput">
<input type = "text" id="inputTodo" placeholder="📍 Enter your to-do">

Choose a reason for hiding this comment

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

엔터를 쳤을 때, todolist에 반영이 안되어서 해당 input의 placeholder 텍스트를 바꾸어도 좋을 것 같아요!

<button class ="addBtn"> + </button>
<div class ="addBtn"> </div>
Copy link

Choose a reason for hiding this comment

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

div로 버튼을 표현해도 아무런 문제가 없지만, 나중에 SEO(Search Engine Optimization)을 위해, 혹은 여러 사람들과의 협업을 위해 태그를 사용해보는 것도 좋을 것 같아요~~

Copy link
Author

Choose a reason for hiding this comment

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

오 협업시에는 그렇겠네요! 앞으로 태그를 더 활용해봐야겠어요! 꿀팁 감사합니다 😆

</div>

<div class = "todoContainer">
<h2>List To Do</h2>
<h2>List To Do : <span id="todoCount">0</span></h2>
<div id = "todoList"></div>
</div>

<div class = "doneContainer">
<h2>List Done</h2>
<h2>List Done : <span id="doneCount">0</span> </h2>
<div id = "doneList"></div>
</div>

Expand Down
32 changes: 24 additions & 8 deletions script.js
Original file line number Diff line number Diff line change
@@ -1,37 +1,52 @@
const inputTodo = document.querySelector("#inputTodo");
const todoItems = document.querySelector("#todoList");
const doneList = document.querySelector("#doneList");
const doneArray = document.querySelectorAll("#doneList .todoItem");
const addBtn = document.querySelector(".addBtn");
const todoTextArray = [];
const doneTextArray = [];

//버튼 생성하는 함수
function createBtn(className, text) {
var button = document.createElement("div");

button.textContent = text;
button.setAttribute("class", "listBtns");
button.classList.add(className);
return button;
}

//array 삭제 후 저장하는 함수
function deleteData(arr, value) {
const index = arr.indexOf(value);
if (index !== -1) {
arr.splice(index, 1);
}
}

Choose a reason for hiding this comment

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

delete 함수 if문과 index 사용하셔서 깔끔하게 작성하신 것 같아요! 배워갑니당:)


//deleteBtn을 눌렀을때
function deleteItem() {
var removeBtns = document.querySelectorAll(".deleteBtn");
for (i = 0; i < removeBtns.length; i++) {
removeBtns[i].addEventListener("click", function () {
if (this.parentNode)
if (this.parentNode) {
this.parentNode.parentNode.removeChild(this.parentNode);
var del = this.parentNode.firstChild.textContent;

if (todoArr.includes(del))
deleteData(todoArr, this.parentNode.firstChild.textContent);
else deleteData(doneArr, this.parentNode.firstChild.textContent);
}
});
}
}

//doneBtn을 눌렀을때
function todoToDone() {
var doneBtns = document.querySelectorAll(".doneBtn");

for (var i = 0; i < doneBtns.length; i++) {
doneBtns[i].addEventListener("click", function () {
if (this.parentNode.parentNode)
if (this.parentNode.parentNode === todoItems) {
doneList.insertBefore(this.parentNode, doneList.childNodes[0]);
deleteData(todoArr, this.parentNode.firstChild.textContent);
doneArr.push(this.parentNode.firstChild.textContent);
}
});
}
}
Expand All @@ -45,9 +60,10 @@ function newTodo() {
newDiv.appendChild(doneBtn);
newDiv.appendChild(deleteBtn);
newDiv.setAttribute("class", "todoItem");

todoItems.insertBefore(newDiv, todoItems.childNodes[0]);
todoArr.push(inputTodo.value); // todoArr 에 값 저장해줌
inputTodo.value = "";

//deleteBtn 누르면 삭제 구현
deleteItem();

Expand Down
7 changes: 3 additions & 4 deletions style.css
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ body{
background-color: #f0f0f0;
margin: 10px;
height: 200px;
border-radius: 10px;
}
.header{
height: 15px;
Expand All @@ -38,18 +39,16 @@ body{
.Red {
background-color: #F5655B;
}

.round.Yellow {
.Yellow {
background-color: #F6BD3B;
}

.Green {
background-color: #43C645;
}

.todo_input{
.todoInput {
Copy link

Choose a reason for hiding this comment

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

class를 비롯해서, 네이밍을 할 때에는 의도나 역할이 확실히 드러나게 하는 것이 좋을 것 같아요! 저도 알고는 있지만 잘 지키고 있진 않지만요ㅎㅎ.. todoInput의 기능을 보면 input 과 버튼을 감싸고 있는 역할인 듯 한데, inputContainer와 같이 네이밍해보는 것도 좋을 것 같아요~~

Copy link
Author

Choose a reason for hiding this comment

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

네이밍 하는것도 정말 어려운것같아요.. ㅎㅎ 말씀해 주신대로 앞으로 네이밍 할때 규칙성 있게 지어야겠어요!!

Copy link
Member

Choose a reason for hiding this comment

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

대균님 코멘트에 더해서, 클래스 네이밍의 경우에는 kebab-case 가 일반적으로 많이 사용되는 것 같아요!
css 방법론 중 하나인 BEM 방식도 참고해보시면 도움 될 것 같습니다. 😄

width:100%;
background-color: whitesmoke;
height: 60px;
display: flex;
align-items: center;
Expand Down