Open
Conversation
- 숫자가 아닌 경우 예외 - 정수가 아닌 경우 예외 - 양수가 아닌 경우 예외 - 1000으로 나누어 떨어지지 않는 경우 예외
- 번호가 6개가 아닌 경우 예외 - 중복된 번호가 있는 경우 예외 - 1~45 범위를 벗어나는 경우 예외
- 1~45 범위를 벗어나는 경우 예외 - 당첨 번호와 중복인 경우 예외
- 구입 금액/1000개의 로또 발행 - 각 로또는 1~45 범위의 중복되지 않은 6개의 랜덤 숫자로 구성 - 번호 오름차순 정렬 - LottoController에서 로또 발행 로직 연동
- PRIZE_TABLE 상수 추가로 조건, 등수, 상금 정의 - calculateResult에 당첨 결과 기능 추가 - lottoController에 calculateResult 연결
- calculateResult() -> initResult(), analyzeLotto(), findPrize()로 분리
- printResult() -> printStatistics(), printProfitRate()
|
수고하셨습니다 우선 봤을때는 매직넘버와 매직스트링을 사용한다면 더 좋을것같습니다 또 매직넘버와 매직스트링을 사용하는 이유에 대해서 공부하면 더 좋아보입니다 |
inseong01
reviewed
Nov 11, 2025
inseong01
left a comment
There was a problem hiding this comment.
리드미가 잘 작성되어 있어서 코드 파악하는 데 수월했습니다.
3주 차 미션하시느라 수고하셨습니다~
Comment on lines
+4
to
+7
| async readPurchaseAmount() { | ||
| const input = await Console.readLineAsync("구입금액을 입력해 주세요.\n"); | ||
| return input; | ||
| }, |
There was a problem hiding this comment.
동일한 구조가 반복되고 있어서
Suggested change
| async readPurchaseAmount() { | |
| const input = await Console.readLineAsync("구입금액을 입력해 주세요.\n"); | |
| return input; | |
| }, | |
| async readLine(prompt) { | |
| const input = await Console.readLineAsync(`${prompt}\n`); | |
| return input; | |
| }, |
이렇게 하면 재사용할 수 있을 것 같아요.
|
|
||
| const outputView = { | ||
| printPurchasedLottos(lottos) { | ||
| Console.print(`\n${lottos.length}개를 구매했습니다.`); |
There was a problem hiding this comment.
여러 곳에서 Console.print를 호출하고 있는데 하나의 메서드로 만들어서 인자를 출력하는 방식으로 사용하면 좋을 것 같아요.
| @@ -0,0 +1,47 @@ | |||
| const validator = { | |||
Comment on lines
+22
to
+29
| winningNumbers.forEach((num) => { | ||
| if (!Number.isInteger(num)) { | ||
| throw new Error("[ERROR] 당첨 번호는 숫자여야 합니다."); | ||
| } | ||
| if (num < 1 || num > 45) { | ||
| throw new Error("[ERROR] 로또 번호는 1부터 45 사이의 숫자여야 합니다."); | ||
| } | ||
| }); |
There was a problem hiding this comment.
한 요소에 두 개의 조건을 동시에 검증하고 있는데
Suggested change
| winningNumbers.forEach((num) => { | |
| if (!Number.isInteger(num)) { | |
| throw new Error("[ERROR] 당첨 번호는 숫자여야 합니다."); | |
| } | |
| if (num < 1 || num > 45) { | |
| throw new Error("[ERROR] 로또 번호는 1부터 45 사이의 숫자여야 합니다."); | |
| } | |
| }); | |
| const hasInteger = winningNumbers.every(Number.isInteger); | |
| if (!hasInteger) { | |
| throw new Error("[ERROR] 당첨 번호는 숫자여야 합니다."); | |
| } | |
| const isOutOfNumberRange = winningNumbers.some((num) => num < 1 || num > 45); | |
| if (isOutOfNumberRange) { | |
| throw new Error("[ERROR] 로또 번호는 1부터 45 사이의 숫자여야 합니다."); | |
| } |
이렇게 하면 들여쓰기 깊이도 줄어들고 validator 코드 구조 통일하는 데 도움될 것 같아요.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
javascript-lotto-precourse
로또 구매부터 당첨 결과 확인까지 전 과정을 시뮬레이션하는 JavaScript 애플리케이션입니다.
기능 소개
프로젝트 구조
구현 기능 목록
입력
1000으로 나누어 떨어지지 않는 경우 예외1~45범위를 벗어나는 경우 예외1~45범위를 벗어나는 경우 예외로또 발행
구입 금액 / 1000개의 로또 발행1~45범위의 중복되지 않은 6개의 랜덤 숫자로 구성당첨 결과 계산
출력
[ERROR]로 시작하는 에러 메시지 출력예외 처리
모든 예외 상황에서
[ERROR]로 시작하는 에러 메시지를 출력하고, 올바른 값을 재입력받습니다.구입 금액 예외
[ERROR] 구입 금액은 숫자여야 합니다.[ERROR] 구입 금액은 정수여야 합니다.[ERROR] 구입 금액은 0보다 커야 합니다.[ERROR] 구입 금액은 1000원 단위여야 합니다.당첨 번호 예외
[ERROR] 당첨 번호는 6개여야 합니다.[ERROR] 당첨 번호는 숫자여야 합니다.[ERROR] 로또 번호는 1부터 45 사이의 숫자여야 합니다.[ERROR] 중복된 당첨 번호가 있습니다.보너스 번호 예외
[ERROR] 보너스 번호는 1부터 45 사이의 숫자여야 합니다.[ERROR] 보너스 번호는 당첨 번호와 중복될 수 없습니다.로또 클래스 예외
[ERROR] 로또 번호는 6개여야 합니다.[ERROR] 로또 번호에 중복된 숫자가 있습니다.설계 시 고려한 부분