Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion index.html
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
</head>
<body>
<header>
<h1>혜인이의 계산기</h1>
<h1>호은이의 계산기</h1>

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

뿅 😍

</header>
<main>
<section>
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,6 @@
},
"devDependencies": {
"typescript": "^5.0.2",
"vite": "^4.4.5"
"vite": "^4.5.0"
}
}
42 changes: 42 additions & 0 deletions src/main.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
const $ = (selector: string) => document.querySelector(selector);

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

querySelector로 해줬군요!


const num1Input = $('input[type="number"]:nth-of-type(1)') as HTMLInputElement;

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The 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) {

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The 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)) {

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

아예 예외부분을 빼준 거 너무 좋은 거 같애! 굳굳

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

예외 빼준 부분 좋당

resultDisplay.textContent = "계산 불가";
} else {
resultDisplay.textContent = result.toString();
}
}

if (calculateButton) {

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

if안에 calculateButton를 넣어준 이유가 몬가요..???? calculateButton가 참/거짓으로 판별되는지 궁금해요!

calculateButton.addEventListener("click", calculateResult);

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

혹시 바로 click이벤트를 안 넣은 이유가 있나요?

}
2 changes: 1 addition & 1 deletion yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -181,7 +181,7 @@ typescript@^5.0.2:
resolved "https://registry.yarnpkg.com/typescript/-/typescript-5.2.2.tgz#5ebb5e5a5b75f085f22bc3f8460fba308310fa78"
integrity sha512-mI4WrpHsbCIcwT9cF4FZvr80QUeKvsUsUvKDoR+X/7XHQH98xYD8YHZg7ANtz2GtZt/CBq2QJ0thkGJMHfqc1w==

vite@^4.4.5:
vite@^4.5.0:
version "4.5.0"
resolved "https://registry.yarnpkg.com/vite/-/vite-4.5.0.tgz#ec406295b4167ac3bc23e26f9c8ff559287cff26"
integrity sha512-ulr8rNLA6rkyFAlVWw2q5YJ91v098AFQ2R0PRFwPzREXOUJQPtFUG0t+/ZikhaOCDqFoDhN6/v8Sq0o4araFAw==
Expand Down