Open
Conversation
Open
moondda
reviewed
Nov 14, 2023
moondda
left a comment
There was a problem hiding this comment.
간단한 기능에 맞게 간결하고 깔끔하게 잘 구현하셨네용
에러 처리만 추가적으로 구현해주시면 될 거 같아요(ex. 숫자가 아닌 다른 값이 들어와서 NaN이 리턴되는 경우)
수고하셨습니다~!
Comment on lines
+21
to
+33
| function checkInput() { | ||
| const isInputEmpty: boolean = isEmpty(input1.value, input2.value); | ||
| if (isInputEmpty) { | ||
| alert("뭐 잊은거 없어?"); | ||
| return false; | ||
| } | ||
| return true; | ||
| } | ||
|
|
||
| /* 입력 필드가 비었는지 확인하는 함수 */ | ||
| function isEmpty(num1: string, num2: string): boolean { | ||
| return num1 === "" || num2 === ""; | ||
| } |
hae2ni
reviewed
Nov 15, 2023
Member
hae2ni
left a comment
There was a problem hiding this comment.
역시 구조 나누기 장인이야! 넘 꼼꼼해 너무 고생해써 😄
| @@ -0,0 +1,15 @@ | |||
| export const input1: HTMLInputElement = document.querySelector( | |||
| "body > main > button" | ||
| ) as HTMLButtonElement; | ||
| export const answer: HTMLHeadingElement = document.querySelector( | ||
| "body > main > section > h3" |
Member
There was a problem hiding this comment.
호옥시 그냥 id값으로 만들고 박는거?를 지양하고 다 하나하나 선택자를 이용하신 이유가 있을까요?
| input1, | ||
| input2, | ||
| operation, | ||
| } from "./htmlElements"; |
| operation, | ||
| } from "./htmlElements"; | ||
|
|
||
| calculateButton.addEventListener("click", () => { |
Member
There was a problem hiding this comment.
요거 화살표 함수말고 따로 명명하면 조금 더 가독성있지 않을까 싶어!
| function checkInput() { | ||
| const isInputEmpty: boolean = isEmpty(input1.value, input2.value); | ||
| if (isInputEmpty) { | ||
| alert("뭐 잊은거 없어?"); |
| } | ||
|
|
||
| /* 결과 연산 함수 */ | ||
| function calculate(num1: number, num2: number, sign: string): number { |
Member
There was a problem hiding this comment.
요오거 interface로 바꾸면!!
Suggested change
| function calculate(num1: number, num2: number, sign: string): number { | |
| interface CalculatorInput { | |
| num1: number; | |
| num2: number; | |
| sign: string; | |
| } | |
| function calculate({num1, num2, sign}: CalculatorInput): number { |
| case "mul": | ||
| return num1 * num2; | ||
| case "divide": | ||
| return num1 / num2; |
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.
🌮 무엇을:
🌮 어떻게:
htmlElements.ts에는 querySelector를 통해 가져온 html element들을 모아놨어요TypeScript로 코딩이 처음이라HTMLElement라는 타입이 있는 것도 신기했어요 🤓checkInput()과isEmpty()를 통해 입력값을 검증했어요함수로 분리해보면서 함수의 인자와 반환값의 타입선언을 확실히 이해하게 됐어요 🤓
calculate()를 통해 결과를 계산했어요switch문을 사용하여 선택된 연산 부호에 따라 계산을 해줬어요 🤓🌮 얼마나:
⏰ 얼마나 걸렸나요?
1시간🤔 어떤 부분이 어려웠나요?
변수, 함수 매개변수, 함수 반환 값 등의 타입을 명확하게 정의하는 것을 처음해봐서 신기했습니다!!
🌮 구현 사항:
calculator.mov