Math.random() : 0.1~0.9까지의 숫자를 임의대로 뽑아낼 수 있다. Math.floor() : 소숫점자리수 버리기
document.createElement를 통해 동적으로 HTML 태그를 생성할 수 있다.
document.태그명.appendChild를 통해 태그 위치에 자식태그를 추가할 수 있다.
function getClock(){
//console.log("hello");
const date = new Date();
const hours = String(date.getHours()).padStart(2,"0");
const minutes = String(date.getMinutes()).padStart(2,"0");
const seconds = String(date.getSeconds()).padStart(2,"0");
clock.innerText = `${hours}:${minutes}:${seconds}`;
}
date앞에 두자리를 채우기 위해 .padStart(자릿수, 채울문자)를 사용한다.
date는 숫자형이기 때문에 문자형으로 바꾸기 위해
String(date)로 감싸줘서 String형으로 변환
arr.filter(callback[, index[, array]])[, thisArg])
callback
각 요소를 시험할 함수, true 반환하면 요소 유지, false를 반환하면 버림
다음 세가지의 매개변수를 받음
element
처리할 요소
index(Optional)
처리할 요소의 인덱스
array(Optional)
filter를 호출한 배열
테스트를 통과한 요소로 이루어진 새로운 배열. 어떤 요소도 테스트를 통과하지 못했으면 빈 배열을 반환
function isBigEnough(value){
return value >= 10;
}
var filtered = [12, 5, 8, 130, 44].filter(isBigEnough);
// filtered는 [12, 130, 44]