항해99 언제 끝날까?
2번. 신대륙 발견
성륜이는 오늘 항해99를 시작했다. 성격이 급한 성륜이는 항해 1일 차부터 언제 수료를 하게될 지 궁금하다.
항해 1일 차 날짜를 입력하면 98일 이후 항해를 수료하게 되는 날짜를 계산해주는 알고리즘을 만들어보자.
제한 조건
- 1 ≤ month ≤ 12
- 1 ≤ day ≤ 31 (2월은 28일로 고정합니다, 즉 윤일은 고려하지 않습니다.)

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);
Author And Source
이 문제에 관하여(항해99 언제 끝날까?), 우리는 이곳에서 더 많은 자료를 발견하고 링크를 클릭하여 보았다 https://velog.io/@daonez/항해99-언제-끝날까저자 귀속: 원작자 정보가 원작자 URL에 포함되어 있으며 저작권은 원작자 소유입니다.
                                
                                
                                
                                
                                
                                우수한 개발자 콘텐츠 발견에 전념
                                (Collection and Share based on the CC Protocol.)