Conversation
Open
hae2ni
reviewed
Nov 15, 2023
|
|
||
| const select = document.querySelector("select") as HTMLSelectElement; | ||
| let showresult = document.querySelector("h3") as HTMLHeadingElement; | ||
| const showResultButton = document.querySelector(".result"); |
Member
There was a problem hiding this comment.
요기에는 HTMLButtonElement를 넣을 수 있겠다!
| let showresult = document.querySelector("h3") as HTMLHeadingElement; | ||
| const showResultButton = document.querySelector(".result"); | ||
|
|
||
| showResultButton?.addEventListener("click", () => { |
| const showResultButton = document.querySelector(".result"); | ||
|
|
||
| showResultButton?.addEventListener("click", () => { | ||
| const input1: number = parseFloat(firstInput.value); |
Member
There was a problem hiding this comment.
함수가 기니까 그냥 안에 화살표 함수를 두는 것보다,함수를 새로 명명하는 게 좋을 것 같아요!
기능을 최대한 덜어내는 게 최선!
| case "mul": | ||
| result = input1 * input2; | ||
| break; | ||
| case "divide": |
| return; | ||
| } | ||
| showresult.textContent = String(result); | ||
| alert(`계산 결과는 ${result}`); |
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.
🌮 무엇을:
무엇을 개발했는지 짧게 설명해주세요! (개발 완료된 부분까지 설명)
css은 딱히 안 건드렸고(시간 이슈..), 숫자를 입력하고 연산자를 선택하면 계산된 값이 alarm으로도 뜨고, 화면에도 반영되게 하였다.
🌮 어떻게:
select value에 따라 case를 나눠서 switch 로 계산을 할 수 있게 만들었다.
입력값은 초기에는 string으로 설정되어있어서 parseFloat을 통해서 숫자로 바꿔서 연산이 가능하게 하였다.
🌮 얼마나:
1시간...?
const firstInput = document.querySelector(".first-input") as HTMLInputElement;이렇게 선택하는 부분에서 뒤에 as를 안 붙이는 데에서 에러가 많이 났다. 그리고 속성 참조를 할 때도 옵셔널 체이닝 연산자를 써야하고 (null일 수도 있어서) 하여튼 상당히 정확한 무언가 를 요구하는 언어인것 같다..
🌮 구현 사항:
Screen.Recording.2023-11-08.at.6.11.54.PM.mov