Skip to content
31 changes: 31 additions & 0 deletions practice/practice1.js
Original file line number Diff line number Diff line change
@@ -1 +1,32 @@
// Mission 1
const getInput = () => {
let firstInput = parseInt(prompt(" 첫번째 숫자를 입력하세요."));
let mark = prompt("기호를 입력하세요.");
let secondInput = parseInt(prompt(" 두번째 숫자를 입력하세요."));

return {firstInput, mark, secondInput};
}

const calculate = ({firstInput, mark, secondInput}) => {
let result;
switch(mark){
case '+':
result = firstInput+secondInput;
break;
case '-':
result = firstInput-secondInput;
break;
case '/':
result = firstInput/secondInput;
break;
case '*':
result = firstInput*secondInput;
break;
default:
alert('잘못된 기호입니다.')
return;
}
alert(`${firstInput} ${mark} ${secondInput} = ${result}`);
}

calculate(getInput());
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

하지만 1단계부터 4단계까지의 과정들이 좀 더 있었으면 좋았을 것 같아요!!

8 changes: 8 additions & 0 deletions practice/practice2.js
Original file line number Diff line number Diff line change
@@ -1 +1,9 @@
// Mission 2

//숫자의 크기, 짝수 홀수 여부를 판단하는 예제
const num = parseInt(prompt("숫자를 입력해주세요"));
const realValue = !!num;
const evenNum = num % 2;

console.log(realValue ? (num > 10 ? "숫자가 10보다 큼" : "숫자가 10 이하") : "숫자가 0");
console.log(!evenNum ? "짝수" : "홀수");
84 changes: 84 additions & 0 deletions todolist/component/todoblock.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,84 @@
class TodoBlock extends HTMLElement {
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

extends HTMLElement는 왜 하신건가요???

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

웹 컴포넌트를 연결하기 위해서 생성한 클래스입니다

밑의 두 블로그를 참고했습니다

static get observedAttributes() {
return ['title', 'date'];
}

constructor() {
super();
this.attachShadow({ mode: 'open' });
}

connectedCallback() {
this.render();
}

attributeChangedCallback(name, oldValue, newValue) {
this.render();
}

render() {
this.shadowRoot.innerHTML = `
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

shadowRoot는 뭔가요??

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

shadowRoot는 숨겨진 DOM트리라는 뜻으로
shadowRoot 안에서 만들어진 설정들이 외부의 설정에 영향을 안 받는다라는 특징이 있습니다

<style>
.list-block {
display: flex;
border-top: 1px solid #dedddd;
padding: 14px 12px;
max-width: 600px;
height : 60px;
box-sizing: border-box;
justify-content: space-between;
}
.text-content button {
height: 20px;
width: 20px;
padding: 0px;
border: 1px solid #d2d2d2;
border-radius: 100%;
background-color: white;
color:white;
cursor: pointer;
}

.text-content button:hover {
border: 1px solid #d2d2d2;
background-color: #ececec;
}

.text-content{
display: flex;
}

.text-content div {
margin-left: 8px;
}
.text-content h6 {
margin: 0;
font-size: 1em;
font-weight: 500;
}
.text-content p {
font-size: 0.8em;
margin-top: 2px;
color: #666;
}
.delete {
text-decoration: underline;
margin: auto 0px;
cursor: pointer;
}
</style>
<div class="todo-block list-block">
<div class="text-content">
<button onclick='successCheck(this)'></button>
<div>
<h6 onclick="editTodo(this)">${this.getAttribute('title') || '타이틀'}</h6>
<p>${this.getAttribute('date') || '날짜 000월'}</p>
</div>
</div>
<p class="delete" onclick="deleteTodo(event)">삭제</p>
</div>
`;
}
}

customElements.define('todo-block', TodoBlock);
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

이 코드에 대해 설명해주세요

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

customElements.define('생성할 태그명', 연결할클래스);

이런 구조이고 웹 컴포넌트를 정의하기 위해 사용했습니다

