성륜이는 오늘 항해99를 시작했다. 성격이 급한 성륜이는 항해 1일 차부터 언제 수료를 하게될 지 궁금하다.
항해 1일 차 날짜를 입력하면 98일 이후 항해를 수료하게 되는 날짜를 계산해주는 알고리즘을 만들어보자.
function solution(month, day) {
let result = "";
// 1. Convert date into month and day format
const originalDate = new Date(`${month}/${day}`);
console.log(originalDate);
// 2. Use setDate to add 99 days to the original date.
const resultDate = new Date(originalDate.setDate(originalDate.getDate() + 98));
console.log(resultDate);
// 3. Get the month of the date but add 1 because month index starts at 0
const newMonth = resultDate.getMonth() + 1;
console.log(newMonth);
// 4. Get the day of the date
const newDay = resultDate.getDate();
console.log(newDay);
// 5. Combine into string
result = `${newMonth}월${newDay}일`;
return result;
}
solution(11, 27);
solution(6, 22);
solution(1, 18);