-
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주차] 이규호 미션 제출합니다. #8
base: master
Are you sure you want to change the base?
Changes from 1 commit
3002b55
433ba75
bd2e97d
e3f911c
7db23fe
25bc6c0
0200119
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 |
---|---|---|
@@ -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(); | ||
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}`;//두자릿수 유지를 위한 삼항연산자 | ||
} | ||
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. 중첩된 삼항 연산자 보다는 padStart 라는 함수를 활용하면 좀 더 간편하게 코드를 작성하실 수 있을거 같아요!! https://developer.mozilla.org/ko/docs/Web/JavaScript/Reference/Global_Objects/String/padStart 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. padStart 함수를 활용해서 작성하는게 삼항연산자보다 훨씬 코드가 깔끔하겠네요!! 다른 기능에서도 유용하게 사용할 것 같아요 ㅎㅎ 감사합니다 😊 |
||
|
||
function init(){ | ||
clock(); | ||
setInterval(clock,1000); | ||
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. 초단위의 rerendering을 위해 setInterval 사용하신 점 인상깊네요 👍 |
||
} | ||
|
||
init(); |
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.
date객체에서 getMonth를 통해 달을 가져올 때
을 통해 변수의 초기값 자체를 고친 값으로 수정해주면 변수를 재사용할 때 좀더 용이하지 않을까 싶네요!