30 changes: 30 additions & 0 deletions todolist/index.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
<!-- TODO: 일정 추가, 삭제, 수정, 계획 성공 여부 -->

<!DOCTYPE html>
<html lang="ko">
<head>
<meta charset="UTF-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title>TODOLIST</title>
<link rel="stylesheet" href="style.css" />
</head>
<body>
<main>
<h1>TODOLIST</h1>
<section id="view-list">
<div id="todo-section"></div>
<button class="create-btn" onclick="isShowCreateTodo(this)">
+ 작업추가
</button>
<div class="create-todo" id="create-todo-div">
<label for="create-title-name">TODO: </label>
<input type="text" id="create-title-name" />
<button onclick="createTodo()">등록</button>
</div>
</section>
</main>

<script src="component/todoblock.js"></script>
<script src="script.js"></script>
</body>
</html>
58 changes: 58 additions & 0 deletions todolist/script.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
const todoSection = document.getElementById('todo-section');

/**
* 계획추가하기 함수
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

코드 설명 주석 정말 좋습니다~~

*/
function createTodo(){
const todo = document.getElementById('create-title-name');
if(!!todo.value){
const todoBlock = document.createElement('todo-block');
let today = new Date();

todoBlock.title = todo.value;
todoBlock.setAttribute('date', today.toLocaleString());;
todoSection.appendChild(todoBlock);

// createTodoDiv.classList.remove('show');

}
else{
alert("빈 내용은 추가할 수 없어요")
}
}

/**
* 계획성공여부
*/
function successCheck(element){
element.style.backgroundColor = '#ff701d';
element.style.borderColor = '#dc6e32';
element.innerHTML = `<svg width="14" height="14" viewBox="0 0 14 8" fill="none" xmlns="http://www.w3.org/2000/svg" style="transform: translateY(-2px);"><path d="M11 5L6 10L3 7" stroke="white" stroke-width="2" stroke-linecap="butt" stroke-linejoin="miter"/></svg>`;
}

let createTodoBtn = true;
const createTodoDiv = document.getElementById('create-todo-div');

/**
* 작업추가하기, 작업접기가 토글되면서 createTODO창이 토글
*/
function isShowCreateTodo(element){
createTodoDiv.style.display = 'flex';
element.innerText = createTodoBtn ? '- 작업접기' : '+ 작업추가';
createTodoDiv.classList.toggle('show', createTodoBtn);
createTodoBtn = !createTodoBtn;
}

/**
* 작업수정하기
*/
function editTodo(element){
element.innerText = prompt("변경할 내용을 적어주세요",element.innerText);
}

/*
* 작업삭제하기
*/
function deleteTodo(e){
e.target.parentElement.remove();
}
65 changes: 65 additions & 0 deletions todolist/style.css
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
* {
margin: 0px;
padding: 0px;
}

body {
width: 100vw;
height: 100vh;
background-color: #181717;
}

main {
margin: 0px auto;
max-width: 600px;
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

단위들을 통일시켜주세요!!

background-color: #fff;
min-height: 100vh;
padding: 50px;
}

.create-btn {
border: none;
background-color: #fff;
padding: 4px 10px;
border-radius: 10px;
color: #ff701d;
cursor: pointer !important;
}

.create-todo {
display: flex;
max-width: 230px;
margin-left: 10px;
padding: 8px 10px;
border: 1px solid #E3E3E3;
border-radius: 4px;
justify-content: space-evenly;
align-items: center;
opacity: 0;
transform: translateY(5px);
transition: opacity 0.1s ease-out;
}

#create-todo-div.show {
opacity: 1;
transform: translateY(0);
}

.create-todo > label {
font-size: 1em;
}

.create-todo > button {
border: none;
border-radius: 2px ;
background-color: #ff701d;
color: #fff;
padding: 5px;
line-height: 8px;
font-size: 8px;
box-sizing: border-box;
}

h1 {
padding-bottom: 10px;
}