728x90
생년월일을 입력받아 만 나이 계산하는 함수
//생년월일을 입력받아 만 나이 계산하는 함수
function getAge(dateOfBirth) {
// 코드 작성
let today = new Date();
let birth = new Date(dateOfBirth);
console.log(today)
console.log(birth)
let year = today.getFullYear() - birth.getFullYear();
let birthdayPassed =
today.getMonth() - birth.getMonth() >= 0 &&
today.getDate() - birth.getDate() >= 0;
console.log(birthdayPassed)
if (birthdayPassed) {
return year;
}
return year - 1;
}
console.log(getAge('1990-01-01 16:27:00'));
// Print: 32
20세 미만 출력하는 함수
//20세 미만 출력하는 함수 작성
function getChildren(persons) {
return persons.filter((person)=>{
return person.age < 20;
})
}
const allPersons = [
{ name: "John Kim", age: 10 },
{ name: "Jane Doe", age: 20 },
{ name: "Fred Kang", age: 13 },
{ name: "Chris Doe", age: 39 },
{ name: "Layla Park", age: 19 },
];
console.log(getChildren(allPersons));
// Print: [
// {"name": "John Kim", "age": 10},
// {"name": "Fred Kang", "age": 13},
// {"name": "Layla Park", "age": 19},
// ]
728x90
'Sparta > 스파르타코딩 웹개발 종합반' 카테고리의 다른 글
Node.js - 02 - 미들웨어 (express.js) & Routing (0) | 2022.03.16 |
---|---|
Node.js - 02 - Express.js 세팅 (0) | 2022.03.16 |
Node.js 01 - 자바스크립트 정리 (0) | 2022.03.14 |
웹개발 종합반 프로젝트 - 06 뉴스크롤링(네이버뉴스) (0) | 2022.03.13 |
웹개발 종합반 프로젝트 - 05 진행상황&로그인&뉴스크롤링 (0) | 2022.03.13 |