-
Notifications
You must be signed in to change notification settings - Fork 0
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
[ 수빈 ] #7
base: main
Are you sure you want to change the base?
[ 수빈 ] #7
Conversation
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.
간단한 기능에 맞게 간결하고 깔끔하게 잘 구현하셨네용
에러 처리만 추가적으로 구현해주시면 될 거 같아요(ex. 숫자가 아닌 다른 값이 들어와서 NaN이 리턴되는 경우)
수고하셨습니다~!
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 === ""; | ||
} |
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.
모듈화 좋아용
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.
역시 구조 나누기 장인이야! 넘 꼼꼼해 너무 고생해써 😄
@@ -0,0 +1,15 @@ | |||
export const input1: HTMLInputElement = document.querySelector( |
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.
역시 나누기 장인 황수빈,,, ❤️
"body > main > button" | ||
) as HTMLButtonElement; | ||
export const answer: HTMLHeadingElement = document.querySelector( | ||
"body > main > section > h3" |
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.
호옥시 그냥 id값으로 만들고 박는거?를 지양하고 다 하나하나 선택자를 이용하신 이유가 있을까요?
input1, | ||
input2, | ||
operation, | ||
} from "./htmlElements"; |
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.
굳굳! 너무 깔끔하다!! 진짜 분리 === 황수빈
operation, | ||
} from "./htmlElements"; | ||
|
||
calculateButton.addEventListener("click", () => { |
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.
요거 화살표 함수말고 따로 명명하면 조금 더 가독성있지 않을까 싶어!
function checkInput() { | ||
const isInputEmpty: boolean = isEmpty(input1.value, input2.value); | ||
if (isInputEmpty) { | ||
alert("뭐 잊은거 없어?"); |
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.
귀여웤ㅋㅋㅋㅋ
} | ||
|
||
/* 결과 연산 함수 */ | ||
function calculate(num1: number, num2: number, sign: string): number { |
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.
요오거 interface로 바꾸면!!
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; |
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.
num2가 0일때 예외사항으로 빼면 좋을 것 같아요!
🌮 무엇을:
🌮 어떻게:
htmlElements.ts
에는 querySelector를 통해 가져온 html element들을 모아놨어요TypeScript
로 코딩이 처음이라HTMLElement
라는 타입이 있는 것도 신기했어요 🤓checkInput()
과isEmpty()
를 통해 입력값을 검증했어요함수로 분리해보면서 함수의 인자와 반환값의 타입선언을 확실히 이해하게 됐어요 🤓
calculate()
를 통해 결과를 계산했어요switch
문을 사용하여 선택된 연산 부호에 따라 계산을 해줬어요 🤓🌮 얼마나:
⏰ 얼마나 걸렸나요?
1시간
🤔 어떤 부분이 어려웠나요?
변수, 함수 매개변수, 함수 반환 값 등의 타입을 명확하게 정의하는 것을 처음해봐서 신기했습니다!!
🌮 구현 사항:
calculator.mov