-
Notifications
You must be signed in to change notification settings - Fork 10
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
base: master
Are you sure you want to change the base?
Changes from 1 commit
f9d344d
eed56d2
7786bda
877d2e2
89faf89
7e12519
5889c51
9352968
43a6a30
d36548e
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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"> | ||
<button class ="addBtn"> + </button> | ||
<div class ="addBtn"> ➕ </div> | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. div로 버튼을 표현해도 아무런 문제가 없지만, 나중에 SEO(Search Engine Optimization)을 위해, 혹은 여러 사람들과의 협업을 위해 태그를 사용해보는 것도 좋을 것 같아요~~ There was a problem hiding this comment. Choose a reason for hiding this commentThe 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> | ||
|
||
|
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); | ||
} | ||
} | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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); | ||
} | ||
}); | ||
} | ||
} | ||
|
@@ -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(); | ||
|
||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -20,6 +20,7 @@ body{ | |
background-color: #f0f0f0; | ||
margin: 10px; | ||
height: 200px; | ||
border-radius: 10px; | ||
} | ||
.header{ | ||
height: 15px; | ||
|
@@ -38,18 +39,16 @@ body{ | |
.Red { | ||
background-color: #F5655B; | ||
} | ||
|
||
.round.Yellow { | ||
.Yellow { | ||
background-color: #F6BD3B; | ||
} | ||
|
||
.Green { | ||
background-color: #43C645; | ||
} | ||
|
||
.todo_input{ | ||
.todoInput { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. class를 비롯해서, 네이밍을 할 때에는 의도나 역할이 확실히 드러나게 하는 것이 좋을 것 같아요! 저도 알고는 있지만 잘 지키고 있진 않지만요ㅎㅎ.. todoInput의 기능을 보면 input 과 버튼을 감싸고 있는 역할인 듯 한데, inputContainer와 같이 네이밍해보는 것도 좋을 것 같아요~~ There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 네이밍 하는것도 정말 어려운것같아요.. ㅎㅎ 말씀해 주신대로 앞으로 네이밍 할때 규칙성 있게 지어야겠어요!! There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 대균님 코멘트에 더해서, 클래스 네이밍의 경우에는 |
||
width:100%; | ||
background-color: whitesmoke; | ||
height: 60px; | ||
display: flex; | ||
align-items: center; | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
엔터를 쳤을 때, todolist에 반영이 안되어서 해당 input의 placeholder 텍스트를 바꾸어도 좋을 것 같아요!