• 카테고리

    질문 & 답변
  • 세부 분야

    프로그래밍 언어

  • 해결 여부

    해결됨

로또 번호 생성기 소스코드

21.02.07 13:14 작성 23.01.22 08:27 수정 조회수 214

0

function makeLottoNumber() {
  const lottoList = new Set();
  while (lottoList.size < (CONFIG.bonus ? 7 : 6)) {
    const random = Math.floor(Math.random() * CONFIG.maxNumber + 1);
    lottoList.add(random);
  }
  console.log(CONFIG.title);
  const result = [...lottoList];
  if (CONFIG.bonus) {
    const bonusNum = result.pop();
    return { number: result, bonus: bonusNum };
  } else {
    return { number: result };
  }
}

const CONFIG = {
  title: "Happy Lotto Time!",
  maxNumber: 45,
  bonus: true,
};
console.log(makeLottoNumber());

참고용으로 올립니다.

답변 0

답변을 작성해보세요.

답변을 기다리고 있는 질문이에요.
첫번째 답변을 남겨보세요!