-
Notifications
You must be signed in to change notification settings - Fork 190
[로또] 이유경 미션 제출합니다. #157
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
[로또] 이유경 미션 제출합니다. #157
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
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
리드미가 잘 작성되어 있어서 코드 파악하는 데 수월했습니다.
3주 차 미션하시느라 수고하셨습니다~
| async readPurchaseAmount() { | ||
| const input = await Console.readLineAsync("구입금액을 입력해 주세요.\n"); | ||
| return input; | ||
| }, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
동일한 구조가 반복되고 있어서
| 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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
여러 곳에서 Console.print를 호출하고 있는데 하나의 메서드로 만들어서 인자를 출력하는 방식으로 사용하면 좋을 것 같아요.
| @@ -0,0 +1,47 @@ | |||
| const validator = { | |||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
class가 아닌 객체로 선언한 이유가 궁금해요.
| 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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
한 요소에 두 개의 조건을 동시에 검증하고 있는데
| 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 코드 구조 통일하는 데 도움될 것 같아요.
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] 로또 번호에 중복된 숫자가 있습니다.설계 시 고려한 부분