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주차] 이규호 미션 제출합니다. #8

Open
wants to merge 7 commits into
base: master
Choose a base branch
from
Open
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
27 changes: 27 additions & 0 deletions script.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
const addTodo = document.getElementById('addTodo');
const plusButton = document.getElementById('plusButton');

plusButton.addEventListener('click',()=>{
console.log("clicked");
})

// clock 출력
const clockTarget = document.getElementById("clock-js");
function clock(){
const date = new Date();
const month = date.getMonth();
Copy link
Member

Choose a reason for hiding this comment

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

date객체에서 getMonth를 통해 달을 가져올 때

Suggested change
const month = date.getMonth();
const month = date.getMonth() + 1;

을 통해 변수의 초기값 자체를 고친 값으로 수정해주면 변수를 재사용할 때 좀더 용이하지 않을까 싶네요!

const clockDate = date.getDate();
const day = date.getDay();
const week = ['일','월','화','수','목','금','토'];
const hours = date.getHours();
const minutes = date.getMinutes();
const seconds = date.getSeconds();
clockTarget.innerText=`${month+1}/${clockDate} ${week[day]}요일 ${hours < 10 ? `0${hours}` : hours}:${minutes < 10 ? `0${minutes}` : minutes}:${seconds < 10 ? `0${seconds}` : seconds}`;//두자릿수 유지를 위한 삼항연산자
}
Copy link

Choose a reason for hiding this comment

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

중첩된 삼항 연산자 보다는 padStart 라는 함수를 활용하면 좀 더 간편하게 코드를 작성하실 수 있을거 같아요!!

https://developer.mozilla.org/ko/docs/Web/JavaScript/Reference/Global_Objects/String/padStart

Copy link
Author

Choose a reason for hiding this comment

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

padStart 함수를 활용해서 작성하는게 삼항연산자보다 훨씬 코드가 깔끔하겠네요!! 다른 기능에서도 유용하게 사용할 것 같아요 ㅎㅎ 감사합니다 😊


function init(){
clock();
setInterval(clock,1000);
Copy link
Member

Choose a reason for hiding this comment

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

초단위의 rerendering을 위해 setInterval 사용하신 점 인상깊네요 👍

}

init();