-
Notifications
You must be signed in to change notification settings - Fork 0
[ 호은 ] #3
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?
[ 호은 ] #3
Changes from all commits
f17457e
117f4f6
2ab3015
b10cc75
d78183e
94bd2b8
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -9,7 +9,7 @@ | |
| </head> | ||
| <body> | ||
| <header> | ||
| <h1>혜인이의 계산기</h1> | ||
| <h1>호은이의 계산기</h1> | ||
| </header> | ||
| <main> | ||
| <section> | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -10,6 +10,6 @@ | |
| }, | ||
| "devDependencies": { | ||
| "typescript": "^5.0.2", | ||
| "vite": "^4.4.5" | ||
| "vite": "^4.5.0" | ||
| } | ||
| } | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,42 @@ | ||
| const $ = (selector: string) => document.querySelector(selector); | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. querySelector로 해줬군요! |
||
|
|
||
| const num1Input = $('input[type="number"]:nth-of-type(1)') as HTMLInputElement; | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 머야머야! 선택자 장인이자나!!! 진짜 장하다ㅠㅠ 넘넘 잘해 |
||
| const num2Input = $('input[type="number"]:nth-of-type(2)') as HTMLInputElement; | ||
| const selectOperator = $('select[name="calculate"]') as HTMLSelectElement; | ||
| const resultDisplay = $("h3") as HTMLHeadingElement; | ||
| const calculateButton = $("button"); | ||
|
|
||
| function calculateResult() { | ||
| const num1 = parseFloat(num1Input.value); | ||
| const num2 = parseFloat(num2Input.value); | ||
| const operator = selectOperator.value; | ||
|
|
||
| let result: number; | ||
|
|
||
| switch (operator) { | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 굳굳! 깔끔하다! |
||
| case "sum": | ||
| result = num1 + num2; | ||
| break; | ||
| case "sub": | ||
| result = num1 - num2; | ||
| break; | ||
| case "mul": | ||
| result = num1 * num2; | ||
| break; | ||
| case "divide": | ||
| result = num1 / num2; | ||
| break; | ||
| default: | ||
| result = NaN; | ||
| } | ||
|
|
||
| if (isNaN(result)) { | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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 commentThe reason will be displayed to describe this comment to others. Learn more. 예외 빼준 부분 좋당 |
||
| resultDisplay.textContent = "계산 불가"; | ||
| } else { | ||
| resultDisplay.textContent = result.toString(); | ||
| } | ||
| } | ||
|
|
||
| if (calculateButton) { | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. if안에 calculateButton를 넣어준 이유가 몬가요..???? calculateButton가 참/거짓으로 판별되는지 궁금해요! |
||
| calculateButton.addEventListener("click", calculateResult); | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 혹시 바로 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.
뿅 😍